Skip to content

Commit c0a846f

Browse files
authored
Merge pull request #615 from swakwork/feat/source-label
feat(Twitter): Added `Show post source label` patch
2 parents 1be6fbb + 931bc76 commit c0a846f

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package crimera.patches.twitter.timeline.showSourceLabel
2+
3+
import app.revanced.patcher.data.BytecodeContext
4+
import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels
5+
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
6+
import app.revanced.patcher.fingerprint.MethodFingerprint
7+
import app.revanced.patcher.patch.BytecodePatch
8+
import app.revanced.patcher.patch.PatchException
9+
import app.revanced.patcher.patch.annotation.CompatiblePackage
10+
import app.revanced.patcher.patch.annotation.Patch
11+
import app.revanced.patcher.util.smali.ExternalLabel
12+
import com.android.tools.smali.dexlib2.Opcode
13+
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction11n
14+
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c
15+
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
16+
import crimera.patches.twitter.misc.settings.SettingsPatch
17+
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint
18+
import crimera.patches.twitter.misc.shareMenu.nativeDownloader.extractDescriptors
19+
20+
object SourceLabelFingerprint : MethodFingerprint(
21+
strings = listOf("show_tweet_source_disabled"),
22+
)
23+
24+
@Patch(
25+
name = "Show post source label",
26+
description = "Source label will be shown only on public posts",
27+
dependencies = [SettingsPatch::class],
28+
compatiblePackages = [CompatiblePackage("com.twitter.android")],
29+
requiresIntegrations = true,
30+
)
31+
@Suppress("unused")
32+
object ShowSourceLabel : BytecodePatch(
33+
setOf(SettingsStatusLoadFingerprint, SourceLabelFingerprint),
34+
) {
35+
override fun execute(context: BytecodeContext) {
36+
val result = SourceLabelFingerprint.result ?: throw PatchException("SourceLabelFingerprint not found")
37+
38+
val method = result.mutableMethod
39+
40+
val instructions = method.getInstructions()
41+
42+
val igetWide = instructions.first { it.opcode == Opcode.IGET_WIDE }
43+
val igetWideIns = igetWide as Instruction22c
44+
val idRef = igetWideIns.reference.extractDescriptors()[0]
45+
val idReg = igetWideIns.registerB
46+
47+
val igetWideIndex = igetWide.location.index
48+
val igetWideP1Ins = instructions[igetWideIndex + 1] as Instruction35c
49+
val dummyReg1 = igetWideP1Ins.registerC
50+
val dummyReg2 = igetWideP1Ins.registerD
51+
52+
val const4 = instructions.filter { it.opcode == Opcode.CONST_4 }[1]
53+
val const4Ins = const4 as Instruction11n
54+
val const4Reg = const4Ins.registerA
55+
56+
val apiMethod = "${SettingsPatch.PATCHES_DESCRIPTOR}/tweet/TweetInfoAPI;"
57+
method.addInstructionsWithLabels(
58+
const4.location.index + 1,
59+
"""
60+
sget-boolean v$dummyReg1, ${SettingsPatch.PREF_DESCRIPTOR};->SHOW_SRC_LBL:Z
61+
if-eqz v$dummyReg1, :piko
62+
invoke-virtual {v$idReg}, $idRef->getId()J
63+
move-result-wide v$dummyReg1
64+
65+
invoke-static {v$dummyReg1, v$dummyReg2}, $apiMethod->sendRequest(J)V
66+
invoke-static {v$dummyReg1, v$dummyReg2}, $apiMethod->getTweetSource(J)Ljava/lang/String;
67+
move-result-object v$const4Reg
68+
""".trimIndent(),
69+
ExternalLabel("piko", igetWide),
70+
)
71+
72+
SettingsStatusLoadFingerprint.enableSettings("showSourceLabel")
73+
}
74+
}

src/main/resources/twitter/settings/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@
9999
<!-- Timeline Settings -->
100100
<string name="piko_title_timeline">Timeline</string>
101101
<string name="piko_pref_disable_auto_timeline_scroll">Disable auto timeline scroll on launch</string>
102+
<string name="piko_pref_show_post_source">Show post source label</string>
103+
<string name="piko_pref_show_post_source_desc">There might be a delay while opening a post info and also label will be shown only on public posts</string>
102104
<string name="piko_pref_hide_live_threads">live threads</string>
103105
<string name="piko_pref_hide_live_threads_desc">Hides live section in timeline</string>
104106
<string name="piko_pref_hide_banner">banner</string>

0 commit comments

Comments
 (0)