Skip to content

Commit

Permalink
feat(Joey for Reddit): Add Change OAuth client id patch
Browse files Browse the repository at this point in the history
  • Loading branch information
barncastle authored and oSumAtrIX committed Jul 30, 2023
1 parent 2ef62e5 commit 1bac47d
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.api.fingerprints

import app.revanced.patcher.extensions.or
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

object GetClientIdFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC,
opcodes = listOf(
Opcode.CONST, // R.string.valuable_cid
Opcode.INVOKE_STATIC, // StringMaster.decrypt
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT
),
customFingerprint = custom@{ _, classDef ->
classDef.sourceFile == "AuthUtility.java"
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.api.patch

import app.revanced.patcher.annotation.Compatibility
import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Package
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patches.reddit.customclients.AbstractChangeOAuthClientIdPatch
import app.revanced.patches.reddit.customclients.ChangeOAuthClientIdPatchAnnotation
import app.revanced.patches.reddit.customclients.joeyforreddit.api.fingerprints.GetClientIdFingerprint
import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.patch.DisablePiracyDetectionPatch

@ChangeOAuthClientIdPatchAnnotation
@Description(
"Changes the OAuth client ID. " +
"The OAuth application type has to be \"Installed app\" " +
"and the redirect URI has to be set to \"https://127.0.0.1:65023/authorize_callback\"."
)
@Compatibility(
[
Package("o.o.joey"),
Package("o.o.joey.pro"),
Package("o.o.joey.dev")
]
)
@DependsOn([DisablePiracyDetectionPatch::class])
class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(
"https://127.0.0.1:65023/authorize_callback", Options, listOf(GetClientIdFingerprint)
) {
override fun List<MethodFingerprintResult>.patch(context: BytecodeContext): PatchResult {
first().mutableMethod.addInstructions(
0,
"""
const-string v0, "$clientId"
return-object v0
"""
)

return PatchResultSuccess()
}

companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode

object PiracyDetectionFingerprint : MethodFingerprint(
returnType = "V",
accessFlags = AccessFlags.PRIVATE or AccessFlags.STATIC,
opcodes = listOf(
Opcode.NEW_INSTANCE, // new PiracyDetectionRunnable()
Opcode.CONST_16,
Opcode.CONST_WIDE_16,
Opcode.INVOKE_DIRECT, // <init>(..)
Opcode.INVOKE_VIRTUAL, // run()
Opcode.RETURN_VOID
),
customFingerprint = custom@{ _, classDef ->
classDef.type.endsWith("ProcessLifeCyleListener;")
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.patch

import app.revanced.extensions.toErrorResult
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.fingerprints.PiracyDetectionFingerprint

class DisablePiracyDetectionPatch : BytecodePatch(listOf(PiracyDetectionFingerprint)) {
override fun execute(context: BytecodeContext): PatchResult {
PiracyDetectionFingerprint.result?.mutableMethod?.addInstruction(
0,
"""
return-void
"""
) ?: return PiracyDetectionFingerprint.toErrorResult()

return PatchResultSuccess()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import app.revanced.patches.reddit.customclients.syncforreddit.detection.piracy.
@Patch
@Name("Disable ads")
@DependsOn([DisablePiracyDetectionPatch::class])
@Description("Disables ads.")
@Compatibility([Package("com.laurencedawson.reddit_sync")])
class DisableAdsPatch : BytecodePatch(listOf(IsAdsEnabledFingerprint)) {
override fun execute(context: BytecodeContext): PatchResult {
Expand Down

0 comments on commit 1bac47d

Please sign in to comment.