diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/SharedExtensionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/SharedExtensionPatch.kt index dd6883783..7e155f261 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/SharedExtensionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/SharedExtensionPatch.kt @@ -1,14 +1,8 @@ package app.revanced.patches.music.utils.extension import app.revanced.patches.music.utils.extension.hooks.applicationInitHook -import app.revanced.patches.music.utils.extension.hooks.mainActivityBaseContextHook -import app.revanced.patches.shared.extension.hooks.cronetEngineContextHook -import app.revanced.patches.shared.extension.hooks.firebaseInitProviderContextHook import app.revanced.patches.shared.extension.sharedExtensionPatch val sharedExtensionPatch = sharedExtensionPatch( applicationInitHook, - cronetEngineContextHook, - firebaseInitProviderContextHook, - mainActivityBaseContextHook, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/hooks/MainActivityBaseContextHook.kt b/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/hooks/MainActivityBaseContextHook.kt deleted file mode 100644 index 549eff2ba..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/music/utils/extension/hooks/MainActivityBaseContextHook.kt +++ /dev/null @@ -1,32 +0,0 @@ -package app.revanced.patches.music.utils.extension.hooks - -import app.revanced.patches.shared.extension.extensionHook -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -private var attachBaseContextIndex = -1 - -internal val mainActivityBaseContextHook = extensionHook( - insertIndexResolver = { method -> - attachBaseContextIndex = method.indexOfFirstInstructionOrThrow { - getReference()?.name == "attachBaseContext" - } - - attachBaseContextIndex + 1 - }, - contextRegisterResolver = { method -> - val overrideInstruction = - method.implementation!!.instructions.elementAt(attachBaseContextIndex) - as FiveRegisterInstruction - "v${overrideInstruction.registerD}" - }, -) { - returns("V") - parameters("Landroid/content/Context;") - custom { method, classDef -> - classDef.type == "Lcom/google/android/apps/youtube/music/activities/MusicActivity;" && - method.name == "attachBaseContext" - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/CronetEngineContextHook.kt b/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/CronetEngineContextHook.kt deleted file mode 100644 index e31cf801b..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/CronetEngineContextHook.kt +++ /dev/null @@ -1,48 +0,0 @@ -package app.revanced.patches.shared.extension.hooks - -import app.revanced.patches.shared.extension.extensionHook -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstruction -import app.revanced.util.indexOfFirstInstructionOrThrow -import com.android.tools.smali.dexlib2.AccessFlags -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction3rc -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -private var initIndex = -1 -private var isRange = true - -internal val cronetEngineContextHook = extensionHook( - insertIndexResolver = { method -> - initIndex = method.indexOfFirstInstruction(Opcode.INVOKE_DIRECT_RANGE) - - if (initIndex < 0) { - initIndex = method.indexOfFirstInstructionOrThrow(Opcode.INVOKE_DIRECT) - isRange = false - } - - initIndex - }, - contextRegisterResolver = { method -> - val initInstruction = - method.implementation!!.instructions.elementAt(initIndex) - if (isRange) { - val overrideInstruction = initInstruction as Instruction3rc - "v${overrideInstruction.startRegister + 1}" - } else { - val overrideInstruction = initInstruction as FiveRegisterInstruction - "v${overrideInstruction.registerD}" - } - }, -) { - returns("Lorg/chromium/net/CronetEngine;") - accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC) - strings("Could not create CronetEngine") - custom { method, classDef -> - method.indexOfFirstInstruction { - (opcode == Opcode.INVOKE_DIRECT || opcode == Opcode.INVOKE_DIRECT_RANGE) && - getReference()?.parameterTypes?.firstOrNull() == "Landroid/content/Context;" - } >= 0 - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/FirebaseInitProviderContextHook.kt b/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/FirebaseInitProviderContextHook.kt deleted file mode 100644 index e52f23dfa..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/shared/extension/hooks/FirebaseInitProviderContextHook.kt +++ /dev/null @@ -1,37 +0,0 @@ -package app.revanced.patches.shared.extension.hooks - -import app.revanced.patches.shared.extension.extensionHook -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstruction -import com.android.tools.smali.dexlib2.Opcode -import com.android.tools.smali.dexlib2.iface.Method -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -private var getResourcesIndex = -1 - -internal val firebaseInitProviderContextHook = extensionHook( - insertIndexResolver = { method -> - getResourcesIndex = indexOfGerResourcesInstruction(method) - - getResourcesIndex + 2 - }, - contextRegisterResolver = { method -> - val overrideInstruction = - method.implementation!!.instructions.elementAt(getResourcesIndex) - as FiveRegisterInstruction - - "v${overrideInstruction.registerC}" - }, -) { - strings("firebase_database_url") - custom { method, _ -> - indexOfGerResourcesInstruction(method) >= 0 - } -} - -private fun indexOfGerResourcesInstruction(method: Method) = - method.indexOfFirstInstruction { - opcode == Opcode.INVOKE_VIRTUAL && - getReference()?.toString() =="Landroid/content/Context;->getResources()Landroid/content/res/Resources;" - } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/SharedExtensionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/SharedExtensionPatch.kt index e2ba7dc77..bab6ee3da 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/SharedExtensionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/SharedExtensionPatch.kt @@ -1,17 +1,9 @@ package app.revanced.patches.youtube.utils.extension -import app.revanced.patches.shared.extension.hooks.cronetEngineContextHook -import app.revanced.patches.shared.extension.hooks.firebaseInitProviderContextHook import app.revanced.patches.shared.extension.sharedExtensionPatch import app.revanced.patches.youtube.utils.extension.hooks.applicationInitHook -import app.revanced.patches.youtube.utils.extension.hooks.mainActivityBaseContextHook -import app.revanced.patches.youtube.utils.extension.hooks.urlActivityBaseContextHook // TODO: Move this to a "Hook.kt" file. Same for other extension hook patches. val sharedExtensionPatch = sharedExtensionPatch( applicationInitHook, - cronetEngineContextHook, - firebaseInitProviderContextHook, - mainActivityBaseContextHook, - urlActivityBaseContextHook, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/MainActivityBaseContextHook.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/MainActivityBaseContextHook.kt deleted file mode 100644 index 1f17ed305..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/MainActivityBaseContextHook.kt +++ /dev/null @@ -1,36 +0,0 @@ -package app.revanced.patches.youtube.utils.extension.hooks - -import app.revanced.patches.shared.extension.extensionHook -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -private var attachBaseContextIndex = -1 - -internal val mainActivityBaseContextHook = extensionHook( - insertIndexResolver = { method -> - attachBaseContextIndex = method.indexOfFirstInstructionOrThrow { - getReference()?.name == "attachBaseContext" - } - - attachBaseContextIndex + 1 - }, - contextRegisterResolver = { method -> - val overrideInstruction = - method.implementation!!.instructions.elementAt(attachBaseContextIndex) - as FiveRegisterInstruction - "v${overrideInstruction.registerD}" - }, -) { - returns("V") - parameters("Landroid/content/Context;") - custom { method, classDef -> - method.name == "attachBaseContext" && - ( - classDef.endsWith("/MainActivity;") || - // Old versions of YouTube called this class "WatchWhileActivity" instead. - classDef.endsWith("/WatchWhileActivity;") - ) - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/UrlActivityBaseContextHook.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/UrlActivityBaseContextHook.kt deleted file mode 100644 index b14d0b71e..000000000 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/utils/extension/hooks/UrlActivityBaseContextHook.kt +++ /dev/null @@ -1,32 +0,0 @@ -package app.revanced.patches.youtube.utils.extension.hooks - -import app.revanced.patches.shared.extension.extensionHook -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction -import com.android.tools.smali.dexlib2.iface.reference.MethodReference - -private var attachBaseContextIndex = -1 - -internal val urlActivityBaseContextHook = extensionHook( - insertIndexResolver = { method -> - attachBaseContextIndex = method.indexOfFirstInstructionOrThrow { - getReference()?.name == "attachBaseContext" - } - - attachBaseContextIndex + 1 - }, - contextRegisterResolver = { method -> - val overrideInstruction = - method.implementation!!.instructions.elementAt(attachBaseContextIndex) - as FiveRegisterInstruction - "v${overrideInstruction.registerD}" - }, -) { - returns("V") - parameters("Landroid/content/Context;") - custom { method, classDef -> - classDef.endsWith("/Shell_UrlActivity;") && - method.name == "attachBaseContext" - } -}