diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/Fingerprints.kt index 5b3029094..e8fda82a8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/Fingerprints.kt @@ -1,31 +1,35 @@ package app.revanced.patches.reddit.customclients.redditisfun.api -import app.revanced.patcher.fingerprint +import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively +import app.revanced.patcher.accessFlags +import app.revanced.patcher.instructions +import app.revanced.patcher.invoke +import app.revanced.patcher.parameterTypes +import app.revanced.patcher.patch.BytecodePatchContext +import app.revanced.patcher.returnType import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal fun baseClientIdFingerprint(string: String) = fingerprint { - strings("yyOCBp.RHJhDKd", string) -} - -internal val basicAuthorizationFingerprint = baseClientIdFingerprint( - string = "fJOxVwBUyo*=f: compatibleWith( "com.andrewshu.android.reddit", @@ -30,21 +31,34 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl * @param getReplacementIndex A function that returns the index of the instruction to replace * using the [Match.StringMatch] list from the [Match]. */ - fun Fingerprint.replaceWith( + fun MutableMethod.replaceWith( string: String, - getReplacementIndex: List.() -> Int, - ) = method.apply { - val replacementIndex = stringMatches.getReplacementIndex() - val clientIdRegister = getInstruction(replacementIndex).registerA + offset: Int, + getReplacementIndex: String + ) { + val anchorIndex = indexOfFirstInstructionOrThrow { + opcode == Opcode.CONST_STRING && getReference()?.string == string + } - replaceInstruction(replacementIndex, "const-string v$clientIdRegister, \"$string\"") + val targetIndex = anchorIndex + offset + val clientIdRegister = getInstruction(targetIndex).registerA + + replaceInstruction(targetIndex, "const-string v$clientIdRegister, \"$getReplacementIndex\"") } // Patch OAuth authorization. - buildAuthorizationStringFingerprint.replaceWith(clientId!!) { first().index + 4 } + buildAuthorizationStringMethod.replaceWith( + string = "yyOCBp.RHJhDKd", + offset = 4, + getReplacementIndex = clientId!! + ) // Path basic authorization. - basicAuthorizationFingerprint.replaceWith("$clientId:") { last().index + 7 } + basicAuthorizationMethod.replaceWith( + string = "fJOxVwBUyo*=f:()?.contains("old.reddit.com") == true + getReference()?.string?.contains("old.reddit.com") == true } val targetRegister = getInstruction(index).registerA