fix: bypass-ambient-mode-restrictions patch is broken

This commit is contained in:
inotia00 2023-04-03 21:53:08 +09:00
parent 2ccafc6b4b
commit 032cea651a
2 changed files with 23 additions and 13 deletions

View File

@ -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" }
)

View File

@ -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()
/*