feat(reddit/sanitize-sharing-links): simplified patch method

This commit is contained in:
inotia00 2023-07-05 15:18:55 +09:00
parent 1b76970209
commit a1800b8632
3 changed files with 23 additions and 35 deletions

View File

@ -1,21 +0,0 @@
package app.revanced.patches.reddit.misc.tracking.url.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
import org.jf.dexlib2.AccessFlags
import org.jf.dexlib2.Opcode
object ShareLinkFactoryFingerprint : MethodFingerprint(
returnType = "L",
accessFlags = AccessFlags.PUBLIC or AccessFlags.FINAL,
opcodes = listOf(
Opcode.CONST_STRING,
Opcode.INVOKE_DIRECT,
Opcode.APUT_OBJECT,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.INVOKE_STATIC, // Returns the URL.
Opcode.MOVE_RESULT_OBJECT
),
customFingerprint = { methodDef, _ -> methodDef.definingClass.endsWith("ShareLinkFactory;") }
)

View File

@ -0,0 +1,9 @@
package app.revanced.patches.reddit.misc.tracking.url.fingerprints
import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint
object ShareLinkFormatterFingerprint : MethodFingerprint(
returnType = "Ljava/lang/String;",
parameters = listOf("Ljava/lang/String;", "Ljava/util/Map;"),
strings = listOf("uri.getQueryParameters(name)", "uri.queryParameterNames", "newUriBuilder.build().toString()"),
)

View File

@ -5,18 +5,18 @@ 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.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
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.patches.reddit.misc.tracking.url.fingerprints.ShareLinkFactoryFingerprint
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.reddit.misc.tracking.url.fingerprints.ShareLinkFormatterFingerprint
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
@Patch
@Name("sanitize-sharing-links")
@ -25,23 +25,23 @@ import org.jf.dexlib2.iface.instruction.OneRegisterInstruction
@RedditCompatibility
@Version("0.0.1")
class SanitizeUrlQueryPatch : BytecodePatch(
listOf(ShareLinkFactoryFingerprint)
listOf(ShareLinkFormatterFingerprint)
) {
override fun execute(context: BytecodeContext): PatchResult {
ShareLinkFactoryFingerprint.result?.let { result ->
ShareLinkFormatterFingerprint.result?.let { result ->
result.mutableMethod.apply {
val insertIndex = result.scanResult.patternScanResult!!.endIndex + 1
val urlRegister = getInstruction<OneRegisterInstruction>(insertIndex - 1).registerA
addInstructions(
insertIndex,
addInstructionsWithLabels(
0,
"""
invoke-static {v$urlRegister}, $SANITIZE_METHOD_DESCRIPTOR
move-result-object v$urlRegister
"""
invoke-static {}, $SANITIZE_METHOD_DESCRIPTOR
move-result v0
if-eqz v0, :off
return-object p0
""", ExternalLabel("off", getInstruction(0))
)
}
} ?: return ShareLinkFactoryFingerprint.toErrorResult()
} ?: return ShareLinkFormatterFingerprint.toErrorResult()
updateSettingsStatus("SanitizeUrlQuery")
@ -51,6 +51,6 @@ class SanitizeUrlQueryPatch : BytecodePatch(
private companion object {
private const val SANITIZE_METHOD_DESCRIPTOR =
"Lapp/revanced/reddit/patches/SanitizeUrlQueryPatch;" +
"->stripQueryParameters(Ljava/lang/String;)Ljava/lang/String;"
"->stripQueryParameters()Z"
}
}