Skip to content

Commit

Permalink
Merge pull request #17 from crimera/dev
Browse files Browse the repository at this point in the history
chore: Merge branch `dev` to `main`
  • Loading branch information
crimera authored Mar 8, 2024
2 parents 247450a + 250e879 commit 251da7a
Show file tree
Hide file tree
Showing 13 changed files with 308 additions and 21 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,32 @@
# [1.11.0-dev.3](https://github.com/crimera/piko/compare/v1.11.0-dev.2...v1.11.0-dev.3) (2024-03-08)


### Bug Fixes

* **Twitter:** Download patch ([f87dee7](https://github.com/crimera/piko/commit/f87dee798632528595ac3efab1349d7a3fecafa0))

# [1.11.0-dev.2](https://github.com/crimera/piko/compare/v1.11.0-dev.1...v1.11.0-dev.2) (2024-03-04)


### Features

* **Twitter:** Hide FAB ([4cdf50f](https://github.com/crimera/piko/commit/4cdf50fb036ed8596c9e4a3e3f1702ae78525d28))
* **Twitter:** Hide FAB Menu Buttons ([4f25bd6](https://github.com/crimera/piko/commit/4f25bd60888b70ccd4518a42459583b6ef8fcc54))
* **Twitter:** Hide Promoted Trends ([1be736e](https://github.com/crimera/piko/commit/1be736e31ae11d21a62f7a3f4aad2689647ada92))

# [1.11.0-dev.1](https://github.com/crimera/piko/compare/v1.10.0...v1.11.0-dev.1) (2024-03-03)


### Bug Fixes

* unshort url for 10.30 ([ef3e00f](https://github.com/crimera/piko/commit/ef3e00f80fc469e5f09f8d7e43136791dbd94872))


### Features

* no t.co links ([776e700](https://github.com/crimera/piko/commit/776e7007b571cc2803d566891c72a42057297bb6))
* **Twitter:** Disable in favor of official patch bundle ([9a81fab](https://github.com/crimera/piko/commit/9a81fabed7457d1be967250faa548a67accc27bc))

# [1.10.0](https://github.com/crimera/piko/compare/v1.9.1...v1.10.0) (2024-03-03)


Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
org.gradle.parallel = true
org.gradle.caching = true
kotlin.code.style = official
version = 1.10.0
version = 1.11.0-dev.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package crimera.patches.twitter.ads.trends

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
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 com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import crimera.patches.twitter.ads.trends.fingerprints.HidePromotedTrendFingerprint

@Patch(
name = "Hide Promoted Trends",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false
)
@Suppress("unused")
class HidePromotedTrendPatch : BytecodePatch(
setOf(HidePromotedTrendFingerprint)
) {
override fun execute(context: BytecodeContext) {
val result = HidePromotedTrendFingerprint.result
?: throw PatchException("Fingerprint not found")

val method = result.mutableMethod
val instructions = method.getInstructions()

val return_obj = instructions.last { it.opcode == Opcode.RETURN_OBJECT }
val return_loc = return_obj.location.index
val return_reg = method.getInstruction<OneRegisterInstruction>(return_loc).registerA
val loc = return_loc-7
val reg = method.getInstruction<TwoRegisterInstruction>(loc).registerA

method.addInstructionsWithLabels(return_loc,"""
if-eqz v$reg, :cond_1212
const v$return_reg, 0x0
""".trimIndent(),
ExternalLabel("cond_1212", return_obj)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package crimera.patches.twitter.ads.trends.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object HidePromotedTrendFingerprint : MethodFingerprint(
returnType = "Ljava/lang/Object;",
customFingerprint = {it,_->
it.definingClass == "Lcom/twitter/model/json/timeline/urt/JsonTimelineTrend;"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package crimera.patches.twitter.interaction.downloads.unlockdownloads
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.getInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.extensions.InstructionExtensions.removeInstruction
import app.revanced.patcher.patch.BytecodePatch
Expand All @@ -11,18 +12,22 @@ 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 com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction
import crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints.DownloadPatchFingerprint
import crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints.FIleDownloaderFingerprint
import crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints.MediaEntityFingerprint

// Credits to @iKirby
@Patch(
name = "Download patch",
description = "Unlocks the ability to download videos from Twitter",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
description = "Unlocks the ability to download videos and gifs from Twitter/X",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false
)
@Suppress("unused")
object DownloadPatch : BytecodePatch(
setOf(DownloadPatchFingerprint, FIleDownloaderFingerprint)
setOf(DownloadPatchFingerprint,FIleDownloaderFingerprint,MediaEntityFingerprint)
) {
override fun execute(context: BytecodeContext) {
val result = DownloadPatchFingerprint.result
Expand All @@ -31,32 +36,61 @@ object DownloadPatch : BytecodePatch(
val method = result.mutableMethod
val instructions = method.getInstructions()

val index = instructions.filter { it.opcode == Opcode.IF_EQ }[1].location.index
val first_if_loc = instructions.first { it.opcode == Opcode.IF_EQ }.location.index
val reg = method.getInstruction<TwoRegisterInstruction>(first_if_loc)
val r1 = reg.registerA
val r2 = reg.registerB

////add support for gif
method.addInstructionsWithLabels(
index + 1,
first_if_loc + 1,
"""
const/4 v5, 0x2
const/4 v$r2, 0x2
if-eq v4, v5, :cond_0
if-eq v$r1, v$r2, :cond_1212
""",
ExternalLabel("cond_0", method.getInstructions().first { it.opcode == Opcode.NEW_INSTANCE })
ExternalLabel("cond_1212", method.getInstructions().first { it.opcode == Opcode.NEW_INSTANCE })
)

//enable download for all media
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")

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")
}
}

val method2 = f2Result.mutableMethod
val instructions2 = method2.getInstructions()
val first_if2_loc = instructions2.first { it.opcode == Opcode.IF_EQZ }.location.index
val r3 = method2.getInstruction<OneRegisterInstruction>(first_if2_loc).registerA

//remove premium restriction
method2.addInstructions(first_if2_loc,"""
const v$r3, true
""".trimIndent())


//force video downloadable
val f3Result = MediaEntityFingerprint.result
?: throw PatchException("MediaEntityFingerprint not found")

val method3 = f3Result.mutableMethod
val instructions3 = method3.getInstructions()
val loc = instructions3.last { it.opcode == Opcode.IGET_BOOLEAN }.location.index
val r4 = method3.getInstruction<TwoRegisterInstruction>(loc).registerA

method3.addInstructions(loc+1,"""
const v$r4, true
""".trimIndent())




//end
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprin
import app.revanced.patcher.fingerprint.MethodFingerprint

object FIleDownloaderFingerprint: MethodFingerprint(
returnType = "V",
returnType = "Z",
strings = listOf(
"fileDownloader",
"dialogOpener"
"mediaEntity",
"variantToDownload.url"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints

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


object MediaEntityFingerprint:MethodFingerprint(
opcodes = listOf(
Opcode.IGET_BOOLEAN,
),

customFingerprint = { it, _ ->
it.definingClass == "Lcom/twitter/model/json/core/JsonMediaEntity;"
}

)
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package crimera.patches.twitter.link.unshorten

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
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.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 com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.link.unshorten.fingerprints.JsonObjectMapperFingerprint

@Patch(
name = "No shortened URL",
description = "Get rid of t.co short urls.",
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object NoShortenedUrlPatch : BytecodePatch(
setOf(JsonObjectMapperFingerprint)
) {
private const val METHOD_REFERENCE =
"Lapp/revanced/integrations/twitter/patches/links/UnshortenUrlsPatch;->" +
"unshort(Ljava/lang/Object;)V"

override fun execute(context: BytecodeContext) {

val result = JsonObjectMapperFingerprint.result
?: throw Exception("Fingerprint not found")

val method = result.mutableMethod
val instructions = method.getInstructions()

// somehow targetIndex2 is above :cond_2, inject again before branching
var targetIndex = -1
val targetIndex2 = instructions.size - 1
for (i in 0..targetIndex2) {
if (instructions[i].opcode == Opcode.IF_EQ) {
targetIndex = i;
}
}

val inject = """
invoke-static { v0 }, $METHOD_REFERENCE
""".trimIndent()

result.mutableMethod.addInstructions(targetIndex, inject)
result.mutableMethod.addInstructions(targetIndex2, inject)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package crimera.patches.twitter.link.unshorten.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags


internal object JsonObjectMapperFingerprint : MethodFingerprint(
// Lcom/twitter/model/json/core/JsonUrlEntity$$JsonObjectMapper;
customFingerprint = { methodDef, _ -> methodDef.name.contains("parse") && methodDef.definingClass == "Lcom/twitter/model/json/core/JsonUrlEntity\$\$JsonObjectMapper;" }
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package crimera.patches.twitter.misc.FAB

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.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.misc.FAB.fingerprints.HideFABFingerprint

@Patch(
name = "Hide FAB Menu Buttons",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false
)
@Suppress("unused")
class HideFABMenuButtonsPatch : BytecodePatch(
setOf(HideFABFingerprint)
){
override fun execute(context: BytecodeContext) {
val result = HideFABFingerprint.result
?: throw PatchException("Fingerprint not found")

val method = result.mutableMethod
val instructions = method.getInstructions()
val loc = instructions.last { it.opcode == Opcode.CONST_STRING }.location.index+2
val reg = method.getInstruction<OneRegisterInstruction>(loc).registerA

method.addInstructions(loc+1,"""
const v$reg, false
""".trimIndent(),
)

}
}
38 changes: 38 additions & 0 deletions src/main/kotlin/crimera/patches/twitter/misc/FAB/HideFABPatch.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package crimera.patches.twitter.misc.FAB

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
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 crimera.patches.twitter.misc.FAB.fingerprints.HideFABFingerprint

@Patch(
name = "Hide FAB",
compatiblePackages = [CompatiblePackage("com.twitter.android")] ,
use = false
)
@Suppress("unused")
class HideFABPatch :BytecodePatch(
setOf(HideFABFingerprint)
){
override fun execute(context: BytecodeContext) {
val result = HideFABFingerprint.result
?: throw PatchException("Fingerprint not found")

val method = result.mutableMethod
val instructions = method.getInstructions()
val const_obj = instructions.last { it.opcode == Opcode.CONST_4 }

method.addInstructionsWithLabels(0,"""
goto :cond_1212
""".trimIndent(),
ExternalLabel("cond_1212",const_obj)
)

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package crimera.patches.twitter.misc.FAB.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object HideFABFingerprint: MethodFingerprint(
strings = listOf(
"android_compose_fab_menu_enabled"
)
)
Loading

0 comments on commit 251da7a

Please sign in to comment.