|
| 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 | +} |
0 commit comments