diff --git a/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt b/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt index 32c69a4..563b82f 100644 --- a/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt +++ b/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt @@ -3,14 +3,7 @@ package app.revanced.patches.nova.prime.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint import com.android.tools.smali.dexlib2.Opcode -object UnlockPrimeFingerprint : MethodFingerprint( - "V", - opcodes = listOf( - Opcode.IPUT_OBJECT, - Opcode.CONST_STRING, - Opcode.CONST_4, - Opcode.INVOKE_INTERFACE, - Opcode.MOVE_RESULT - ), - strings = listOf("1") +object UpdatePrimeStatusFingerprint : MethodFingerprint( + opcodes = listOf(Opcode.CONST_4), // Modify this to change the prime status. + strings = listOf("widget_reset_ids") ) diff --git a/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt b/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt index f74be87..264e7fc 100644 --- a/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt +++ b/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt @@ -2,39 +2,35 @@ package app.revanced.patches.nova.prime.patch import app.revanced.util.exception import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.BytecodePatch -import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.patch.annotation.CompatiblePackage -import app.revanced.patches.nova.prime.fingerprints.UnlockPrimeFingerprint -import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction11x +import app.revanced.patches.nova.prime.fingerprints.UpdatePrimeStatusFingerprint +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Unlock prime", description = "Unlocks Nova Prime and all functions of the app.", compatiblePackages = [CompatiblePackage("com.teslacoilsw.launcher")] ) +@Suppress("unused") object UnlockPrimePatch : BytecodePatch( - setOf(UnlockPrimeFingerprint) + setOf(UpdatePrimeStatusFingerprint) ) { - override fun execute(context: BytecodeContext) { - UnlockPrimeFingerprint.result?.apply { - // Any value except 0 unlocks prime, but 512 is needed for a protection mechanism - // which would reset the preferences if the value on disk had changed after a restart. - val PRIME_STATUS: Int = 512 - val insertIndex = scanResult.patternScanResult!!.endIndex + 1 + // Any value except 0 unlocks Nova Prime, but 512 is needed for a protection mechanism + // otherwise the preferences will be reset if the status on disk changes after a restart. + private const val PRIME_STATUS = 512 - val primeStatusRegister = - (mutableMethod.implementation!!.instructions[insertIndex - 1] as BuilderInstruction11x).registerA + override fun execute(context: BytecodeContext) = UpdatePrimeStatusFingerprint.result?.let { + val setStatusIndex = it.scanResult.patternScanResult!!.startIndex - mutableMethod.addInstruction( - insertIndex, - """ - const/16 v$primeStatusRegister, $PRIME_STATUS - """ - ) - } ?: throw UnlockPrimeFingerprint.exception + it.mutableMethod.apply { + val statusRegister = getInstruction(setStatusIndex).registerA + replaceInstruction(setStatusIndex, "const/16 v$statusRegister, $PRIME_STATUS") + } - } + return@let + } ?: throw UpdatePrimeStatusFingerprint.exception }