@@ -5,34 +5,63 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
55import app.revanced.patcher.patch.BytecodePatch
66import app.revanced.patcher.patch.annotation.CompatiblePackage
77import app.revanced.patcher.patch.annotation.Patch
8+ import app.revanced.patches.tumblr.fixes.fingerprints.AddQueryParamFingerprint
89import app.revanced.patches.tumblr.fixes.fingerprints.HttpPathParserFingerprint
910import 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" )
1920object 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}
0 commit comments