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.
feat(Twitter): added
Reader Mode patch
- Loading branch information
Showing
3 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
src/main/kotlin/crimera/patches/twitter/premium/readermode/EnableReaderModePatch.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,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 | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...n/crimera/patches/twitter/premium/readermode/fingerprints/EnableReaderMode1Fingerprint.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 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" | ||
) | ||
) |
12 changes: 12 additions & 0 deletions
12
...n/crimera/patches/twitter/premium/readermode/fingerprints/EnableReaderMode2Fingerprint.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 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" | ||
) | ||
) |