Skip to content

Commit a47ee38

Browse files
1fexdoSumAtrIX
andauthored
feat(Sync for Reddit): Add Fix video downloads patch (#3739)
Co-authored-by: oSumAtrIX <johan.melkonyan1@web.de>
1 parent 085db40 commit a47ee38

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed

api/revanced-patches.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,12 @@ public final class app/revanced/patches/reddit/customclients/syncforreddit/fix/u
840840
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
841841
}
842842

843+
public final class app/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch : app/revanced/patcher/patch/BytecodePatch {
844+
public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch;
845+
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
846+
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
847+
}
848+
843849
public final class app/revanced/patches/reddit/customclients/syncforreddit/misc/integrations/IntegrationsPatch : app/revanced/patches/shared/misc/integrations/BaseIntegrationsPatch {
844850
public static final field INSTANCE Lapp/revanced/patches/reddit/customclients/syncforreddit/misc/integrations/IntegrationsPatch;
845851
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package app.revanced.patches.reddit.customclients.syncforreddit.fix.video
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
6+
import app.revanced.patcher.patch.BytecodePatch
7+
import app.revanced.patcher.patch.annotation.CompatiblePackage
8+
import app.revanced.patcher.patch.annotation.Patch
9+
import app.revanced.patches.reddit.customclients.syncforreddit.fix.video.fingerprints.ParseRedditVideoNetworkResponseFingerprint
10+
import app.revanced.util.resultOrThrow
11+
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
12+
13+
@Patch(
14+
name = "Fix video downloads",
15+
description = "Fixes a bug in Sync's MPD parser resulting in only the audio-track being saved.",
16+
compatiblePackages = [
17+
CompatiblePackage("com.laurencedawson.reddit_sync"),
18+
CompatiblePackage("com.laurencedawson.reddit_sync.pro"),
19+
CompatiblePackage("com.laurencedawson.reddit_sync.dev"),
20+
],
21+
requiresIntegrations = true,
22+
)
23+
@Suppress("unused")
24+
object FixVideoDownloadsPatch : BytecodePatch(
25+
fingerprints = setOf(ParseRedditVideoNetworkResponseFingerprint),
26+
) {
27+
private const val INTEGRATIONS_CLASS_DESCRIPTOR =
28+
"Lapp/revanced/integrations/syncforreddit/FixRedditVideoDownloadPatch;"
29+
private const val GET_LINKS_METHOD = "getLinks([B)[Ljava/lang/String;"
30+
31+
override fun execute(context: BytecodeContext) {
32+
ParseRedditVideoNetworkResponseFingerprint.resultOrThrow().let {
33+
val scanResult = it.scanResult.patternScanResult!!
34+
val newInstanceIndex = scanResult.startIndex
35+
val invokeDirectIndex = scanResult.endIndex - 1
36+
37+
val buildResponseInstruction = it.mutableMethod.getInstruction<Instruction35c>(invokeDirectIndex)
38+
39+
it.mutableMethod.addInstructions(
40+
newInstanceIndex + 1,
41+
"""
42+
# Get byte array from response.
43+
iget-object v2, p1, Lcom/android/volley/NetworkResponse;->data:[B
44+
45+
# Parse the videoUrl and audioUrl from the byte array.
46+
invoke-static { v2 }, $INTEGRATIONS_CLASS_DESCRIPTOR->$GET_LINKS_METHOD
47+
move-result-object v2
48+
49+
# Get videoUrl (Index 0).
50+
const/4 v5, 0x0
51+
aget-object v${buildResponseInstruction.registerE}, v2, v5
52+
53+
# Get audioUrl (Index 1).
54+
const/4 v6, 0x1
55+
aget-object v${buildResponseInstruction.registerF}, v2, v6
56+
57+
# Register E and F are used to build the response.
58+
""",
59+
)
60+
}
61+
}
62+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.revanced.patches.reddit.customclients.syncforreddit.fix.video.fingerprints
2+
3+
import app.revanced.patcher.fingerprint.MethodFingerprint
4+
import com.android.tools.smali.dexlib2.Opcode
5+
6+
internal object ParseRedditVideoNetworkResponseFingerprint : MethodFingerprint(
7+
opcodes = listOf(
8+
Opcode.NEW_INSTANCE,
9+
Opcode.IGET_OBJECT,
10+
Opcode.INVOKE_DIRECT,
11+
Opcode.CONST_WIDE_32
12+
),
13+
customFingerprint = { methodDef, classDef ->
14+
classDef.sourceFile == "RedditVideoRequest.java" && methodDef.name == "parseNetworkResponse"
15+
}
16+
)

0 commit comments

Comments
 (0)