feat: Use properties file for Client spoof patches

This commit is contained in:
oSumAtrIX 2023-10-03 01:28:22 +02:00
parent 46f135892a
commit e5d548c642
No known key found for this signature in database
GPG Key ID: A9B3094ACDB604B4
9 changed files with 62 additions and 41 deletions

View File

@ -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<MethodFingerprint>?.executePatch(
@ -85,5 +120,6 @@ abstract class AbstractSpoofClientPatch(
*
* @param context The current [BytecodeContext].
*/
open fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) { }
// Not every client needs to patch miscellaneous things.
open fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) {}
}

View File

@ -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")

View File

@ -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")

View File

@ -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", [

View File

@ -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"),

View File

@ -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")

View File

@ -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")

View File

@ -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")

View File

@ -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"),