mirror of
https://github.com/ReVanced/revanced-patches.git
synced 2026-01-25 11:41:04 +00:00
refactor(baconreader): SpoofClientPatch
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
package app.revanced.patches.reddit.customclients.baconreader.api
|
||||
|
||||
import app.revanced.patcher.fingerprint
|
||||
import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMutableMethodDeclaratively
|
||||
import app.revanced.patcher.definingClass
|
||||
import app.revanced.patcher.name
|
||||
import app.revanced.patcher.patch.BytecodePatchContext
|
||||
|
||||
internal val getAuthorizationUrlFingerprint = fingerprint {
|
||||
strings("client_id=zACVn0dSFGdWqQ")
|
||||
}
|
||||
internal val getClientIdFingerprint = fingerprint {
|
||||
strings("client_id=zACVn0dSFGdWqQ")
|
||||
custom { method, classDef ->
|
||||
if (!classDef.endsWith("RedditOAuth;")) return@custom false
|
||||
internal val BytecodePatchContext.getAuthorizationUrlMethod by gettingFirstMutableMethodDeclaratively(
|
||||
"client_id=zACVn0dSFGdWqQ"
|
||||
)
|
||||
|
||||
method.name == "getAuthorizeUrl"
|
||||
}
|
||||
internal val BytecodePatchContext.getClientIdMethod by gettingFirstMutableMethodDeclaratively("client_id=zACVn0dSFGdWqQ") {
|
||||
name("getAuthorizeUrl")
|
||||
definingClass { endsWith("RedditOAuth;") }
|
||||
}
|
||||
|
||||
internal val requestTokenFingerprint = fingerprint {
|
||||
strings("zACVn0dSFGdWqQ", "kDm2tYpu9DqyWFFyPlNcXGEni4k") // App ID and secret.
|
||||
}
|
||||
internal val BytecodePatchContext.requestTokenMethod by gettingFirstMutableMethodDeclaratively(
|
||||
"zACVn0dSFGdWqQ",
|
||||
"kDm2tYpu9DqyWFFyPlNcXGEni4k"
|
||||
)
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package app.revanced.patches.reddit.customclients.baconreader.api
|
||||
|
||||
import app.revanced.patcher.Fingerprint
|
||||
import app.revanced.patcher.extensions.getInstruction
|
||||
import app.revanced.patcher.extensions.replaceInstruction
|
||||
import app.revanced.patches.reddit.customclients.spoofClientPatch
|
||||
import app.revanced.patches.shared.misc.string.replaceStringPatch
|
||||
import app.revanced.util.getReference
|
||||
import app.revanced.util.indexOfFirstInstructionOrThrow
|
||||
import com.android.tools.smali.dexlib2.Opcode
|
||||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||
import com.android.tools.smali.dexlib2.iface.reference.StringReference
|
||||
import com.android.tools.smali.dexlib2.mutable.MutableMethod
|
||||
|
||||
val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/auth") { clientIdOption ->
|
||||
dependsOn(
|
||||
@@ -22,22 +26,22 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/au
|
||||
val clientId by clientIdOption
|
||||
|
||||
apply {
|
||||
fun Fingerprint.patch(replacementString: String) {
|
||||
val clientIdIndex = stringMatches.first().index
|
||||
|
||||
method.apply {
|
||||
val clientIdRegister = getInstruction<OneRegisterInstruction>(clientIdIndex).registerA
|
||||
replaceInstruction(
|
||||
clientIdIndex,
|
||||
"const-string v$clientIdRegister, \"$replacementString\"",
|
||||
)
|
||||
fun MutableMethod.patch(targetString: String, replacementString: String) {
|
||||
val clientIdIndex = indexOfFirstInstructionOrThrow {
|
||||
opcode == Opcode.CONST_STRING && getReference<StringReference>()?.string == targetString
|
||||
}
|
||||
|
||||
val clientIdRegister = getInstruction<OneRegisterInstruction>(clientIdIndex).registerA
|
||||
replaceInstruction(
|
||||
clientIdIndex,
|
||||
"const-string v$clientIdRegister, \"$replacementString\"",
|
||||
)
|
||||
}
|
||||
|
||||
// Patch client id in authorization url.
|
||||
getAuthorizationUrlFingerprint.patch("client_id=$clientId")
|
||||
getAuthorizationUrlMethod.patch("client_id=zACVn0dSFGdWqQ", "client_id=$clientId")
|
||||
|
||||
// Patch client id for access token request.
|
||||
requestTokenFingerprint.patch(clientId!!)
|
||||
requestTokenMethod.patch("zACVn0dSFGdWqQ", clientId!!)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user