From 2fde60eceb0a96fa857c32cd55c1fd7fe776a679 Mon Sep 17 00:00:00 2001 From: Temm Date: Sun, 31 Mar 2024 01:46:50 +0100 Subject: [PATCH] feat(Tumblr): Add `Fix old versions` patch (#2954) Co-authored-by: oSumAtrIX --- api/revanced-patches.api | 10 +++++ .../tumblr/fixes/FixOldVersionsPatch.kt | 38 +++++++++++++++++++ .../fingerprints/HttpPathParserFingerprint.kt | 15 ++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 274be198..4bba02a5 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -1056,6 +1056,16 @@ public final class app/revanced/patches/tumblr/featureflags/OverrideFeatureFlags public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/tumblr/fixes/FixOldVersionsPatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/tumblr/fixes/FixOldVersionsPatch; + public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V + public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V +} + +public final class app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint { + public static final field INSTANCE Lapp/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint; +} + public final class app/revanced/patches/tumblr/live/DisableTumblrLivePatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/tumblr/live/DisableTumblrLivePatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt b/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt new file mode 100644 index 00000000..9fe883d9 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt @@ -0,0 +1,38 @@ +package app.revanced.patches.tumblr.fixes + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.patch.BytecodePatch +import app.revanced.patcher.patch.annotation.CompatiblePackage +import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patches.tumblr.fixes.fingerprints.HttpPathParserFingerprint +import app.revanced.util.exception + +@Patch( + name = "Fix old versions", + description = "Fixes old versions of the app (v33.2 and earlier) breaking due to Tumblr removing remnants of Tumblr" + + " Live from the API, which causes many requests to fail. This patch has no effect on newer versions of the app.", + compatiblePackages = [CompatiblePackage("com.tumblr")], + use = false, +) +@Suppress("unused") +object FixOldVersionsPatch : BytecodePatch( + setOf(HttpPathParserFingerprint), +) { + override fun execute(context: BytecodeContext) = + HttpPathParserFingerprint.result?.let { + val endIndex = it.scanResult.patternScanResult!!.endIndex + + it.mutableMethod.addInstructions( + endIndex + 1, + """ + # Remove "?live_now" from the request path p2. + # p2 = p2.replace(p1, p3) + const-string p1, ",?live_now" + const-string p3, "" + invoke-virtual {p2, p1, p3}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String; + move-result-object p2 + """, + ) + } ?: throw HttpPathParserFingerprint.exception +} diff --git a/src/main/kotlin/app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint.kt b/src/main/kotlin/app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint.kt new file mode 100644 index 00000000..0ef376ed --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint.kt @@ -0,0 +1,15 @@ +package app.revanced.patches.tumblr.fixes.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.Opcode + +// Fingerprint for the parseHttpMethodAndPath from retrofit2 +// https://github.com/square/retrofit/blob/ebf87b10997e2136af4d335276fa950221852c64/retrofit/src/main/java/retrofit2/RequestFactory.java#L270-L302 +// Injecting here allows modifying the path/query params of API endpoints defined via annotations +object HttpPathParserFingerprint : MethodFingerprint( + strings = listOf("Only one HTTP method is allowed. Found: %s and %s."), + opcodes = listOf( + Opcode.IPUT_OBJECT, + Opcode.IPUT_BOOLEAN + ) +) \ No newline at end of file