From 1ee89fe0e6a8353d72bb742c06d9f9571f535784 Mon Sep 17 00:00:00 2001 From: Pun Butrach Date: Mon, 12 Jan 2026 17:16:28 +0700 Subject: [PATCH] refactor(photomath): SignatureDetectionPatch --- .../detection/signature/Fingerprints.kt | 26 ++++++++++--------- .../signature/SignatureDetectionPatch.kt | 16 +++++++----- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/Fingerprints.kt index c6563270e..fa7fdaa52 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/Fingerprints.kt @@ -1,18 +1,20 @@ package app.revanced.patches.photomath.detection.signature +import app.revanced.patcher.allOf +import app.revanced.patcher.firstMethodComposite +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke import com.android.tools.smali.dexlib2.Opcode -import app.revanced.patcher.fingerprint -internal val checkSignatureFingerprint = fingerprint { - opcodes( - Opcode.CONST_STRING, - Opcode.INVOKE_STATIC, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT, +internal val checkSignatureMethodMatch = firstMethodComposite("SHA") { + instructions( + allOf(Opcode.CONST_STRING(), "SHA"()), + Opcode.INVOKE_STATIC(), + Opcode.INVOKE_STATIC(), + Opcode.MOVE_RESULT_OBJECT(), + Opcode.INVOKE_VIRTUAL(), + Opcode.MOVE_RESULT_OBJECT(), + Opcode.INVOKE_STATIC(), + Opcode.MOVE_RESULT(), ) - strings("SHA") } diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt index af1f088c0..ab8045ad2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt @@ -2,17 +2,19 @@ package app.revanced.patches.photomath.detection.signature import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.patch.bytecodePatch +import app.revanced.patcher.patch.creatingBytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -val signatureDetectionPatch = bytecodePatch( +@Suppress("unused", "ObjectPropertyName") +val `Signature detection` by creatingBytecodePatch( description = "Disables detection of incorrect signature.", ) { - apply { - val replacementIndex = checkSignatureFingerprint.instructionMatches.last().index - val checkRegister = - checkSignatureFingerprint.method.getInstruction(replacementIndex).registerA - checkSignatureFingerprint.method.replaceInstruction(replacementIndex, "const/4 v$checkRegister, 0x1") + val replacementIndex = checkSignatureMethodMatch.indices.last() + + checkSignatureMethodMatch.method.apply { + val checkRegister = getInstruction(replacementIndex).registerA + replaceInstruction(replacementIndex, "const/4 v$checkRegister, 0x1") + } } }