generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 34
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
3 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/your/org/patches/twitter/download/DownloadPatch.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,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") | ||
} | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/kotlin/your/org/patches/twitter/download/fingerprints/DownloadPatchFingerprint.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 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)" | ||
) | ||
) |
11 changes: 11 additions & 0 deletions
11
src/main/kotlin/your/org/patches/twitter/download/fingerprints/FIleDownloaderFingerprint.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,11 @@ | ||
package your.org.patches.twitter.download.fingerprints | ||
|
||
import app.revanced.patcher.fingerprint.MethodFingerprint | ||
|
||
object FIleDownloaderFingerprint: MethodFingerprint( | ||
returnType = "V", | ||
strings = listOf( | ||
"fileDownloader", | ||
"dialogOpener" | ||
) | ||
) |