diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt index 373589f0dd..ca00ee71f5 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/AbstractSpoofClientPatch.kt @@ -7,8 +7,10 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.options.PatchOptionException import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption import java.io.File +import java.util.* abstract class AbstractSpoofClientPatch( private val redirectUri: String, @@ -24,32 +26,65 @@ abstract class AbstractSpoofClientPatch( "client-id", null, "OAuth client ID", - "The Reddit OAuth client ID." + "The Reddit OAuth client ID. " + + "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\"", + true ) override fun execute(context: BytecodeContext) { - if (clientId == null) { - // Ensure device runs Android. - try { - Class.forName("android.os.Environment") - } catch (e: ClassNotFoundException) { - throw PatchException("No client ID provided") + val requiredOptions = options.values.filter { it.required } + + val isAndroidButRequiredOptionsUnset = try { + Class.forName("android.os.Environment") + + requiredOptions.any { it.value == null } + } catch (_: ClassNotFoundException) { + false + } + + if (isAndroidButRequiredOptionsUnset) { + val properties = Properties() + + val propertiesFile = File( + Environment.getExternalStorageDirectory(), + "revanced_client_spoof_${redirectUri.hashCode()}.properties" + ) + if (propertiesFile.exists()) { + properties.load(propertiesFile.inputStream()) + + // Set options from properties file. + properties.forEach { (name, value) -> + try { + options[name.toString()] = value.toString().trim() + } catch (_: PatchOptionException.PatchOptionNotFoundException) { + // Ignore unknown options. + } + } + } else { + options.keys.forEach { properties.setProperty(it, "") } + + properties.store( + propertiesFile.outputStream(), + "Options for the ReVanced \"Client Spoof\" patch. Required options: " + + requiredOptions.joinToString { it.key } + ) } - File(Environment.getExternalStorageDirectory(), "reddit_client_id_revanced.txt").also { - if (it.exists()) return@also + requiredOptions.filter { it.value == null }.let { requiredUnsetOptions -> + if (requiredUnsetOptions.isEmpty()) return@let val error = """ - In order to use this patch, you need to provide a client ID. - You can do that by creating a file at ${it.absolutePath} with the client ID as its content. - 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". + In order to use this patch, you need to provide the following options: + ${requiredUnsetOptions.joinToString("\n") { "${it.key}: ${it.description}" }} + + A properties file has been created at ${propertiesFile.absolutePath}. + Please fill in the required options before using this patch. """.trimIndent() throw PatchException(error) - }.let { clientId = it.readText().trim() } + } } fun List?.executePatch( @@ -85,5 +120,6 @@ abstract class AbstractSpoofClientPatch( * * @param context The current [BytecodeContext]. */ - open fun List.patchMiscellaneous(context: BytecodeContext) { } + // Not every client needs to patch miscellaneous things. + open fun List.patchMiscellaneous(context: BytecodeContext) {} } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt index 7c5da73f50..e85019073c 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt @@ -14,9 +14,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"http://baconreader.com/auth\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [ CompatiblePackage("com.onelouder.baconreader"), CompatiblePackage("com.onelouder.baconreader.premium") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt index c70c7ece7d..137cb137a4 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt @@ -10,9 +10,7 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"http://rubenmayayo.com\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [CompatiblePackage("com.rubenmayayo.reddit")] ) @Suppress("unused") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt index 2214f82c53..5a2a7e968a 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt @@ -13,9 +13,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"infinity://localhost\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [ CompatiblePackage( "ml.docilealligator.infinityforreddit", [ diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt index 3d51bcbe02..29ab8a71de 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt @@ -12,9 +12,7 @@ import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy. @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "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\".", + description = "Restores functionality of the app by using custom client ID's.", dependencies = [DisablePiracyDetectionPatch::class], compatiblePackages = [ CompatiblePackage("o.o.joey"), diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt index 304d44c18f..026870b207 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt @@ -16,9 +16,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"redditisfun://auth\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [ CompatiblePackage("com.andrewshu.android.reddit"), CompatiblePackage("com.andrewshu.android.redditdonation") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt index 8cd5613f5a..690e17861e 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt @@ -13,9 +13,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"dbrady://relay\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [ CompatiblePackage("free.reddit.news"), CompatiblePackage("reddit.news") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt index af79f9e6a0..88c85abf72 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt @@ -10,9 +10,7 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"http://www.ccrama.me\".", + description = "Restores functionality of the app by using custom client ID's.", compatiblePackages = [CompatiblePackage("me.ccrama.redditslide")] ) @Suppress("unused") diff --git a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/SpoofClientPatch.kt b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/SpoofClientPatch.kt index 4cc08d3b71..074323e88d 100644 --- a/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/SpoofClientPatch.kt +++ b/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/api/SpoofClientPatch.kt @@ -9,6 +9,7 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion. 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.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption import app.revanced.patches.reddit.customclients.AbstractSpoofClientPatch import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetAuthorizationStringFingerprint import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetBearerTokenFingerprint @@ -20,9 +21,7 @@ import java.util.* @Patch( name = "Spoof client", - description = "Spoofs the client in order to allow logging in. " + - "The OAuth application type has to be \"Installed app\" " + - "and the redirect URI has to be set to \"http://redditsync/auth\".", + description = "Restores functionality of the app by using custom client ID's.", dependencies = [DisablePiracyDetectionPatch::class], compatiblePackages = [ CompatiblePackage("com.laurencedawson.reddit_sync"),