Skip to content

Commit

Permalink
fix(boostforreddit): use correct options
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Jun 20, 2023
1 parent edd67b8 commit ec39732
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import android.os.Environment
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import app.revanced.patcher.patch.*
import app.revanced.patches.reddit.customclients.boostforreddit.api.patch.ChangeOAuthClientIdPatch
import app.revanced.patches.reddit.customclients.syncforreddit.api.patch.ChangeOAuthClientIdPatch.Companion.clientId
import java.io.File

abstract class AbstractChangeOAuthClientIdPatch(
private val redirectUri: String,
private val options: ChangeOAuthClientIdOptionsContainer,
private val fingerprint: MethodFingerprint,
) : BytecodePatch(listOf(fingerprint)) {
override fun execute(context: BytecodeContext): PatchResult {
if (ChangeOAuthClientIdPatch.clientId == null) {
if (options.clientId == null) {
// Test if on Android
try {
Class.forName("android.os.Environment")
Expand All @@ -30,11 +29,11 @@ abstract class AbstractChangeOAuthClientIdPatch(
Alternatively, you can provide the client ID using patch options.
You can get your client ID from https://www.reddit.com/prefs/apps.
The application type has to be "installed app" and the redirect URI has to be set to "$redirectUri"
The application type has to be "Installed app" and the redirect URI has to be set to "$redirectUri".
""".trimIndent()

return PatchResultError(error)
}.let { clientId = it.readText().trim() }
}.let { options.clientId = it.readText().trim() }
}

return fingerprint.patch(context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints
@Version("0.0.1")
class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(
"http://rubenmayayo.com",
Options,
GetClientIdFingerprint
) {
override fun MethodFingerprint.patch(context: BytecodeContext): PatchResult {
Expand All @@ -32,5 +33,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(
return PatchResultSuccess()
}

companion object : Options.ChangeOAuthClientIdOptionsContainer()
companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer()
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import org.jf.dexlib2.iface.instruction.ReferenceInstruction
import org.jf.dexlib2.iface.reference.StringReference
import java.util.*


@Patch
@Name("change-oauth-client-id")
@Description("Changes the OAuth client ID.")
@Compatibility([Package("com.laurencedawson.reddit_sync"), Package("com.laurencedawson.reddit_sync.pro")])
@Version("0.0.1")
class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(
"http://redditsync/auth",
Options,
GetAuthorizationStringFingerprint,
) {
override fun MethodFingerprint.patch(context: BytecodeContext): PatchResult {
Expand All @@ -51,7 +51,7 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(

val newAuthorizationUrl = reference.string.replace(
"client_id=.*?&".toRegex(),
"client_id=${clientId!!}&"
"client_id=$clientId&"
)

replaceInstruction(
Expand All @@ -64,5 +64,5 @@ class ChangeOAuthClientIdPatch : AbstractChangeOAuthClientIdPatch(
return PatchResultSuccess()
}

companion object : Options.ChangeOAuthClientIdOptionsContainer()
companion object Options : AbstractChangeOAuthClientIdPatch.Options.ChangeOAuthClientIdOptionsContainer()
}

0 comments on commit ec39732

Please sign in to comment.