From 5a2cad077f03880ee1417c5cfd448bbdea4c07e2 Mon Sep 17 00:00:00 2001 From: badawoll <129878899+badawoll@users.noreply.github.com> Date: Mon, 28 Aug 2023 13:45:47 +0000 Subject: [PATCH] feat(Photomath): Support latest version Co-authored-by: oSumAtrIX --- .../fingerprints/GetDeviceIdFingerprint.kt | 9 +++++ .../deviceid/patch/SpoofDeviceIdPatch.kt | 32 ++++++++++++++++++ .../fingerprints/CheckSignatureFingerprint.kt | 10 +----- .../patch/SignatureDetectionPatch.kt | 1 - .../IsBookpointEnabledFingerprint.kt | 17 ++++++++++ .../bookpoint/patch/EnableBookpointPatch.kt | 20 +++++++++++ .../annotations/UnlockPlusCompatibilty.kt | 8 ----- .../misc/unlockplus/patch/UnlockPlusPatch.kt | 33 ++++++++----------- 8 files changed, 92 insertions(+), 38 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/fingerprints/GetDeviceIdFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/patch/SpoofDeviceIdPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/fingerprints/IsBookpointEnabledFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/patch/EnableBookpointPatch.kt delete mode 100644 src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/annotations/UnlockPlusCompatibilty.kt diff --git a/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/fingerprints/GetDeviceIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/fingerprints/GetDeviceIdFingerprint.kt new file mode 100644 index 000000000..b69e9d1f2 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/fingerprints/GetDeviceIdFingerprint.kt @@ -0,0 +1,9 @@ +package app.revanced.patches.photomath.detection.deviceid.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint + +object GetDeviceIdFingerprint : MethodFingerprint( + returnType = "Ljava/lang/String;", + strings = listOf("androidId", "android_id"), + parameters = listOf() +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/patch/SpoofDeviceIdPatch.kt b/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/patch/SpoofDeviceIdPatch.kt new file mode 100644 index 000000000..a295c0bc7 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/patch/SpoofDeviceIdPatch.kt @@ -0,0 +1,32 @@ +package app.revanced.patches.photomath.detection.deviceid.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.annotation.Compatibility +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Package +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotations.DependsOn +import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patches.photomath.detection.deviceid.fingerprints.GetDeviceIdFingerprint +import app.revanced.patches.photomath.detection.signature.patch.SignatureDetectionPatch +import kotlin.random.Random + +@Patch +@DependsOn([SignatureDetectionPatch::class]) +@Name("Spoof device ID") +@Description("Spoofs device ID to mitigate manual bans by developers.") +@Compatibility([Package("com.microblink.photomath")]) +class SpoofDeviceIdPatch : BytecodePatch( + listOf(GetDeviceIdFingerprint) +) { + override fun execute(context: BytecodeContext) = GetDeviceIdFingerprint.result?.mutableMethod?.replaceInstructions( + 0, + """ + const-string v0, "${Random.nextLong().toString(16)}" + return-object v0 + """ + ) ?: throw GetDeviceIdFingerprint.exception +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/photomath/detection/signature/fingerprints/CheckSignatureFingerprint.kt b/src/main/kotlin/app/revanced/patches/photomath/detection/signature/fingerprints/CheckSignatureFingerprint.kt index 3bb7e92f6..bce10ba85 100644 --- a/src/main/kotlin/app/revanced/patches/photomath/detection/signature/fingerprints/CheckSignatureFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/photomath/detection/signature/fingerprints/CheckSignatureFingerprint.kt @@ -1,19 +1,11 @@ package app.revanced.patches.photomath.detection.signature.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode object CheckSignatureFingerprint : MethodFingerprint( - returnType = "V", - accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, - customFingerprint = { methodDef, _ -> - (methodDef.definingClass == "Lcom/microblink/photomath/main/activity/LauncherActivity;" || - methodDef.definingClass == "Lcom/microblink/photomath/PhotoMath;") && - methodDef.name == "onCreate" - }, strings = listOf( + "packageInfo.signatures", "currentSignature" ), opcodes = listOf( diff --git a/src/main/kotlin/app/revanced/patches/photomath/detection/signature/patch/SignatureDetectionPatch.kt b/src/main/kotlin/app/revanced/patches/photomath/detection/signature/patch/SignatureDetectionPatch.kt index f6bc11609..cab96846e 100644 --- a/src/main/kotlin/app/revanced/patches/photomath/detection/signature/patch/SignatureDetectionPatch.kt +++ b/src/main/kotlin/app/revanced/patches/photomath/detection/signature/patch/SignatureDetectionPatch.kt @@ -23,5 +23,4 @@ class SignatureDetectionPatch : BytecodePatch( mutableMethod.replaceInstruction(signatureCheckInstruction.location.index, "const/4 v$checkRegister, 0x1") } ?: throw CheckSignatureFingerprint.exception } - } diff --git a/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/fingerprints/IsBookpointEnabledFingerprint.kt b/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/fingerprints/IsBookpointEnabledFingerprint.kt new file mode 100644 index 000000000..c1ce1f01f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/fingerprints/IsBookpointEnabledFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.photomath.misc.bookpoint.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +object IsBookpointEnabledFingerprint : MethodFingerprint( + returnType = "Z", + accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL, + parameters = listOf(), + strings = listOf( + "NoGeoData", + "NoCountryInGeo", + "RemoteConfig", + "GeoRCMismatch" + ) +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/patch/EnableBookpointPatch.kt b/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/patch/EnableBookpointPatch.kt new file mode 100644 index 000000000..0966f508a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/photomath/misc/bookpoint/patch/EnableBookpointPatch.kt @@ -0,0 +1,20 @@ +package app.revanced.patches.photomath.misc.bookpoint.patch + +import app.revanced.extensions.exception +import app.revanced.patcher.annotation.Description +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patches.photomath.misc.bookpoint.fingerprints.IsBookpointEnabledFingerprint + +@Description("Enables textbook access") +class EnableBookpointPatch : BytecodePatch(listOf(IsBookpointEnabledFingerprint)) { + override fun execute(context: BytecodeContext) = + IsBookpointEnabledFingerprint.result?.mutableMethod?.replaceInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) ?: throw IsBookpointEnabledFingerprint.exception +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/annotations/UnlockPlusCompatibilty.kt b/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/annotations/UnlockPlusCompatibilty.kt deleted file mode 100644 index aa73c1fd3..000000000 --- a/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/annotations/UnlockPlusCompatibilty.kt +++ /dev/null @@ -1,8 +0,0 @@ -package app.revanced.patches.photomath.misc.unlockplus.annotations - -import app.revanced.patcher.annotation.Compatibility -import app.revanced.patcher.annotation.Package - -@Compatibility([Package("com.microblink.photomath", arrayOf("8.20.0"))]) -@Target(AnnotationTarget.CLASS) -internal annotation class UnlockPlusCompatibilty diff --git a/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/patch/UnlockPlusPatch.kt b/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/patch/UnlockPlusPatch.kt index 6d76eb0ed..9b351aa41 100644 --- a/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/patch/UnlockPlusPatch.kt +++ b/src/main/kotlin/app/revanced/patches/photomath/misc/unlockplus/patch/UnlockPlusPatch.kt @@ -1,37 +1,30 @@ package app.revanced.patches.photomath.misc.unlockplus.patch import app.revanced.extensions.exception -import app.revanced.patcher.annotation.Description +import app.revanced.patcher.annotation.Compatibility import app.revanced.patcher.annotation.Name +import app.revanced.patcher.annotation.Package import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch import app.revanced.patches.photomath.detection.signature.patch.SignatureDetectionPatch -import app.revanced.patches.photomath.misc.unlockplus.annotations.UnlockPlusCompatibilty +import app.revanced.patches.photomath.misc.bookpoint.patch.EnableBookpointPatch import app.revanced.patches.photomath.misc.unlockplus.fingerprints.IsPlusUnlockedFingerprint @Patch @Name("Unlock plus") -@DependsOn([SignatureDetectionPatch::class]) -@Description("Unlocks plus features.") -@UnlockPlusCompatibilty +@DependsOn([SignatureDetectionPatch::class, EnableBookpointPatch::class]) +@Compatibility([Package("com.microblink.photomath")]) class UnlockPlusPatch : BytecodePatch( - listOf( - IsPlusUnlockedFingerprint - ) + listOf(IsPlusUnlockedFingerprint) ) { - override fun execute(context: BytecodeContext) { - IsPlusUnlockedFingerprint.result?.mutableMethod?.apply { - addInstructions( - 0, - """ - const/4 v0, 0x1 - return v0 - """ - ) - } ?: throw IsPlusUnlockedFingerprint.exception - } - + override fun execute(context: BytecodeContext) = IsPlusUnlockedFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + const/4 v0, 0x1 + return v0 + """ + ) ?: throw IsPlusUnlockedFingerprint.exception } \ No newline at end of file