generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(redditisfun): add
change-oauth-client-id
patch
- Loading branch information
Showing
4 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../patches/reddit/customclients/redditisfun/api/fingerprints/AbstractClientIdFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint | ||
|
||
abstract class AbstractClientIdFingerprint(string: String) : MethodFingerprint( | ||
strings = listOfNotNull("yyOCBp.RHJhDKd", string), | ||
) |
5 changes: 5 additions & 0 deletions
5
...atches/reddit/customclients/redditisfun/api/fingerprints/BasicAuthorizationFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints | ||
|
||
object BasicAuthorizationFingerprint : AbstractClientIdFingerprint( | ||
string = "fJOxVwBUyo*=f:<OoejWs:AqmIJ", // Encrypted basic authorization string. | ||
) |
5 changes: 5 additions & 0 deletions
5
.../reddit/customclients/redditisfun/api/fingerprints/BuildAuthorizationStringFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints | ||
|
||
object BuildAuthorizationStringFingerprint : AbstractClientIdFingerprint( | ||
string = "client_id" | ||
) |
57 changes: 57 additions & 0 deletions
57
...p/revanced/patches/reddit/customclients/redditisfun/api/patch/ChangeOAuthClientIdPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package app.revanced.patches.reddit.customclients.redditisfun.api.patch | ||
|
||
import app.revanced.patcher.annotation.Compatibility | ||
import app.revanced.patcher.annotation.Package | ||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult | ||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult.MethodFingerprintScanResult.StringsScanResult.StringMatch | ||
import app.revanced.patcher.patch.PatchResult | ||
import app.revanced.patcher.patch.PatchResultSuccess | ||
import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch | ||
import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation | ||
import app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints.BasicAuthorizationFingerprint | ||
import app.revanced.patches.reddit.customclients.redditisfun.api.fingerprints.BuildAuthorizationStringFingerprint | ||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction | ||
|
||
@ChangeOAuthClientIdPatchAnnotation | ||
@Compatibility([Package("com.andrewshu.android.reddit")]) | ||
class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch( | ||
"redditisfun://auth", | ||
Options, | ||
listOf( | ||
BuildAuthorizationStringFingerprint, | ||
BasicAuthorizationFingerprint, | ||
) | ||
) { | ||
override fun List<MethodFingerprintResult>.patch(context: BytecodeContext): PatchResult { | ||
/** | ||
* Replaces a one register instruction with a const-string instruction | ||
* at the index returned by [getReplacementIndex]. | ||
* | ||
* @param string The string to replace the instruction with. | ||
* @param getReplacementIndex A function that returns the index of the instruction to replace | ||
* using the [StringMatch] list from the [MethodFingerprintResult]. | ||
*/ | ||
fun MethodFingerprintResult.replaceWith( | ||
string: String, | ||
getReplacementIndex: List<StringMatch>.() -> Int, | ||
) = mutableMethod.apply { | ||
val replacementIndex = scanResult.stringsScanResult!!.matches.getReplacementIndex() | ||
val clientIdRegister = getInstruction<OneRegisterInstruction>(replacementIndex).registerA | ||
|
||
replaceInstruction(replacementIndex, "const-string v$clientIdRegister, \"$string\"") | ||
} | ||
|
||
// Patch OAuth authorization. | ||
first().replaceWith(clientId!!) { first().index + 4 } | ||
|
||
// Path basic authorization. | ||
last().replaceWith("$clientId:") { last().index + 7 } | ||
|
||
return PatchResultSuccess() | ||
} | ||
|
||
companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer() | ||
} |