refactor(joeyforreddit): SpoofClientPatch

This commit is contained in:
Pun Butrach
2026-01-12 16:03:25 +07:00
parent cdec438fd4
commit b6c1ec7d18
2 changed files with 27 additions and 22 deletions

View File

@@ -1,28 +1,31 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.api
package app.revanced.patches.reddit.customclients.infinity.api
import com.android.tools.smali.dexlib2.Opcode
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
import app.revanced.patcher.accessFlags
import app.revanced.patcher.classDef
import app.revanced.patcher.custom
import app.revanced.patcher.instructions
import app.revanced.patcher.invoke
import app.revanced.patcher.patch.BytecodePatchContext
import app.revanced.patcher.returnType
import com.android.tools.smali.dexlib2.AccessFlags
import app.revanced.patcher.fingerprint
import com.android.tools.smali.dexlib2.Opcode
internal val authUtilityUserAgentFingerprint = fingerprint {
internal val BytecodePatchContext.authUtilityUserAgentMethod by gettingFirstMutableMethodDeclaratively {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("Ljava/lang/String;")
opcodes(Opcode.APUT_OBJECT)
custom { method, classDef ->
classDef.sourceFile == "AuthUtility.java"
}
returnType("Ljava/lang/String;")
instructions(Opcode.APUT_OBJECT())
custom { classDef.sourceFile == "AuthUtility.java" }
}
internal val getClientIdFingerprint = fingerprint {
internal val BytecodePatchContext.getClientIdMethod by gettingFirstMutableMethodDeclaratively {
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
returns("L")
opcodes(
Opcode.CONST, // R.string.valuable_cid
Opcode.INVOKE_STATIC, // StringMaster.decrypt
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT
returnType("L")
instructions(
Opcode.CONST(),
Opcode.INVOKE_STATIC(),
Opcode.MOVE_RESULT_OBJECT(),
Opcode.RETURN_OBJECT(),
)
custom { _, classDef ->
classDef.sourceFile == "AuthUtility.java"
}
}
custom { classDef.sourceFile == "AuthUtility.java" }
}

View File

@@ -1,5 +1,7 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.api
import app.revanced.patches.reddit.customclients.infinity.api.authUtilityUserAgentMethod
import app.revanced.patches.reddit.customclients.infinity.api.getClientIdMethod
import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.disablePiracyDetectionPatch
import app.revanced.patches.reddit.customclients.spoofClientPatch
import app.revanced.util.returnEarly
@@ -18,7 +20,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "https://127.0.0.1:65023/a
apply {
// region Patch client id.
getClientIdFingerprint.method.returnEarly(clientId!!)
getClientIdMethod.returnEarly(clientId!!)
// endregion
@@ -28,7 +30,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "https://127.0.0.1:65023/a
val randomName = (0..100000).random()
val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"
authUtilityUserAgentFingerprint.method.returnEarly(userAgent)
authUtilityUserAgentMethod.returnEarly(userAgent)
// endregion
}