Skip to content

Commit

Permalink
feat(Infinity for Reddit - Spoof client): Support latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Dec 2, 2023
1 parent 25ebf61 commit ca42fd9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -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\""
)
}
}
}

override fun List<MethodFingerprintResult>.patchUserAgent(context: BytecodeContext) {
first().let { result ->
val insertIndex = result.scanResult.stringsScanResult!!.matches.first().index
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()

result.mutableMethod.addInstructions(
insertIndex,
"""
const-string v0, "$OAUTH_USER_AGENT"
invoke-virtual {p1, v0}, Landroid/webkit/WebSettings;->setUserAgentString(Ljava/lang/String;)V
"""
)
add(newGetClientIdMethod)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit ca42fd9

Please sign in to comment.