From 19c0b0d194bb97c7248ea7a9b081176961653b9d Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 12 Apr 2022 20:59:06 +0200 Subject: [PATCH] feat: integrations patch --- src/main/kotlin/app/revanced/patches/Index.kt | 4 +- .../app/revanced/patches/misc/Integrations.kt | 53 +++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/app/revanced/patches/misc/Integrations.kt diff --git a/src/main/kotlin/app/revanced/patches/Index.kt b/src/main/kotlin/app/revanced/patches/Index.kt index 91787b99..cec102db 100644 --- a/src/main/kotlin/app/revanced/patches/Index.kt +++ b/src/main/kotlin/app/revanced/patches/Index.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.patch.Patch import app.revanced.patches.ad.VideoAds import app.revanced.patches.interaction.EnableSeekbarTapping import app.revanced.patches.layout.* +import app.revanced.patches.misc.Integrations /** * Index contains all the patches and should be imported when using this library. @@ -21,6 +22,7 @@ object Index { ::HideReels, ::HideSuggestions, ::OldQualityLayout, - ::EnableSeekbarTapping + ::EnableSeekbarTapping, + ::Integrations ) } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/misc/Integrations.kt b/src/main/kotlin/app/revanced/patches/misc/Integrations.kt new file mode 100644 index 00000000..1b4c66e6 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/misc/Integrations.kt @@ -0,0 +1,53 @@ +package app.revanced.patches.misc + +import app.revanced.patcher.cache.Cache +import app.revanced.patcher.extensions.addInstructions +import app.revanced.patcher.extensions.or +import app.revanced.patcher.patch.Patch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultSuccess +import app.revanced.patcher.proxy.mutableTypes.MutableMethod.Companion.toMutable +import app.revanced.patcher.smali.asInstructions +import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.immutable.ImmutableMethod +import org.jf.dexlib2.immutable.ImmutableMethodImplementation + +class Integrations : Patch("integrations-patch") { + override fun execute(cache: Cache): PatchResult { + val map = cache.methodMap["integrations-patch"] + val implementation = map.method.implementation!! + val count = implementation.registerCount - 1 + + implementation.addInstructions( + map.scanData.endIndex, + """ + invoke-static {v$count}, Lpl/jakubweg/StringRef;->setContext(Landroid/content/Context;)V + sput-object v$count, Lapp/revanced/integrations/Globals;->context:Landroid/content/Context; + """.trimIndent().asInstructions() + ) + + val classDef = map.definingClassProxy.resolve() + classDef.methods.add( + ImmutableMethod( + classDef.type, + "getAppContext", + null, + "Landroid/content/Context;", + AccessFlags.PUBLIC or AccessFlags.STATIC, + null, + null, + ImmutableMethodImplementation( + 1, + """ + invoke-static { }, Lapp/revanced/integrations/Globals;->getAppContext()Landroid/content/Context; + move-result-object v0 + return-object v0 + """.trimIndent().asInstructions(), + null, + null + ) + ).toMutable() + ) + return PatchResultSuccess() + } +} \ No newline at end of file