generated from ReVanced/revanced-patches-template
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Twitter): Add
Custom download folder
- Loading branch information
Showing
6 changed files
with
65 additions
and
7 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
...n/crimera/patches/twitter/interaction/downloads/changedirectory/ChangeDownloadDirPatch.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,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()) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...r/interaction/downloads/changedirectory/fingerprints/SetDownloadDestinationFingerprint.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,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)" | ||
) | ||
) |
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
2 changes: 1 addition & 1 deletion
2
.../fingerprints/DownloadPatchFingerprint.kt → .../fingerprints/DownloadPatchFingerprint.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
2 changes: 1 addition & 1 deletion
2
...fingerprints/FIleDownloaderFingerprint.kt → ...fingerprints/FIleDownloaderFingerprint.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
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