From 46d11f3530fcdae9ed08b7e93aac235638a92dff Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 12 Sep 2024 20:18:22 +0200 Subject: [PATCH] feat(Sync for Reddit): Add `Fix /user/ endpoint` patch --- api/revanced-patches.api | 6 ++ .../fix/user/FixUserEndpointPatch.kt | 60 +++++++++++++++++++ .../BaseUserEndpointFingerprint.kt | 10 ++++ .../OAuthFriendRequestFingerprint.kt | 3 + ...redditInfoRequestConstructorFingerprint.kt | 10 ++++ ...thSubredditInfoRequestHelperFingerprint.kt | 10 ++++ .../OAuthUnfriendRequestFingerprint.kt | 3 + .../OAuthUserIdRequestFingerprint.kt | 3 + .../OAuthUserInfoRequestFingerprint.kt | 3 + 9 files changed, 108 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/BaseUserEndpointFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthFriendRequestFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestConstructorFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestHelperFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUnfriendRequestFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserIdRequestFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserInfoRequestFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 769746f26..c9b58d288 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -828,6 +828,12 @@ public final class app/revanced/patches/reddit/customclients/syncforreddit/fix/s public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/syncforreddit/fix/slink/FixSLinksPatch; } +public final class app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + public final class app/revanced/patches/reddit/customclients/syncforreddit/misc/integrations/IntegrationsPatch : app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch { public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/syncforreddit/misc/integrations/IntegrationsPatch; } diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch.kt new file mode 100644 index 000000000..9105dda72 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch.kt @@ -0,0 +1,60 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user + +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.MethodFingerprint +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints.* +import app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints.OAuthFriendRequestFingerprint +import app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints.OAuthSubredditInfoRequestHelperFingerprint +import app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints.OAuthUnfriendRequestFingerprint +import app.revanced.util.getReference +import app.revanced.util.resultOrThrow +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.StringReference + +@Patch( + name = "Fix /user/ endpoint", + description = "Fixes the endpoint for viewing user profiles by replacing /u/ with /user/.", + compatiblePackages = [ + CompatiblePackage("com.laurencedawson.reddit_sync"), + CompatiblePackage("com.laurencedawson.reddit_sync.pro"), + CompatiblePackage("com.laurencedawson.reddit_sync.dev"), + ], +) +@Suppress("unused") +object FixUserEndpointPatch : BytecodePatch( + fingerprints = setOf( + OAuthFriendRequestFingerprint, + OAuthSubredditInfoRequestConstructorFingerprint, + OAuthSubredditInfoRequestHelperFingerprint, + OAuthUnfriendRequestFingerprint, + OAuthUserIdRequestFingerprint, + OAuthUserInfoRequestFingerprint, + ), +) { + override fun execute(context: BytecodeContext) { + arrayOf( + OAuthFriendRequestFingerprint, + OAuthSubredditInfoRequestConstructorFingerprint, + OAuthSubredditInfoRequestHelperFingerprint, + OAuthUnfriendRequestFingerprint, + OAuthUserIdRequestFingerprint, + OAuthUserInfoRequestFingerprint, + ).map(MethodFingerprint::resultOrThrow).map { + it.scanResult.stringsScanResult!!.matches.first().index to it.mutableMethod + }.forEach { (userPathStringIndex, method) -> + val userPathStringInstruction = method.getInstruction(userPathStringIndex) + val userPathStringRegister = userPathStringInstruction.registerA + val fixedUserPathString = userPathStringInstruction.getReference()!!.string.replace("u/", "user/") + + method.replaceInstruction( + userPathStringIndex, + "const-string v$userPathStringRegister, \"${fixedUserPathString}\"", + ) + } + } +} diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/BaseUserEndpointFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/BaseUserEndpointFingerprint.kt new file mode 100644 index 000000000..cccd9d102 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/BaseUserEndpointFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal abstract class BaseUserEndpointFingerprint(source: String, accessFlags: Int? = null) : + MethodFingerprint( + accessFlags = accessFlags, + strings = listOf("u/"), + customFingerprint = { _, classDef -> classDef.sourceFile == source }, + ) diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthFriendRequestFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthFriendRequestFingerprint.kt new file mode 100644 index 000000000..82522e88a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthFriendRequestFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +internal object OAuthFriendRequestFingerprint : BaseUserEndpointFingerprint("OAuthFriendRequest.java") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestConstructorFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestConstructorFingerprint.kt new file mode 100644 index 000000000..61326f9b9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestConstructorFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +import app.revanced.patcher.extensions.or +import com.android.tools.smali.dexlib2.AccessFlags + +internal object OAuthSubredditInfoRequestConstructorFingerprint : + BaseUserEndpointFingerprint( + "OAuthSubredditInfoRequest.java", + AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, + ) diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestHelperFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestHelperFingerprint.kt new file mode 100644 index 000000000..a2e648f4a --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestHelperFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +import app.revanced.patcher.extensions.or +import com.android.tools.smali.dexlib2.AccessFlags + +internal object OAuthSubredditInfoRequestHelperFingerprint : + BaseUserEndpointFingerprint( + "OAuthSubredditInfoRequest.java", + AccessFlags.PRIVATE or AccessFlags.STATIC, + ) diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUnfriendRequestFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUnfriendRequestFingerprint.kt new file mode 100644 index 000000000..e2e527b63 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUnfriendRequestFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +internal object OAuthUnfriendRequestFingerprint : BaseUserEndpointFingerprint("OAuthUnfriendRequest.java") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserIdRequestFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserIdRequestFingerprint.kt new file mode 100644 index 000000000..871a604ae --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserIdRequestFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +internal object OAuthUserIdRequestFingerprint : BaseUserEndpointFingerprint("OAuthUserIdRequest.java") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserInfoRequestFingerprint.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserInfoRequestFingerprint.kt new file mode 100644 index 000000000..78cd6e8c5 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserInfoRequestFingerprint.kt @@ -0,0 +1,3 @@ +package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints + +internal object OAuthUserInfoRequestFingerprint : BaseUserEndpointFingerprint("OAuthUserInfoRequest.java")