Skip to content

Commit

Permalink
fix(Custom download folder): Restore compatibility with versions prio…
Browse files Browse the repository at this point in the history
…r to 10.64
  • Loading branch information
crimera committed Oct 21, 2024
1 parent 4e7b0f4 commit b88b00b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ 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.interaction.downloads.copyMediaLink.DownloadCallFingerprint
import crimera.patches.twitter.misc.settings.SettingsPatch
import crimera.patches.twitter.misc.settings.SettingsPatch.PREF_DESCRIPTOR
import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFingerprint
Expand All @@ -22,31 +22,33 @@ import crimera.patches.twitter.misc.settings.fingerprints.SettingsStatusLoadFing
compatiblePackages = [CompatiblePackage("com.twitter.android")]
)
@Suppress("unused")
object ChangeDownloadDirPatch: BytecodePatch(
setOf(SetDownloadDestinationFingerprint, SettingsStatusLoadFingerprint)
object ChangeDownloadDirPatch : BytecodePatch(
setOf(DownloadCallFingerprint, SettingsStatusLoadFingerprint)
) {
private const val GETFOLDER_DESCRIPTOR =
"invoke-static {p1}, $PREF_DESCRIPTOR;->getVideoFolder(Ljava/lang/String;)Ljava/lang/String;"
private const val PUBLICFOLDER_DESCRIPTOR =
"invoke-static {}, $PREF_DESCRIPTOR;->getPublicFolder()Ljava/lang/String;"

override fun execute(context: BytecodeContext) {
val result = SetDownloadDestinationFingerprint.result
?: throw PatchException("Could not find fingerprint")
val result = DownloadCallFingerprint.result ?: throw PatchException("Could not find fingerprint")

val method = result.mutableMethod
val method = result.mutableClass.methods.findLast { method ->
method.implementation?.instructions?.map { it.opcode }?.contains(Opcode.NEW_INSTANCE) == true
} ?: throw PatchException("Error")

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

val publicFolderRegister = method.getInstruction<OneRegisterInstruction>(insertAt-1).registerA
method.addInstructions(insertAt, """
val publicFolderRegister = method.getInstruction<OneRegisterInstruction>(insertAt - 1).registerA
method.addInstructions(
insertAt, """
$PUBLICFOLDER_DESCRIPTOR
move-result-object v$publicFolderRegister
$GETFOLDER_DESCRIPTOR
move-result-object p1
""".trimIndent())
""".trimIndent()
)

SettingsStatusLoadFingerprint.enableSettings("enableDownloadFolder")
}
Expand Down

This file was deleted.

0 comments on commit b88b00b

Please sign in to comment.