refactor(redditisfun): SpoofClientPatch
This commit is contained in:
parent
94cc175b55
commit
8dfcbd09cc
2 changed files with 50 additions and 32 deletions
|
|
@ -1,31 +1,35 @@
|
||||||
package app.revanced.patches.reddit.customclients.redditisfun.api
|
package app.revanced.patches.reddit.customclients.redditisfun.api
|
||||||
|
|
||||||
import app.revanced.patcher.fingerprint
|
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
|
||||||
|
import app.revanced.patcher.accessFlags
|
||||||
|
import app.revanced.patcher.instructions
|
||||||
|
import app.revanced.patcher.invoke
|
||||||
|
import app.revanced.patcher.parameterTypes
|
||||||
|
import app.revanced.patcher.patch.BytecodePatchContext
|
||||||
|
import app.revanced.patcher.returnType
|
||||||
import com.android.tools.smali.dexlib2.AccessFlags
|
import com.android.tools.smali.dexlib2.AccessFlags
|
||||||
import com.android.tools.smali.dexlib2.Opcode
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
|
|
||||||
internal fun baseClientIdFingerprint(string: String) = fingerprint {
|
internal val BytecodePatchContext.basicAuthorizationMethod by gettingFirstMutableMethodDeclaratively(
|
||||||
strings("yyOCBp.RHJhDKd", string)
|
"yyOCBp.RHJhDKd",
|
||||||
}
|
"fJOxVwBUyo*=f:<OoejWs:AqmIJ" // Encrypted basic authorization string.
|
||||||
|
|
||||||
internal val basicAuthorizationFingerprint = baseClientIdFingerprint(
|
|
||||||
string = "fJOxVwBUyo*=f:<OoejWs:AqmIJ", // Encrypted basic authorization string.
|
|
||||||
)
|
)
|
||||||
|
|
||||||
internal val buildAuthorizationStringFingerprint = baseClientIdFingerprint(
|
internal val BytecodePatchContext.buildAuthorizationStringMethod by gettingFirstMutableMethodDeclaratively(
|
||||||
string = "client_id",
|
"yyOCBp.RHJhDKd",
|
||||||
|
"client_id"
|
||||||
)
|
)
|
||||||
|
|
||||||
internal val getUserAgentFingerprint = fingerprint {
|
internal val BytecodePatchContext.getUserAgentMethod by gettingFirstMutableMethodDeclaratively {
|
||||||
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
|
accessFlags(AccessFlags.PUBLIC, AccessFlags.STATIC)
|
||||||
returns("Ljava/lang/String;")
|
returnType("Ljava/lang/String;")
|
||||||
parameters()
|
parameterTypes()
|
||||||
opcodes(
|
instructions(
|
||||||
Opcode.NEW_ARRAY,
|
Opcode.NEW_ARRAY(),
|
||||||
Opcode.CONST_4,
|
Opcode.CONST_4(),
|
||||||
Opcode.INVOKE_STATIC,
|
Opcode.INVOKE_STATIC(),
|
||||||
Opcode.MOVE_RESULT_OBJECT,
|
Opcode.MOVE_RESULT_OBJECT(),
|
||||||
Opcode.APUT_OBJECT,
|
Opcode.APUT_OBJECT(),
|
||||||
Opcode.CONST,
|
Opcode.CONST(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,17 @@
|
||||||
package app.revanced.patches.reddit.customclients.redditisfun.api
|
package app.revanced.patches.reddit.customclients.redditisfun.api
|
||||||
|
|
||||||
import app.revanced.patcher.Fingerprint
|
|
||||||
import app.revanced.patcher.Match
|
|
||||||
import app.revanced.patcher.extensions.getInstruction
|
import app.revanced.patcher.extensions.getInstruction
|
||||||
import app.revanced.patcher.extensions.replaceInstruction
|
import app.revanced.patcher.extensions.replaceInstruction
|
||||||
import app.revanced.patches.reddit.customclients.spoofClientPatch
|
import app.revanced.patches.reddit.customclients.spoofClientPatch
|
||||||
import app.revanced.util.getReference
|
import app.revanced.util.getReference
|
||||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||||
import app.revanced.util.returnEarly
|
import app.revanced.util.returnEarly
|
||||||
|
import com.android.tools.smali.dexlib2.Opcode
|
||||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
||||||
|
import com.android.tools.smali.dexlib2.mutable.MutableMethod
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { clientIdOption ->
|
val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { clientIdOption ->
|
||||||
compatibleWith(
|
compatibleWith(
|
||||||
"com.andrewshu.android.reddit",
|
"com.andrewshu.android.reddit",
|
||||||
|
|
@ -30,21 +31,34 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
|
||||||
* @param getReplacementIndex A function that returns the index of the instruction to replace
|
* @param getReplacementIndex A function that returns the index of the instruction to replace
|
||||||
* using the [Match.StringMatch] list from the [Match].
|
* using the [Match.StringMatch] list from the [Match].
|
||||||
*/
|
*/
|
||||||
fun Fingerprint.replaceWith(
|
fun MutableMethod.replaceWith(
|
||||||
string: String,
|
string: String,
|
||||||
getReplacementIndex: List<Match.StringMatch>.() -> Int,
|
offset: Int,
|
||||||
) = method.apply {
|
getReplacementIndex: String
|
||||||
val replacementIndex = stringMatches.getReplacementIndex()
|
) {
|
||||||
val clientIdRegister = getInstruction<OneRegisterInstruction>(replacementIndex).registerA
|
val anchorIndex = indexOfFirstInstructionOrThrow {
|
||||||
|
opcode == Opcode.CONST_STRING && getReference<StringReference>()?.string == string
|
||||||
|
}
|
||||||
|
|
||||||
replaceInstruction(replacementIndex, "const-string v$clientIdRegister, \"$string\"")
|
val targetIndex = anchorIndex + offset
|
||||||
|
val clientIdRegister = getInstruction<OneRegisterInstruction>(targetIndex).registerA
|
||||||
|
|
||||||
|
replaceInstruction(targetIndex, "const-string v$clientIdRegister, \"$getReplacementIndex\"")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Patch OAuth authorization.
|
// Patch OAuth authorization.
|
||||||
buildAuthorizationStringFingerprint.replaceWith(clientId!!) { first().index + 4 }
|
buildAuthorizationStringMethod.replaceWith(
|
||||||
|
string = "yyOCBp.RHJhDKd",
|
||||||
|
offset = 4,
|
||||||
|
getReplacementIndex = clientId!!
|
||||||
|
)
|
||||||
|
|
||||||
// Path basic authorization.
|
// Path basic authorization.
|
||||||
basicAuthorizationFingerprint.replaceWith("$clientId:") { last().index + 7 }
|
basicAuthorizationMethod.replaceWith(
|
||||||
|
string = "fJOxVwBUyo*=f:<OoejWs:AqmIJ",
|
||||||
|
offset = 7,
|
||||||
|
getReplacementIndex = "$clientId:"
|
||||||
|
)
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
@ -54,7 +68,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
|
||||||
val randomName = (0..100000).random()
|
val randomName = (0..100000).random()
|
||||||
val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"
|
val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)"
|
||||||
|
|
||||||
getUserAgentFingerprint.method.returnEarly(userAgent)
|
getUserAgentMethod.returnEarly(userAgent)
|
||||||
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
|
@ -62,9 +76,9 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl
|
||||||
|
|
||||||
// Reddit messed up and does not append a redirect uri to the authorization url to old.reddit.com/login.
|
// Reddit messed up and does not append a redirect uri to the authorization url to old.reddit.com/login.
|
||||||
// Replace old.reddit.com with www.reddit.com to fix this.
|
// Replace old.reddit.com with www.reddit.com to fix this.
|
||||||
buildAuthorizationStringFingerprint.method.apply {
|
buildAuthorizationStringMethod.apply {
|
||||||
val index = indexOfFirstInstructionOrThrow {
|
val index = indexOfFirstInstructionOrThrow {
|
||||||
getReference<StringReference>()?.contains("old.reddit.com") == true
|
getReference<StringReference>()?.string?.contains("old.reddit.com") == true
|
||||||
}
|
}
|
||||||
|
|
||||||
val targetRegister = getInstruction<OneRegisterInstruction>(index).registerA
|
val targetRegister = getInstruction<OneRegisterInstruction>(index).registerA
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue