Skip to content

Commit

Permalink
feat(twitter): Add download patch
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera committed Jan 30, 2024
1 parent 93567d9 commit b9612bf
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/main/kotlin/your/org/patches/twitter/download/DownloadPatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package your.org.patches.twitter

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import com.android.tools.smali.dexlib2.Opcode
import your.org.patches.twitter.download.fingerprints.DownloadPatchFingerprint
import your.org.patches.twitter.download.fingerprints.FIleDownloaderFingerprint

@Patch(
name = "Download patch",
description = "Unlocks the ability to download videos from Twitter",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
object DownloadPatch : BytecodePatch(
setOf(DownloadPatchFingerprint, FIleDownloaderFingerprint)
) {
override fun execute(context: BytecodeContext) {
val result = DownloadPatchFingerprint.result
?: throw PatchException("DownloadPatchFingerprint not found")

val method = result.mutableMethod
val instructions = method.getInstructions()
instructions.forEach {
println(it.opcode)
}

val index = instructions.filter { it.opcode == Opcode.IF_EQ }[1].location.index

method.addInstructionsWithLabels(
index + 1,
"""
const/4 v5, 0x2
if-eq v4, v5, :cond_0
""",
ExternalLabel("cond_0", method.getInstructions().first { it.opcode == Opcode.NEW_INSTANCE })
)

instructions.first { it.opcode == Opcode.IGET_BOOLEAN }.location.index.apply {
method.removeInstruction(this)
method.removeInstruction(this)
}

val f2Result = FIleDownloaderFingerprint.result
?: throw PatchException("FIleDownloaderFingerprint not found")

print(f2Result.classDef.superclass)

f2Result.mutableClass.methods.forEach {
if (it.name == "a") {
// get first if
val i = it.getInstructions().first { inst -> inst.opcode == Opcode.IF_EQZ }.location.index
it.addInstructions(i, "const/4 v0, 0x1")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package your.org.patches.twitter.download.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object DownloadPatchFingerprint : MethodFingerprint(
returnType = "V",
strings = listOf(
"media_options_sheet",
"resources.getString(R.string.post_video)",
"resources.getString(R.string.post_photo)"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package your.org.patches.twitter.download.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object FIleDownloaderFingerprint: MethodFingerprint(
returnType = "V",
strings = listOf(
"fileDownloader",
"dialogOpener"
)
)

0 comments on commit b9612bf

Please sign in to comment.