feat(Infinity for Reddit - Spoof client): Support latest version
This commit is contained in:
parent
25ebf61b75
commit
ca42fd9365
|
@ -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<MethodFingerprintResult>.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<OneRegisterInstruction>(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<MethodFingerprintResult>.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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
)
|
|
@ -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)
|
|
@ -1,3 +0,0 @@
|
|||
package app.revanced.patches.reddit.customclients.infinityforreddit.api.fingerprints
|
||||
|
||||
object GetHttpBasicAuthHeaderFingerprint : AbstractClientIdFingerprint(additionalStrings = arrayOf("Authorization"))
|
|
@ -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;")
|
||||
})
|
Loading…
Reference in a new issue