From 032cea651a023f96f79046b3f04a245ef246af73 Mon Sep 17 00:00:00 2001 From: inotia00 Date: Mon, 3 Apr 2023 21:53:08 +0900 Subject: [PATCH] fix: `bypass-ambient-mode-restrictions` patch is broken --- .../fingerprints/PowerSaveModeFingerprint.kt | 20 ++++++++++++------- .../ambientmode/patch/PowerSaveModePatch.kt | 16 +++++++++------ 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt index 9ab86a4a76..2281a7da2d 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/fingerprints/PowerSaveModeFingerprint.kt @@ -4,16 +4,22 @@ import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import org.jf.dexlib2.AccessFlags import org.jf.dexlib2.Opcode -import org.jf.dexlib2.iface.instruction.NarrowLiteralInstruction object PowerSaveModeFingerprint : MethodFingerprint( returnType = "V", access = AccessFlags.PUBLIC or AccessFlags.FINAL, parameters = listOf("L"), - opcodes = listOf(Opcode.SUB_INT_2ADDR), - customFingerprint = { methodDef -> - methodDef.implementation!!.instructions.any { - ((it as? NarrowLiteralInstruction)?.narrowLiteral == 107243) - } - } + opcodes = listOf( + Opcode.IGET_OBJECT, + Opcode.CHECK_CAST, + Opcode.CHECK_CAST, + Opcode.IGET_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT, + Opcode.INVOKE_STATIC, + Opcode.MOVE_RESULT_OBJECT, + Opcode.INVOKE_VIRTUAL, + Opcode.RETURN_VOID + ), + customFingerprint = { it.name == "accept" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt index 680510d0f6..d5f0c7dc1b 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/misc/ambientmode/patch/PowerSaveModePatch.kt @@ -8,6 +8,7 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch @@ -31,25 +32,28 @@ class PowerSaveModePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext): PatchResult { - PowerSaveModeFingerprint.result?.mutableMethod?.let { - val instructions = it.implementation!!.instructions + PowerSaveModeFingerprint.result?.mutableMethod?.let { method -> + val instructions = method.implementation!!.instructions + var powerManagerIndex = -1 + for ((index, instruction) in instructions.withIndex()) { if (instruction.opcode != Opcode.INVOKE_VIRTUAL) continue val invokeInstruction = instruction as Instruction35c if ((invokeInstruction.reference as MethodReference).name != "isPowerSaveMode") continue - val targetIndex = index + 1 + powerManagerIndex = index + 1 - val targetRegister = (instructions.elementAt(targetIndex) as OneRegisterInstruction).registerA + val targetRegister = (instructions.elementAt(powerManagerIndex) as OneRegisterInstruction).registerA - it.addInstructions( - targetIndex + 1, """ + method.addInstructions( + powerManagerIndex + 1, """ invoke-static {v$targetRegister}, $MISC_PATH/PowerSaveModePatch;->bypassPowerSaveModeRestrictions(Z)Z move-result v$targetRegister """ ) } + if (powerManagerIndex == -1) return PatchResultError("Couldn't find PowerManager reference") } ?: return PowerSaveModeFingerprint.toErrorResult() /*