Skip to content

Commit

Permalink
feat(Twitter): Add Custom download folder
Browse files Browse the repository at this point in the history
  • Loading branch information
crimera committed Mar 2, 2024
1 parent bc01b60 commit 7c93541
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package crimera.patches.twitter.interaction.downloads.changedirectory

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.extensions.InstructionExtensions.replaceInstruction
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.interaction.downloads.changedirectory.fingerprints.SetDownloadDestinationFingerprint
import crimera.patches.twitter.misc.settings.SettingsPatch.UTILS_DESCRIPTOR

@Patch(
name = "Custom download folder",
description = "Change the download directory for video downloads",
requiresIntegrations = true,
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object ChangeDownloadDirPatch: BytecodePatch(
setOf(SetDownloadDestinationFingerprint)
) {
private const val GETFOLDER_DESCRIPTOR =
"invoke-static {p1}, $UTILS_DESCRIPTOR;->getVideoFolder(Ljava/lang/String;)Ljava/lang/String;"
override fun execute(context: BytecodeContext) {
val result = SetDownloadDestinationFingerprint.result
?: throw PatchException("Could not find fingerprint")

val method = result.mutableMethod

val insertAt = method.getInstructions()
.first { it.opcode == Opcode.INVOKE_VIRTUAL }.location.index

val publicFolderRegister = method.getInstruction<OneRegisterInstruction>(insertAt-1).registerA
method.replaceInstruction(insertAt-1, """
sget-object v$publicFolderRegister, Landroid/os/Environment;->DIRECTORY_MOVIES:Ljava/lang/String;
""".trimIndent())

method.addInstructions(insertAt, """
$GETFOLDER_DESCRIPTOR
move-result-object p1
""".trimIndent())
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package crimera.patches.twitter.interaction.downloads.changedirectory.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

object SetDownloadDestinationFingerprint: MethodFingerprint(
returnType = "V",
strings = listOf(
"parse(downloadData.url)"
)
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crimera.patches.twitter.interaction.downloads
package crimera.patches.twitter.interaction.downloads.unlockdownloads

import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstructions
Expand All @@ -11,8 +11,8 @@ 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.interaction.downloads.fingerprints.DownloadPatchFingerprint
import crimera.patches.twitter.interaction.downloads.fingerprints.FIleDownloaderFingerprint
import crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints.DownloadPatchFingerprint
import crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints.FIleDownloaderFingerprint

// Credits to @iKirby
@Patch(
Expand All @@ -38,7 +38,7 @@ object DownloadPatch : BytecodePatch(
"""
const/4 v5, 0x2
if-eq v4, v5, :cond_0
if-eq v4, v5, :cond_0
""",
ExternalLabel("cond_0", method.getInstructions().first { it.opcode == Opcode.NEW_INSTANCE })
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crimera.patches.twitter.interaction.downloads.fingerprints
package crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package crimera.patches.twitter.interaction.downloads.fingerprints
package crimera.patches.twitter.interaction.downloads.unlockdownloads.fingerprints

import app.revanced.patcher.fingerprint.MethodFingerprint

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ object SettingsPatch : BytecodePatch(
setOf(SettingsFingerprint)
) {
private const val INTEGRATIONS_PACKAGE = "Lapp/revanced/integrations/twitter"
private const val UTILS_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/Utils"
const val UTILS_DESCRIPTOR = "$INTEGRATIONS_PACKAGE/Utils"
private const val ADD_PREF_DESCRIPTOR = "$UTILS_DESCRIPTOR;->addPref([Ljava/lang/String;Ljava/lang/String;)[Ljava/lang/String;"
private const val START_ACTIVITY_DESCRIPTOR =
"invoke-static {}, $UTILS_DESCRIPTOR;->startActivity()V"
Expand Down

0 comments on commit 7c93541

Please sign in to comment.