feat: Use properties file for Client spoof
patches
This commit is contained in:
parent
46f135892a
commit
e5d548c642
|
@ -7,8 +7,10 @@ import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprintResult
|
||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchException
|
import app.revanced.patcher.patch.PatchException
|
||||||
|
import app.revanced.patcher.patch.options.PatchOptionException
|
||||||
import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption
|
import app.revanced.patcher.patch.options.types.StringPatchOption.Companion.stringPatchOption
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
import java.util.*
|
||||||
|
|
||||||
abstract class AbstractSpoofClientPatch(
|
abstract class AbstractSpoofClientPatch(
|
||||||
private val redirectUri: String,
|
private val redirectUri: String,
|
||||||
|
@ -24,32 +26,65 @@ abstract class AbstractSpoofClientPatch(
|
||||||
"client-id",
|
"client-id",
|
||||||
null,
|
null,
|
||||||
"OAuth client ID",
|
"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) {
|
override fun execute(context: BytecodeContext) {
|
||||||
if (clientId == null) {
|
val requiredOptions = options.values.filter { it.required }
|
||||||
// Ensure device runs Android.
|
|
||||||
try {
|
val isAndroidButRequiredOptionsUnset = try {
|
||||||
Class.forName("android.os.Environment")
|
Class.forName("android.os.Environment")
|
||||||
} catch (e: ClassNotFoundException) {
|
|
||||||
throw PatchException("No client ID provided")
|
requiredOptions.any { it.value == null }
|
||||||
|
} catch (_: ClassNotFoundException) {
|
||||||
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
File(Environment.getExternalStorageDirectory(), "reddit_client_id_revanced.txt").also {
|
if (isAndroidButRequiredOptionsUnset) {
|
||||||
if (it.exists()) return@also
|
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 }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
requiredOptions.filter { it.value == null }.let { requiredUnsetOptions ->
|
||||||
|
if (requiredUnsetOptions.isEmpty()) return@let
|
||||||
|
|
||||||
val error = """
|
val error = """
|
||||||
In order to use this patch, you need to provide a client ID.
|
In order to use this patch, you need to provide the following options:
|
||||||
You can do that by creating a file at ${it.absolutePath} with the client ID as its content.
|
${requiredUnsetOptions.joinToString("\n") { "${it.key}: ${it.description}" }}
|
||||||
Alternatively, you can provide the client ID using patch options.
|
|
||||||
|
|
||||||
You can get your client ID from https://www.reddit.com/prefs/apps.
|
A properties file has been created at ${propertiesFile.absolutePath}.
|
||||||
The application type has to be "Installed app" and the redirect URI has to be set to "$redirectUri".
|
Please fill in the required options before using this patch.
|
||||||
""".trimIndent()
|
""".trimIndent()
|
||||||
|
|
||||||
throw PatchException(error)
|
throw PatchException(error)
|
||||||
}.let { clientId = it.readText().trim() }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun List<MethodFingerprint>?.executePatch(
|
fun List<MethodFingerprint>?.executePatch(
|
||||||
|
@ -85,5 +120,6 @@ abstract class AbstractSpoofClientPatch(
|
||||||
*
|
*
|
||||||
* @param context The current [BytecodeContext].
|
* @param context The current [BytecodeContext].
|
||||||
*/
|
*/
|
||||||
|
// Not every client needs to patch miscellaneous things.
|
||||||
open fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) {}
|
open fun List<MethodFingerprintResult>.patchMiscellaneous(context: BytecodeContext) {}
|
||||||
}
|
}
|
|
@ -14,9 +14,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"http://baconreader.com/auth\".",
|
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage("com.onelouder.baconreader"),
|
CompatiblePackage("com.onelouder.baconreader"),
|
||||||
CompatiblePackage("com.onelouder.baconreader.premium")
|
CompatiblePackage("com.onelouder.baconreader.premium")
|
||||||
|
|
|
@ -10,9 +10,7 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"http://rubenmayayo.com\".",
|
|
||||||
compatiblePackages = [CompatiblePackage("com.rubenmayayo.reddit")]
|
compatiblePackages = [CompatiblePackage("com.rubenmayayo.reddit")]
|
||||||
)
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
|
|
@ -13,9 +13,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"infinity://localhost\".",
|
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage(
|
CompatiblePackage(
|
||||||
"ml.docilealligator.infinityforreddit", [
|
"ml.docilealligator.infinityforreddit", [
|
||||||
|
|
|
@ -12,9 +12,7 @@ import app.revanced.patches.reddit.customclients.joeyforreddit.detection.piracy.
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"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\".",
|
|
||||||
dependencies = [DisablePiracyDetectionPatch::class],
|
dependencies = [DisablePiracyDetectionPatch::class],
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage("o.o.joey"),
|
CompatiblePackage("o.o.joey"),
|
||||||
|
|
|
@ -16,9 +16,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"redditisfun://auth\".",
|
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage("com.andrewshu.android.reddit"),
|
CompatiblePackage("com.andrewshu.android.reddit"),
|
||||||
CompatiblePackage("com.andrewshu.android.redditdonation")
|
CompatiblePackage("com.andrewshu.android.redditdonation")
|
||||||
|
|
|
@ -13,9 +13,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"dbrady://relay\".",
|
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage("free.reddit.news"),
|
CompatiblePackage("free.reddit.news"),
|
||||||
CompatiblePackage("reddit.news")
|
CompatiblePackage("reddit.news")
|
||||||
|
|
|
@ -10,9 +10,7 @@ import app.revanced.patches.reddit.customclients.boostforreddit.api.fingerprints
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"http://www.ccrama.me\".",
|
|
||||||
compatiblePackages = [CompatiblePackage("me.ccrama.redditslide")]
|
compatiblePackages = [CompatiblePackage("me.ccrama.redditslide")]
|
||||||
)
|
)
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
|
|
@ -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.fingerprint.method.impl.MethodFingerprintResult
|
||||||
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
import app.revanced.patcher.patch.annotation.CompatiblePackage
|
||||||
import app.revanced.patcher.patch.annotation.Patch
|
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.AbstractSpoofClientPatch
|
||||||
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetAuthorizationStringFingerprint
|
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetAuthorizationStringFingerprint
|
||||||
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetBearerTokenFingerprint
|
import app.revanced.patches.reddit.customclients.syncforreddit.api.fingerprints.GetBearerTokenFingerprint
|
||||||
|
@ -20,9 +21,7 @@ import java.util.*
|
||||||
|
|
||||||
@Patch(
|
@Patch(
|
||||||
name = "Spoof client",
|
name = "Spoof client",
|
||||||
description = "Spoofs the client in order to allow logging in. " +
|
description = "Restores functionality of the app by using custom client ID's.",
|
||||||
"The OAuth application type has to be \"Installed app\" " +
|
|
||||||
"and the redirect URI has to be set to \"http://redditsync/auth\".",
|
|
||||||
dependencies = [DisablePiracyDetectionPatch::class],
|
dependencies = [DisablePiracyDetectionPatch::class],
|
||||||
compatiblePackages = [
|
compatiblePackages = [
|
||||||
CompatiblePackage("com.laurencedawson.reddit_sync"),
|
CompatiblePackage("com.laurencedawson.reddit_sync"),
|
||||||
|
|
Loading…
Reference in a new issue