|
| 1 | +package app.revanced.patches.twitter.interaction.downloads |
| 2 | + |
| 3 | +import app.revanced.patcher.data.BytecodeContext |
| 4 | +import app.revanced.patcher.extensions.InstructionExtensions.addInstruction |
| 5 | +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction |
| 6 | +import app.revanced.patcher.extensions.InstructionExtensions.getInstructions |
| 7 | +import app.revanced.patcher.fingerprint.MethodFingerprint |
| 8 | +import app.revanced.patcher.fingerprint.MethodFingerprintResult |
| 9 | +import app.revanced.patcher.patch.BytecodePatch |
| 10 | +import app.revanced.patcher.patch.annotation.CompatiblePackage |
| 11 | +import app.revanced.patcher.patch.annotation.Patch |
| 12 | +import app.revanced.patches.twitter.interaction.downloads.fingerprints.ConstructMediaOptionsSheetFingerprint |
| 13 | +import app.revanced.patches.twitter.interaction.downloads.fingerprints.ShowDownloadVideoUpsellBottomSheetFingerprint |
| 14 | +import app.revanced.util.exception |
| 15 | +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction |
| 16 | +import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction |
| 17 | + |
| 18 | +@Patch( |
| 19 | + name = "Unlock downloads", |
| 20 | + description = "Unlocks the ability to download any video.", |
| 21 | + compatiblePackages = [CompatiblePackage("com.twitter.android")] |
| 22 | +) |
| 23 | +@Suppress("unused") |
| 24 | +object UnlockDownloadsPatch : BytecodePatch( |
| 25 | + setOf(ConstructMediaOptionsSheetFingerprint, ShowDownloadVideoUpsellBottomSheetFingerprint) |
| 26 | +) { |
| 27 | + override fun execute(context: BytecodeContext) { |
| 28 | + fun MethodFingerprint.patch(getRegisterAndIndex: MethodFingerprintResult.() -> Pair<Int, Int>) = result?.let { |
| 29 | + getRegisterAndIndex(it).let { (index, register) -> |
| 30 | + it.mutableMethod.addInstruction(index, "const/4 v$register, 0x1") |
| 31 | + } |
| 32 | + } ?: throw exception |
| 33 | + |
| 34 | + // Allow downloads for non-premium users. |
| 35 | + ShowDownloadVideoUpsellBottomSheetFingerprint.patch { |
| 36 | + val checkIndex = scanResult.patternScanResult!!.startIndex |
| 37 | + val register = mutableMethod.getInstruction<OneRegisterInstruction>(checkIndex).registerA |
| 38 | + |
| 39 | + checkIndex to register |
| 40 | + } |
| 41 | + |
| 42 | + // Force show the download menu item. |
| 43 | + ConstructMediaOptionsSheetFingerprint.patch { |
| 44 | + val showDownloadButtonIndex = mutableMethod.getInstructions().lastIndex - 1 |
| 45 | + val register = mutableMethod.getInstruction<TwoRegisterInstruction>(showDownloadButtonIndex).registerA |
| 46 | + |
| 47 | + showDownloadButtonIndex to register |
| 48 | + } |
| 49 | + } |
| 50 | +} |
0 commit comments