Skip to content

Commit 1ac6127

Browse files
leumasmeoSumAtrIX
andauthored
fix(Tumblr - Fix old versions): Improve reliability by removing remnances of Tumblr Live (#2988)
Co-authored-by: oSumAtrIX <[email protected]>
1 parent e1ed1ae commit 1ac6127

File tree

4 files changed

+60
-24
lines changed

4 files changed

+60
-24
lines changed

api/revanced-patches.api

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,10 +1062,6 @@ public final class app/revanced/patches/tumblr/fixes/FixOldVersionsPatch : app/r
10621062
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
10631063
}
10641064

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-
10691065
public final class app/revanced/patches/tumblr/live/DisableTumblrLivePatch : app/revanced/patcher/patch/BytecodePatch {
10701066
public static final field INSTANCE Lapp/revanced/patches/tumblr/live/DisableTumblrLivePatch;
10711067
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V

src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,63 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
55
import app.revanced.patcher.patch.BytecodePatch
66
import app.revanced.patcher.patch.annotation.CompatiblePackage
77
import app.revanced.patcher.patch.annotation.Patch
8+
import app.revanced.patches.tumblr.fixes.fingerprints.AddQueryParamFingerprint
89
import app.revanced.patches.tumblr.fixes.fingerprints.HttpPathParserFingerprint
910
import app.revanced.util.exception
1011

1112
@Patch(
1213
name = "Fix old versions",
1314
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+
" Live from the API, which causes many requests to fail. This patch has no effect on newer versions of the app.",
1516
compatiblePackages = [CompatiblePackage("com.tumblr")],
1617
use = false,
1718
)
1819
@Suppress("unused")
1920
object FixOldVersionsPatch : BytecodePatch(
20-
setOf(HttpPathParserFingerprint),
21+
setOf(HttpPathParserFingerprint, AddQueryParamFingerprint),
2122
) {
22-
override fun execute(context: BytecodeContext) =
23+
override fun execute(context: BytecodeContext) {
24+
val liveQueryParameters = listOf(
25+
",?live_now",
26+
",?live_streaming_user_id",
27+
)
28+
2329
HttpPathParserFingerprint.result?.let {
2430
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-
)
31+
// Remove the live query parameters from the path when it's specified via a @METHOD annotation.
32+
for (liveQueryParameter in liveQueryParameters) {
33+
it.mutableMethod.addInstructions(
34+
endIndex + 1,
35+
"""
36+
# urlPath = urlPath.replace(liveQueryParameter, "")
37+
const-string p1, "$liveQueryParameter"
38+
const-string p3, ""
39+
invoke-virtual {p2, p1, p3}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
40+
move-result-object p2
41+
""",
42+
)
43+
}
3744
} ?: throw HttpPathParserFingerprint.exception
45+
46+
AddQueryParamFingerprint.result?.let {
47+
// Remove the live query parameters when passed via a parameter which has the @Query annotation.
48+
// e.g. an API call could be defined like this:
49+
// @GET("api/me/info")
50+
// ApiResponse getCurrentUserInfo(@Query("fields[blog]") String value)
51+
// which would result in the path "api/me/inf0?fields[blog]=${value}"
52+
// Here we make sure that this value doesn't contain the broken query parameters.
53+
for (liveQueryParameter in liveQueryParameters) {
54+
it.mutableMethod.addInstructions(
55+
0,
56+
"""
57+
# queryParameterValue = queryParameterValue.replace(liveQueryParameter, "")
58+
const-string v0, "$liveQueryParameter"
59+
const-string v1, ""
60+
invoke-virtual {p2, v0, v1}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;
61+
move-result-object p2
62+
""",
63+
)
64+
}
65+
} ?: throw AddQueryParamFingerprint.exception
66+
}
3867
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package app.revanced.patches.tumblr.fixes.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
5+
// Fingerprint for the addQueryParam method from retrofit2
6+
// https://github.com/square/retrofit/blob/trunk/retrofit/src/main/java/retrofit2/RequestBuilder.java#L186
7+
// Injecting here allows modifying dynamically set query parameters
8+
internal object AddQueryParamFingerprint : MethodFingerprint(
9+
strings = listOf("Malformed URL. Base: ", ", Relative: "),
10+
parameters = listOf("Ljava/lang/String;", "Ljava/lang/String;", "Z"),
11+
)

src/main/kotlin/app/revanced/patches/tumblr/fixes/fingerprints/HttpPathParserFingerprint.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ package app.revanced.patches.tumblr.fixes.fingerprints
33
import app.revanced.patcher.fingerprint.MethodFingerprint
44
import com.android.tools.smali.dexlib2.Opcode
55

6-
// Fingerprint for the parseHttpMethodAndPath from retrofit2
6+
// Fingerprint for the parseHttpMethodAndPath method from retrofit2
77
// https://github.com/square/retrofit/blob/ebf87b10997e2136af4d335276fa950221852c64/retrofit/src/main/java/retrofit2/RequestFactory.java#L270-L302
88
// Injecting here allows modifying the path/query params of API endpoints defined via annotations
9-
object HttpPathParserFingerprint : MethodFingerprint(
9+
internal object HttpPathParserFingerprint : MethodFingerprint(
1010
strings = listOf("Only one HTTP method is allowed. Found: %s and %s."),
1111
opcodes = listOf(
1212
Opcode.IPUT_OBJECT,
13-
Opcode.IPUT_BOOLEAN
14-
)
15-
)
13+
Opcode.IPUT_BOOLEAN,
14+
),
15+
)

0 commit comments

Comments
 (0)