generated from ReVanced/revanced-patches-template
-
-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/kotlin/app/revanced/patches/twitter/interaction/downloads/UnlockDownloadsPatch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package app.revanced.patches.twitter.interaction.downloads | ||
|
||
import app.revanced.patcher.data.BytecodeContext | ||
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction | ||
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import app.revanced.patcher.fingerprint.MethodFingerprintResult | ||
import app.revanced.patcher.patch.BytecodePatch | ||
import app.revanced.patcher.patch.annotation.CompatiblePackage | ||
import app.revanced.patcher.patch.annotation.Patch | ||
import app.revanced.patches.twitter.interaction.downloads.fingerprints.ConstructMediaOptionsSheetFingerprint | ||
import app.revanced.patches.twitter.interaction.downloads.fingerprints.ShowDownloadVideoUpsellBottomSheetFingerprint | ||
import app.revanced.util.exception | ||
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction | ||
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction | ||
|
||
@Patch( | ||
name = "Unlock downloads", | ||
description = "Unlocks the ability to download any video.", | ||
compatiblePackages = [CompatiblePackage("com.twitter.android")] | ||
) | ||
@Suppress("unused") | ||
object UnlockDownloadsPatch : BytecodePatch( | ||
setOf(ConstructMediaOptionsSheetFingerprint, ShowDownloadVideoUpsellBottomSheetFingerprint) | ||
) { | ||
override fun execute(context: BytecodeContext) { | ||
fun MethodFingerprint.patch(getRegisterAndIndex: MethodFingerprintResult.() -> Pair<Int, Int>) = result?.let { | ||
getRegisterAndIndex(it).let { (index, register) -> | ||
it.mutableMethod.addInstruction(index, "const/4 v$register, 0x1") | ||
} | ||
} ?: throw exception | ||
|
||
// Allow downloads for non-premium users. | ||
ShowDownloadVideoUpsellBottomSheetFingerprint.patch { | ||
val checkIndex = scanResult.patternScanResult!!.startIndex | ||
val register = mutableMethod.getInstruction<OneRegisterInstruction>(checkIndex).registerA | ||
|
||
checkIndex to register | ||
} | ||
|
||
// Force show the download menu item. | ||
ConstructMediaOptionsSheetFingerprint.patch { | ||
val showDownloadButtonIndex = mutableMethod.getInstructions().lastIndex - 1 | ||
val register = mutableMethod.getInstruction<TwoRegisterInstruction>(showDownloadButtonIndex).registerA | ||
|
||
showDownloadButtonIndex to register | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...tches/twitter/interaction/downloads/fingerprints/ConstructMediaOptionsSheetFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package app.revanced.patches.twitter.interaction.downloads.fingerprints | ||
|
||
import app.revanced.patcher.extensions.or | ||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.AccessFlags | ||
|
||
|
||
internal object ConstructMediaOptionsSheetFingerprint : MethodFingerprint( | ||
returnType = "V", | ||
accessFlags = AccessFlags.PUBLIC or AccessFlags.CONSTRUCTOR, | ||
strings = listOf("captionsState") | ||
) |
10 changes: 10 additions & 0 deletions
10
...itter/interaction/downloads/fingerprints/ShowDownloadVideoUpsellBottomSheetFingerprint.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.revanced.patches.twitter.interaction.downloads.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
import com.android.tools.smali.dexlib2.Opcode | ||
|
||
internal object ShowDownloadVideoUpsellBottomSheetFingerprint : MethodFingerprint( | ||
returnType = "Z", | ||
strings = listOf("variantToDownload.url"), | ||
opcodes = listOf(Opcode.IF_EQZ) | ||
) |