feat(Infinity for Reddit - Spoof client): Support latest version

This commit is contained in:
oSumAtrIX 2023-12-02 17:26:41 +01:00
parent 25ebf61b75
commit ca42fd9365
No known key found for this signature in database
GPG key ID: A9B3094ACDB604B4
5 changed files with 32 additions and 72 deletions

View file

@ -1,69 +1,54 @@
package app.revanced.patches.reddit.customclients.infinityforreddit.api package app.revanced.patches.reddit.customclients.infinityforreddit.api
import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.or
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction
import app.revanced.patcher.fingerprint.MethodFingerprintResult import app.revanced.patcher.fingerprint.MethodFingerprintResult
import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch 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.AbstractSpoofClientPatch
import app.revanced.patches.reddit.customclients.Constants.OAUTH_USER_AGENT import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.APIUtilsFingerprint
import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.GetHttpBasicAuthHeaderFingerprint import com.android.tools.smali.dexlib2.AccessFlags
import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.LoginActivityOnCreateFingerprint import com.android.tools.smali.dexlib2.immutable.ImmutableMethod
import app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints.SetWebViewSettingsFingerprint import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
@Patch( @Patch(
name = "Spoof client", name = "Spoof client",
description = "Restores functionality of the app by using custom client ID's.", description = "Restores functionality of the app by using custom client ID's.",
compatiblePackages = [ compatiblePackages = [
CompatiblePackage( CompatiblePackage("ml.docilealligator.infinityforreddit")
"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"
]
)
] ]
) )
@Suppress("unused") @Suppress("unused")
object SpoofClientPatch : AbstractSpoofClientPatch( object SpoofClientPatch : AbstractSpoofClientPatch(
"infinity://localhost", "infinity://localhost",
clientIdFingerprints = listOf(GetHttpBasicAuthHeaderFingerprint, LoginActivityOnCreateFingerprint), clientIdFingerprints = listOf(APIUtilsFingerprint),
userAgentFingerprints = listOf(SetWebViewSettingsFingerprint)
) { ) {
override fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext) { override fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext) {
forEach { first().mutableClass.methods.apply {
// First is index of the clientId string. val getClientIdMethod = single { it.name == "getId" }.also(::remove)
val clientIdIndex = it.scanResult.stringsScanResult!!.matches.first().index
it.mutableMethod.apply {
val oAuthClientIdRegister = getInstruction<OneRegisterInstruction>(clientIdIndex).registerA
replaceInstruction( val newGetClientIdMethod = ImmutableMethod(
clientIdIndex, getClientIdMethod.definingClass,
"const-string v$oAuthClientIdRegister, \"$clientId\"" getClientIdMethod.name,
) null,
} getClientIdMethod.returnType,
} AccessFlags.PUBLIC or AccessFlags.STATIC,
} null,
null,
override fun List<MethodFingerprintResult>.patchUserAgent(context: BytecodeContext) { ImmutableMethodImplementation(
first().let { result -> 1,
val insertIndex = result.scanResult.stringsScanResult!!.matches.first().index
result.mutableMethod.addInstructions(
insertIndex,
""" """
const-string v0, "$OAUTH_USER_AGENT" const-string v0, "$clientId"
invoke-virtual {p1, v0}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V return-object v0
""" """.toInstructions(getClientIdMethod),
) null,
null,
),
).toMutable()
add(newGetClientIdMethod)
} }
} }
} }

View file

@ -2,6 +2,6 @@ package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerpr
import app.revanced.patcher.fingerprint.MethodFingerprint import app.revanced.patcher.fingerprint.MethodFingerprint
object SetWebViewSettingsFingerprint : MethodFingerprint( object APIUtilsFingerprint : MethodFingerprint(
strings= listOf("https://www.reddit.com/api/v1/authorize.compact") strings = listOf("native-lib")
) )

View file

@ -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)

View file

@ -1,3 +0,0 @@
package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints
object GetHttpBasicAuthHeaderFingerprint : AbstractClientIdFingerprint(additionalStrings = arrayOf("Authorization"))

View file

@ -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;")
})