mirror of
https://github.com/inotia00/revanced-patches.git
synced 2025-05-09 11:04:36 +02:00
feat(reddit): add settings
patch
This commit is contained in:
parent
10733c7a19
commit
5a6c741bb4
@ -10,18 +10,20 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
|
|||||||
import app.revanced.patcher.patch.BytecodePatch
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
import app.revanced.patcher.patch.PatchResult
|
import app.revanced.patcher.patch.PatchResult
|
||||||
import app.revanced.patcher.patch.PatchResultSuccess
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
import app.revanced.patcher.patch.annotations.Patch
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
|
||||||
import app.revanced.patches.reddit.misc.tracking.url.fingerprints.ShareLinkFactoryFingerprint
|
import app.revanced.patches.reddit.misc.tracking.url.fingerprints.ShareLinkFactoryFingerprint
|
||||||
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
||||||
|
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch
|
||||||
|
import app.revanced.patches.reddit.utils.settings.bytecode.patch.SettingsPatch.Companion.updateSettingsStatus
|
||||||
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
|
||||||
|
|
||||||
@Patch
|
@Patch
|
||||||
@Name("sanitize-sharing-links")
|
@Name("sanitize-sharing-links")
|
||||||
@Description("Removes (tracking) query parameters from the URLs when sharing links.")
|
@Description("Removes (tracking) query parameters from the URLs when sharing links.")
|
||||||
|
@DependsOn([SettingsPatch::class])
|
||||||
@RedditCompatibility
|
@RedditCompatibility
|
||||||
@Version("0.0.1")
|
@Version("0.0.1")
|
||||||
@RequiresIntegrations
|
|
||||||
class SanitizeUrlQueryPatch : BytecodePatch(
|
class SanitizeUrlQueryPatch : BytecodePatch(
|
||||||
listOf(ShareLinkFactoryFingerprint)
|
listOf(ShareLinkFactoryFingerprint)
|
||||||
) {
|
) {
|
||||||
@ -41,6 +43,8 @@ class SanitizeUrlQueryPatch : BytecodePatch(
|
|||||||
}
|
}
|
||||||
} ?: return ShareLinkFactoryFingerprint.toErrorResult()
|
} ?: return ShareLinkFactoryFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
updateSettingsStatus("SanitizeUrlQuery")
|
||||||
|
|
||||||
return PatchResultSuccess()
|
return PatchResultSuccess()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.integrations.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patches.shared.patch.integrations.AbstractIntegrationsPatch.IntegrationsFingerprint
|
||||||
|
|
||||||
|
object InitFingerprint : IntegrationsFingerprint(
|
||||||
|
customFingerprint = { methodDef, _ ->
|
||||||
|
methodDef.definingClass.endsWith("/FrontpageApplication;") &&
|
||||||
|
methodDef.name == "onCreate"
|
||||||
|
}
|
||||||
|
)
|
@ -0,0 +1,15 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.integrations.patch
|
||||||
|
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.patch.annotations.RequiresIntegrations
|
||||||
|
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
||||||
|
import app.revanced.patches.reddit.utils.integrations.fingerprints.InitFingerprint
|
||||||
|
import app.revanced.patches.shared.patch.integrations.AbstractIntegrationsPatch
|
||||||
|
|
||||||
|
@Name("integrations")
|
||||||
|
@RedditCompatibility
|
||||||
|
@RequiresIntegrations
|
||||||
|
class IntegrationsPatch : AbstractIntegrationsPatch(
|
||||||
|
"Lapp/revanced/reddit/utils/ReVancedUtils;",
|
||||||
|
listOf(InitFingerprint),
|
||||||
|
)
|
@ -0,0 +1,17 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.settings.bytecode.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
import org.jf.dexlib2.Opcode
|
||||||
|
|
||||||
|
object OssLicensesMenuActivityOnCreateFingerprint : MethodFingerprint(
|
||||||
|
returnType = "V",
|
||||||
|
opcodes = listOf(
|
||||||
|
Opcode.IGET_BOOLEAN,
|
||||||
|
Opcode.IF_EQZ,
|
||||||
|
Opcode.INVOKE_STATIC
|
||||||
|
),
|
||||||
|
customFingerprint = { methodDef, _ ->
|
||||||
|
methodDef.definingClass.endsWith("/OssLicensesMenuActivity;") &&
|
||||||
|
methodDef.name == "onCreate"
|
||||||
|
}
|
||||||
|
)
|
@ -0,0 +1,10 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.settings.bytecode.fingerprints
|
||||||
|
|
||||||
|
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
|
||||||
|
|
||||||
|
object SettingsStatusLoadFingerprint : MethodFingerprint(
|
||||||
|
customFingerprint = { methodDef, _ ->
|
||||||
|
methodDef.definingClass.endsWith("Lapp/revanced/reddit/settingsmenu/SettingsStatus;") &&
|
||||||
|
methodDef.name == "load"
|
||||||
|
}
|
||||||
|
)
|
@ -0,0 +1,75 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.settings.bytecode.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.toErrorResult
|
||||||
|
import app.revanced.patcher.annotation.Description
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.data.BytecodeContext
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
|
||||||
|
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
|
||||||
|
import app.revanced.patcher.patch.BytecodePatch
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patcher.patch.annotations.DependsOn
|
||||||
|
import app.revanced.patcher.patch.annotations.Patch
|
||||||
|
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
|
||||||
|
import app.revanced.patches.reddit.utils.annotations.RedditCompatibility
|
||||||
|
import app.revanced.patches.reddit.utils.integrations.patch.IntegrationsPatch
|
||||||
|
import app.revanced.patches.reddit.utils.settings.bytecode.fingerprints.OssLicensesMenuActivityOnCreateFingerprint
|
||||||
|
import app.revanced.patches.reddit.utils.settings.bytecode.fingerprints.SettingsStatusLoadFingerprint
|
||||||
|
import app.revanced.patches.reddit.utils.settings.resource.patch.SettingsResourcePatch
|
||||||
|
|
||||||
|
@Patch
|
||||||
|
@Name("settings")
|
||||||
|
@Description("Adds ReVanced settings to Reddit.")
|
||||||
|
@DependsOn(
|
||||||
|
[
|
||||||
|
IntegrationsPatch::class,
|
||||||
|
SettingsResourcePatch::class
|
||||||
|
]
|
||||||
|
)
|
||||||
|
@RedditCompatibility
|
||||||
|
@Version("0.0.1")
|
||||||
|
class SettingsPatch : BytecodePatch(
|
||||||
|
listOf(
|
||||||
|
OssLicensesMenuActivityOnCreateFingerprint,
|
||||||
|
SettingsStatusLoadFingerprint
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
override fun execute(context: BytecodeContext): PatchResult {
|
||||||
|
|
||||||
|
OssLicensesMenuActivityOnCreateFingerprint.result?.let {
|
||||||
|
it.mutableMethod.apply {
|
||||||
|
val insertIndex = it.scanResult.patternScanResult!!.startIndex + 1
|
||||||
|
|
||||||
|
addInstructions(
|
||||||
|
insertIndex, """
|
||||||
|
invoke-static {p0}, $INTEGRATIONS_METHOD_DESCRIPTOR
|
||||||
|
return-void
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} ?: return OssLicensesMenuActivityOnCreateFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
targetMethod = SettingsStatusLoadFingerprint.result?.mutableMethod
|
||||||
|
?: return SettingsStatusLoadFingerprint.toErrorResult()
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
|
||||||
|
internal companion object {
|
||||||
|
private const val INTEGRATIONS_METHOD_DESCRIPTOR =
|
||||||
|
"Lapp/revanced/reddit/settingsmenu/ReVancedSettingActivity;->initializeSettings(Landroid/app/Activity;)V"
|
||||||
|
|
||||||
|
private lateinit var targetMethod: MutableMethod
|
||||||
|
|
||||||
|
fun updateSettingsStatus(description: String) {
|
||||||
|
targetMethod.apply {
|
||||||
|
addInstruction(
|
||||||
|
0,
|
||||||
|
"invoke-static {}, Lapp/revanced/reddit/settingsmenu/SettingsStatus;->$description()V"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package app.revanced.patches.reddit.utils.settings.resource.patch
|
||||||
|
|
||||||
|
import app.revanced.extensions.doRecursively
|
||||||
|
import app.revanced.extensions.startsWithAny
|
||||||
|
import app.revanced.patcher.annotation.Name
|
||||||
|
import app.revanced.patcher.annotation.Version
|
||||||
|
import app.revanced.patcher.data.ResourceContext
|
||||||
|
import app.revanced.patcher.patch.PatchResult
|
||||||
|
import app.revanced.patcher.patch.PatchResultSuccess
|
||||||
|
import app.revanced.patches.shared.patch.settings.AbstractSettingsResourcePatch
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
import kotlin.io.path.exists
|
||||||
|
|
||||||
|
@Name("settings-resource-patch")
|
||||||
|
@Version("0.0.1")
|
||||||
|
class SettingsResourcePatch : AbstractSettingsResourcePatch(
|
||||||
|
"reddit/settings",
|
||||||
|
"reddit/settings/host",
|
||||||
|
false
|
||||||
|
) {
|
||||||
|
override fun execute(context: ResourceContext): PatchResult {
|
||||||
|
super.execute(context)
|
||||||
|
|
||||||
|
fun setIcon(targetXML: String) {
|
||||||
|
context.xmlEditor["res/xml/$targetXML.xml"].use { editor ->
|
||||||
|
editor.file.doRecursively loop@{
|
||||||
|
if (it !is Element) return@loop
|
||||||
|
|
||||||
|
it.getAttributeNode("android:key")?.let { attribute ->
|
||||||
|
if (attribute.textContent.endsWith("key_pref_acknowledgements")) {
|
||||||
|
it.getAttributeNode("android:icon").textContent =
|
||||||
|
"@drawable/icon_beta_planet"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
arrayOf("preferences", "preferences_logged_in").forEach { targetXML ->
|
||||||
|
val resDirectory = context["res"]
|
||||||
|
val targetXml = resDirectory.resolve("xml").resolve("$targetXML.xml").toPath()
|
||||||
|
|
||||||
|
if (targetXml.exists())
|
||||||
|
setIcon(targetXML)
|
||||||
|
}
|
||||||
|
|
||||||
|
// App name
|
||||||
|
val resourceFileNames = arrayOf("strings.xml")
|
||||||
|
|
||||||
|
context.forEach {
|
||||||
|
if (!it.name.startsWithAny(*resourceFileNames)) return@forEach
|
||||||
|
|
||||||
|
// for each file in the "layouts" directory replace all necessary attributes content
|
||||||
|
context.xmlEditor[it.absolutePath].use { editor ->
|
||||||
|
val resourcesNode = editor.file.getElementsByTagName("resources").item(0) as Element
|
||||||
|
|
||||||
|
for (i in 0 until resourcesNode.childNodes.length) {
|
||||||
|
val node = resourcesNode.childNodes.item(i)
|
||||||
|
if (node !is Element) continue
|
||||||
|
|
||||||
|
val element = resourcesNode.childNodes.item(i) as Element
|
||||||
|
element.textContent = when (element.getAttribute("name")) {
|
||||||
|
"label_acknowledgements" -> "@string/revanced_extended_settings_title"
|
||||||
|
else -> continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return PatchResultSuccess()
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" standalone="no"?>
|
||||||
|
<resources>
|
||||||
|
<string name="revanced_enable_sanitize_url_query_summary">Removes (tracking) query parameters from the URLs when sharing links</string>
|
||||||
|
<string name="revanced_enable_sanitize_url_query_title">Sanitize sharing links</string>
|
||||||
|
<string name="revanced_extended_settings_title">ReVanced Extended</string>
|
||||||
|
</resources>
|
Loading…
x
Reference in New Issue
Block a user