forked from ReVanced/revanced-patches
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Sync for Reddit): Add
Fix /user/ endpoint
patch
- Loading branch information
Showing
9 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
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
60 changes: 60 additions & 0 deletions
60
.../app/revanced/patches/reddit/customclients/syncforreddit/fix/user/FixUserEndpointPatch.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,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<OneRegisterInstruction>(userPathStringIndex) | ||
val userPathStringRegister = userPathStringInstruction.registerA | ||
val fixedUserPathString = userPathStringInstruction.getReference<StringReference>()!!.string.replace("u/", "user/") | ||
|
||
method.replaceInstruction( | ||
userPathStringIndex, | ||
"const-string v$userPathStringRegister, \"${fixedUserPathString}\"", | ||
) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...s/reddit/customclients/syncforreddit/fix/user/fingerprints/BaseUserEndpointFingerprint.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,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 }, | ||
) |
3 changes: 3 additions & 0 deletions
3
...reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthFriendRequestFingerprint.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,3 @@ | ||
package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints | ||
|
||
internal object OAuthFriendRequestFingerprint : BaseUserEndpointFingerprint("OAuthFriendRequest.java") |
10 changes: 10 additions & 0 deletions
10
...ts/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestConstructorFingerprint.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,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, | ||
) |
10 changes: 10 additions & 0 deletions
10
...clients/syncforreddit/fix/user/fingerprints/OAuthSubredditInfoRequestHelperFingerprint.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,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, | ||
) |
3 changes: 3 additions & 0 deletions
3
...ddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUnfriendRequestFingerprint.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,3 @@ | ||
package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints | ||
|
||
internal object OAuthUnfriendRequestFingerprint : BaseUserEndpointFingerprint("OAuthUnfriendRequest.java") |
3 changes: 3 additions & 0 deletions
3
...reddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserIdRequestFingerprint.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,3 @@ | ||
package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints | ||
|
||
internal object OAuthUserIdRequestFingerprint : BaseUserEndpointFingerprint("OAuthUserIdRequest.java") |
3 changes: 3 additions & 0 deletions
3
...ddit/customclients/syncforreddit/fix/user/fingerprints/OAuthUserInfoRequestFingerprint.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,3 @@ | ||
package app.revanced.patches.reddit.customclients.syncforreddit.fix.user.fingerprints | ||
|
||
internal object OAuthUserInfoRequestFingerprint : BaseUserEndpointFingerprint("OAuthUserInfoRequest.java") |