Skip to content

Commit

Permalink
fix(Relay - Spoof client): Restore OAuth login
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Sep 24, 2023
1 parent f355dbf commit 96e01f7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@ abstract class AbstractSpoofClientPatch(
private val redirectUri: String,
private val clientIdFingerprints: List<MethodFingerprint>,
private val userAgentFingerprints: List<MethodFingerprint>? = null,
private val miscellaneousFingerprints: List<MethodFingerprint>? = null
) : BytecodePatch(buildSet {
addAll(clientIdFingerprints)
userAgentFingerprints?.let(::addAll)
miscellaneousFingerprints?.let(::addAll)
}) {
var clientId by stringPatchOption(
"client-id",
Expand Down Expand Up @@ -56,21 +58,32 @@ abstract class AbstractSpoofClientPatch(

clientIdFingerprints.executePatch { patchClientId(context) }
userAgentFingerprints.executePatch { patchUserAgent(context) }
miscellaneousFingerprints.executePatch { patchMiscellaneous(context) }
}

/**
* Patch the client ID. The fingerprints are guaranteed to be in the same order as in [clientIdFingerprints].
* Patch the client ID.
* The fingerprints are guaranteed to be in the same order as in [clientIdFingerprints].
*
* @param context The current [BytecodeContext].
*
*/
abstract fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext)

/**
* Patch the user agent. The fingerprints are guaranteed to be in the same order as in [userAgentFingerprints].
* Patch the user agent.
* The fingerprints are guaranteed to be in the same order as in [userAgentFingerprints].
*
* @param context The current [BytecodeContext].
*/
// Not every client needs to patch the user agent.
open fun List<MethodFingerprintResult>.patchUserAgent(context: BytecodeContext) {}

/**
* Patch miscellaneous things such as protection measures.
* The fingerprints are guaranteed to be in the same order as in [miscellaneousFingerprints].
*
* @param context The current [BytecodeContext].
*/
open fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) { }
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package app.revanced.patches.reddit.customclients.relayforreddit.api

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
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.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch
import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetLoggedInBearerTokenFingerprint
import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetLoggedOutBearerTokenFingerprint
import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.GetRefreshTokenFingerprint
import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.LoginActivityClientIdFingerprint
import app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints.*
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch(
Expand All @@ -31,7 +29,8 @@ object SpoofClientPatch : AbstractSpoofClientPatch(
GetLoggedInBearerTokenFingerprint,
GetLoggedOutBearerTokenFingerprint,
GetRefreshTokenFingerprint
)
),
miscellaneousFingerprints = listOf(SetRemoteConfigFingerprint)
) {
override fun List<MethodFingerprintResult>.patchClientId(context: BytecodeContext) {
forEach {
Expand All @@ -46,4 +45,8 @@ object SpoofClientPatch : AbstractSpoofClientPatch(
}
}
}

override fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) =
// Do not load remote config which disables OAuth login remotely
first().mutableMethod.addInstructions(0, "return-void")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package app.revanced.patches.reddit.customclients.relayforreddit.api.fingerprints

import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint

object SetRemoteConfigFingerprint : MethodFingerprint(
strings = listOf("reddit_oauth_url"),
parameters = listOf("Lcom/google/firebase/remoteconfig/FirebaseRemoteConfig;")
)

0 comments on commit 96e01f7

Please sign in to comment.