mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-06-12 05:07:41 +02:00
fix(YouTube): Patched app crashes after first launch or clearing data
This commit is contained in:
@ -2,8 +2,10 @@ package app.revanced.patches.youtube.utils.extension
|
||||
|
||||
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
|
||||
|
||||
// TODO: Move this to a "Hook.kt" file. Same for other extension hook patches.
|
||||
val sharedExtensionPatch = sharedExtensionPatch(
|
||||
applicationInitHook,
|
||||
mainActivityBaseContextHook,
|
||||
)
|
||||
|
@ -0,0 +1,35 @@
|
||||
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;")
|
||||
)
|
||||
}
|
||||
}
|
@ -70,7 +70,7 @@ val playerResponseMethodHookPatch = bytecodePatch(
|
||||
"""
|
||||
invoke-static {$registerVideoId, $registerPlayerParameter, $registerPlaylistId, $registerIsShortAndOpeningOrPlaying}, $hook
|
||||
move-result-object $registerPlayerParameter
|
||||
""",
|
||||
""",
|
||||
)
|
||||
numberOfInstructionsAdded += 2
|
||||
}
|
||||
|
Reference in New Issue
Block a user