From ca42fd93656eae6a5f5f0086e3cf574fb6f4f11e Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sat, 2 Dec 2023 17:26:41 +0100 Subject: [PATCH] feat(Infinity for Reddit - Spoof client): Support latest version --- .../infinityforreddit/api/SpoofClientPatch.kt | 75 ++++++++----------- ...sFingerprint.kt => APIUtilsFingerprint.kt} | 4 +- .../AbstractClientIdFingerprint.kt | 17 ----- .../GetHttpBasicAuthHeaderFingerprint.kt | 3 - .../LoginActivityOnCreateFingerprint.kt | 5 -- 5 files changed, 32 insertions(+), 72 deletions(-) rename src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/{SetWebViewSettingsFingerprint.kt => APIUtilsFingerprint.kt} (53%) delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/AbstractClientIdFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/GetHttpBasicAuthHeaderFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/LoginActivityOnCreateFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt index 0b3c3e87..0a4fed05 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt @@ -1,69 +1,54 @@ package app.revanced.patches.reddit.customclients.infinityforreddit.api import app.revanced.patcher.data.BytecodeContext -import app.revanced.patcher.extensions.InstructionExtensions.addInstructions -import app.revanced.patcher.extensions.InstructionExtensions.getInstruction -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction +import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable +import app.revanced.patcher.util.smali.toInstructions import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch -import app.revanced.patches.reddit.customclients.Constants.OAUTH_USER_AGENT -import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.GetHttpBasicAuthHeaderFingerprint -import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.LoginActivityOnCreateFingerprint -import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.SetWebViewSettingsFingerprint -import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.APIUtilsFingerprint +import com.android.tools.smali.dexlib2.AccessFlags +import com.android.tools.smali.dexlib2.immutable.ImmutableMethod +import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation @Patch( name = "Spoof client", description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [ - CompatiblePackage( - "ml.docilealligator.infinityforreddit", [ - "5.4.0", - "5.4.1", - "5.4.2", - "6.0.1", - "6.0.2", - "6.0.4", - "6.0.6", - "6.1.1" - ] - ) + CompatiblePackage("ml.docilealligator.infinityforreddit") ] ) @Suppress("unused") object SpoofClientPatch : AbstractSpoofClientPatch( "infinity://localhost", - clientIdFingerprints = listOf(GetHttpBasicAuthHeaderFingerprint, LoginActivityOnCreateFingerprint), - userAgentFingerprints = listOf(SetWebViewSettingsFingerprint) + clientIdFingerprints = listOf(APIUtilsFingerprint), ) { override fun List.patchClientId(context: BytecodeContext) { - forEach { - // First is index of the clientId string. - val clientIdIndex = it.scanResult.stringsScanResult!!.matches.first().index - it.mutableMethod.apply { - val oAuthClientIdRegister = getInstruction(clientIdIndex).registerA + first().mutableClass.methods.apply { + val getClientIdMethod = single { it.name == "getId" }.also(::remove) - replaceInstruction( - clientIdIndex, - "const-string v$oAuthClientIdRegister, \"$clientId\"" - ) - } - } - } + val newGetClientIdMethod = ImmutableMethod( + getClientIdMethod.definingClass, + getClientIdMethod.name, + null, + getClientIdMethod.returnType, + AccessFlags.PUBLIC or AccessFlags.STATIC, + null, + null, + ImmutableMethodImplementation( + 1, + """ + const-string v0, "$clientId" + return-object v0 + """.toInstructions(getClientIdMethod), + null, + null, + ), + ).toMutable() - override fun List.patchUserAgent(context: BytecodeContext) { - first().let { result -> - val insertIndex = result.scanResult.stringsScanResult!!.matches.first().index - - result.mutableMethod.addInstructions( - insertIndex, - """ - const-string v0, "$OAUTH_USER_AGENT" - invoke-virtual {p1, v0}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V - """ - ) + add(newGetClientIdMethod) } } } diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/SetWebViewSettingsFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/APIUtilsFingerprint.kt similarity index 53% rename from src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/SetWebViewSettingsFingerprint.kt rename to src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/APIUtilsFingerprint.kt index 1314d722..13d9595b 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/SetWebViewSettingsFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/APIUtilsFingerprint.kt @@ -2,6 +2,6 @@ package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerpr import app.revanced.patcher.fingerprint.MethodFingerprint -object SetWebViewSettingsFingerprint : MethodFingerprint( - strings= listOf("https://www.reddit.com/api/v1/authorize.compact") +object APIUtilsFingerprint : MethodFingerprint( + strings = listOf("native-lib") ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/AbstractClientIdFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/AbstractClientIdFingerprint.kt deleted file mode 100644 index 24e7d67a..00000000 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/AbstractClientIdFingerprint.kt +++ /dev/null @@ -1,17 +0,0 @@ -package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints - -import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.iface.ClassDef -import com.android.tools.smali.dexlib2.iface.Method - -/** - * Fingerprint for a method that has the client id hardcoded in it. - * The first string in the fingerprint is the client id. - * - * @param customFingerprint A custom fingerprint. - * @param additionalStrings Additional strings to add to the fingerprint. - */ -abstract class AbstractClientIdFingerprint( - customFingerprint: ((methodDef: Method, classDef: ClassDef) -> Boolean)? = null, - vararg additionalStrings: String -) : MethodFingerprint(strings = listOf("NOe2iKrPPzwscA", *additionalStrings), customFingerprint = customFingerprint) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/GetHttpBasicAuthHeaderFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/GetHttpBasicAuthHeaderFingerprint.kt deleted file mode 100644 index 59c897de..00000000 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/GetHttpBasicAuthHeaderFingerprint.kt +++ /dev/null @@ -1,3 +0,0 @@ -package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints - -object GetHttpBasicAuthHeaderFingerprint : AbstractClientIdFingerprint(additionalStrings = arrayOf("Authorization")) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/LoginActivityOnCreateFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/LoginActivityOnCreateFingerprint.kt deleted file mode 100644 index 26687b4e..00000000 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/fingerprints/LoginActivityOnCreateFingerprint.kt +++ /dev/null @@ -1,5 +0,0 @@ -package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints - -object LoginActivityOnCreateFingerprint : AbstractClientIdFingerprint(custom@{ methodDef, classDef -> - methodDef.name == "onCreate" && classDef.type.endsWith("LoginActivity;") -}) \ No newline at end of file