Skip to content

Commit

Permalink
feat(Twitter): added Undo Posts Patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Swakshan authored and crimera committed Mar 16, 2024
1 parent 1348099 commit ced73c6
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package crimera.patches.twitter.premium.undoposts

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions
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 com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import crimera.patches.twitter.premium.undoposts.fingerprints.UndoPost1Fingerprint
import crimera.patches.twitter.premium.undoposts.fingerprints.UndoPost2Fingerprint
import crimera.patches.twitter.premium.undoposts.fingerprints.UndoPost3Fingerprint

@Patch(
name = "Enable Undo Posts",
description = "Enable ability to undo posts before it gets posted",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false
)
object EnableUndoPostPatch :BytecodePatch(
setOf(UndoPost1Fingerprint,UndoPost2Fingerprint,UndoPost3Fingerprint)
){
override fun execute(context: BytecodeContext) {

val result1 = UndoPost1Fingerprint.result
?: throw PatchException("UndoPost1Fingerprint not found")

//removes flag check
val method1 = result1.mutableMethod
val loc1 = method1.getInstructions().first { it.opcode == Opcode.IF_EQZ }.location.index
method1.removeInstruction(loc1)



val result2 = UndoPost2Fingerprint.result
?: throw PatchException("UndoPost2Fingerprint not found")

//removes flag check
val method2 = result2.mutableMethod
val loc2 = method2.getInstructions().first { it.opcode == Opcode.IF_EQZ }.location.index
method2.removeInstruction(loc2)

val result3 = UndoPost3Fingerprint.result
?: throw PatchException("UndoPost2Fingerprint not found")



//removes flag check and always return true
val method3 = result3.mutableMethod

val instructions = method3.getInstructions()
method3.removeInstructions(0, instructions.count())

method3.addInstructions(0,"""
sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean;
return-object v0
""".trimIndent())



//end
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package crimera.patches.twitter.premium.undoposts.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.Opcode

object UndoPost1Fingerprint :MethodFingerprint(
returnType = "Z",
strings = listOf(
"subscriptions_feature_1003",
"allow_undo_replies",
"allow_undo_tweet"
),
opcodes = listOf(
Opcode.MOVE_RESULT_OBJECT
)


)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package crimera.patches.twitter.premium.undoposts.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object UndoPost2Fingerprint :MethodFingerprint(
returnType = "Z",
strings = listOf(
"userPreferences",
"draftTweet",
"subscriptions_feature_1003",
"allow_undo_replies",
"allow_undo_tweet"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package crimera.patches.twitter.premium.undoposts.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object UndoPost3Fingerprint :MethodFingerprint(
returnType = "Ljava/lang/Object;",
strings = listOf(
"subscriptions_feature_1003"
)
)

0 comments on commit ced73c6

Please sign in to comment.