Skip to content

Commit

Permalink
feat(Twitter): added Reader Mode patch
Browse files Browse the repository at this point in the history
  • Loading branch information
Swakshan committed Mar 12, 2024
1 parent 8cbe765 commit e4c9e1a
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package crimera.patches.twitter.premium.readermode

import app.revanced.patcher.data.BytecodeContext
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 com.android.tools.smali.dexlib2.Opcode
import crimera.patches.twitter.premium.readermode.fingerprints.EnableReaderMode1Fingerprint
import crimera.patches.twitter.premium.readermode.fingerprints.EnableReaderMode2Fingerprint

@Patch(
name = "Enable Reader Mode",
description = "Enables reader mode on long threads",
compatiblePackages = [CompatiblePackage("com.twitter.android")],
use = false
)
@Suppress("unused")
object EnableReaderModePatch:BytecodePatch(
setOf(EnableReaderMode1Fingerprint,EnableReaderMode2Fingerprint)
){
override fun execute(context: BytecodeContext) {
val result1 = EnableReaderMode1Fingerprint.result
?: throw PatchException("EnableReaderMode1Fingerprint not found")

//find location of the flag
var strLoc: Int = 0
result1.scanResult.stringsScanResult!!.matches.forEach{ match ->
val str = match.string
if(str.equals("subscriptions_feature_1005")){
strLoc = match.index
return@forEach
}
}

if(strLoc==0){
throw PatchException("hook not found")
}
//remove the flag check
val methods = result1.mutableMethod
val instructions = methods.getInstructions()
val filters = instructions.filter { it.opcode == Opcode.IF_EQZ }
for(item in filters){
val loc = item.location.index
if(loc > strLoc){
methods.removeInstruction(loc)
break
}
}


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

//remove the flag check
val methods2 = result2.mutableMethod
val loc = methods2.getInstructions().first{it.opcode == Opcode.IF_EQZ}.location.index
methods2.removeInstruction(loc)


//end
}


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

import app.revanced.patcher.fingerprint.MethodFingerprint

object EnableReaderMode1Fingerprint: MethodFingerprint(
returnType = "V",
strings = listOf(
"android_audio_protected_account_creation_enabled",
"subscriptions_feature_1005"
)
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package crimera.patches.twitter.premium.readermode.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object EnableReaderMode2Fingerprint: MethodFingerprint(
returnType = "Ljava/lang/Object;",
strings = listOf(
"id",
"subscriptions_feature_1005",
"extra_tweet_id"
)
)

0 comments on commit e4c9e1a

Please sign in to comment.