Skip to content

Commit

Permalink
fix: bypass-ambient-mode-restrictions patch is broken
Browse files Browse the repository at this point in the history
  • Loading branch information
inotia00 committed Apr 3, 2023
1 parent 2ccafc6 commit 032cea6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
)
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()

/*
Expand Down

0 comments on commit 032cea6

Please sign in to comment.