|
| 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 | +} |
0 commit comments