From 1aa098cf2fbbcb17eb329ff1e8b7886d26e90032 Mon Sep 17 00:00:00 2001 From: Indranil012 Date: Sat, 10 Feb 2024 23:47:12 +0530 Subject: [PATCH] feat(nova): pro unlock --- .../fingerprints/UnlockPrimeFingerprint.kt | 16 +++++++ .../nova/prime/patch/UnlockPrimePatch.kt | 45 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt create mode 100644 src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt diff --git a/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt b/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt new file mode 100644 index 0000000..b80dbf0 --- /dev/null +++ b/src/main/kotlin/dropped/patches/nova/prime/fingerprints/UnlockPrimeFingerprint.kt @@ -0,0 +1,16 @@ +package app.revanced.patches.nova.prime.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import org.jf.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") +) diff --git a/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt b/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt new file mode 100644 index 0000000..a9d2133 --- /dev/null +++ b/src/main/kotlin/dropped/patches/nova/prime/patch/UnlockPrimePatch.kt @@ -0,0 +1,45 @@ +package app.revanced.patches.nova.prime.patch + +import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.nova.prime.fingerprints.UnlockPrimeFingerprint +import org.jf.dexlib2.builder.instruction.BuilderInstruction11x + +@Patch( + name = "Unlock prime", + description = "Unlocks Nova Prime and all functions of the app.", + compatiblePackages = [CompatiblePackage("com.teslacoilsw.launcher")] +) +object UnlockPrimePatch : BytecodePatch( + setOf( + UnlockPrimeFingerprint + ) +) { + private companion object { + // 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. + const val PRIME_STATUS: Int = 512 + } + + override fun execute(context: BytecodeContext): PatchResult { + UnlockPrimeFingerprint.result?.apply { + val insertIndex = scanResult.patternScanResult!!.endIndex + 1 + + val primeStatusRegister = + (mutableMethod.implementation!!.instructions[insertIndex - 1] as BuilderInstruction11x).registerA + + mutableMethod.addInstruction( + insertIndex, + """ + const/16 v$primeStatusRegister, $PRIME_STATUS + """ + ) + } ?: return UnlockPrimeFingerprint.PatchException() + + return PatchResult() + } +}