mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-04-29 14:14:36 +02:00
fix(Extensions): Remove unnecessary Context hooks
This commit is contained in:
parent
88d59d05b9
commit
35e6c26823
@ -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,
|
||||
)
|
||||
|
@ -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<MethodReference>()?.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"
|
||||
}
|
||||
}
|
@ -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<MethodReference>()?.parameterTypes?.firstOrNull() == "Landroid/content/Context;"
|
||||
} >= 0
|
||||
}
|
||||
}
|
@ -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<MethodReference>()?.toString() =="Landroid/content/Context;->getResources()Landroid/content/res/Resources;"
|
||||
}
|
@ -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,
|
||||
)
|
||||
|
@ -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<MethodReference>()?.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;")
|
||||
)
|
||||
}
|
||||
}
|
@ -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<MethodReference>()?.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"
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user