Skip to content

Commit 2f28e95

Browse files
leumasmeoSumAtrIX
andauthored
feat(Tumblr): Add Fix old versions patch (#2954)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent d819e7b commit 2f28e95

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

api/revanced-patches.api

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,16 @@ public final class app/revanced/patches/tumblr/featureflags/OverrideFeatureFlags
10561056
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
10571057
}
10581058

1059+
public final class app/revanced/patches/tumblr/fixes/FixOldVersionsPatch : app/revanced/patcher/patch/BytecodePatch {
1060+
public static final field INSTANCE Lapp/revanced/patches/tumblr/fixes/FixOldVersionsPatch;
1061+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
1062+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
1063+
}
1064+
1065+
public final class app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint : app/revanced/patcher/fingerprint/MethodFingerprint {
1066+
public static final field INSTANCE Lapp/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint;
1067+
}
1068+
10591069
public final class app/revanced/patches/tumblr/live/DisableTumblrLivePatch : app/revanced/patcher/patch/BytecodePatch {
10601070
public static final field INSTANCE Lapp/revanced/patches/tumblr/live/DisableTumblrLivePatch;
10611071
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package app.revanced.patches.tumblr.fixes
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
5+
import app.revanced.patcher.patch.BytecodePatch
6+
import app.revanced.patcher.patch.annotation.CompatiblePackage
7+
import app.revanced.patcher.patch.annotation.Patch
8+
import app.revanced.patches.tumblr.fixes.fingerprints.HttpPathParserFingerprint
9+
import app.revanced.util.exception
10+
11+
@Patch(
12+
name = "Fix old versions",
13+
description = "Fixes old versions of the app (v33.2 and earlier) breaking due to Tumblr removing remnants of Tumblr" +
14+
" Live from the API, which causes many requests to fail. This patch has no effect on newer versions of the app.",
15+
compatiblePackages = [CompatiblePackage("com.tumblr")],
16+
use = false,
17+
)
18+
@Suppress("unused")
19+
object FixOldVersionsPatch : BytecodePatch(
20+
setOf(HttpPathParserFingerprint),
21+
) {
22+
override fun execute(context: BytecodeContext) =
23+
HttpPathParserFingerprint.result?.let {
24+
val endIndex = it.scanResult.patternScanResult!!.endIndex
25+
26+
it.mutableMethod.addInstructions(
27+
endIndex + 1,
28+
"""
29+
# Remove "?live_now" from the request path p2.
30+
# p2 = p2.replace(p1, p3)
31+
const-string p1, ",?live_now"
32+
const-string p3, ""
33+
invoke-virtual {p2, p1, p3}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
34+
move-result-object p2
35+
""",
36+
)
37+
} ?: throw HttpPathParserFingerprint.exception
38+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package app.revanced.patches.tumblr.fixes.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.Opcode
5+
6+
// Fingerprint for the parseHttpMethodAndPath from retrofit2
7+
// https://github.com/square/retrofit/blob/ebf87b10997e2136af4d335276fa950221852c64/retrofit/src/main/java/retrofit2/RequestFactory.java#L270-L302
8+
// Injecting here allows modifying the path/query params of API endpoints defined via annotations
9+
object HttpPathParserFingerprint : MethodFingerprint(
10+
strings = listOf("Only one HTTP method is allowed. Found: %s and %s."),
11+
opcodes = listOf(
12+
Opcode.IPUT_OBJECT,
13+
Opcode.IPUT_BOOLEAN
14+
)
15+
)

0 commit comments

Comments
 (0)