From 3e4990afff4c86b93970b153db713ad0f813124d Mon Sep 17 00:00:00 2001 From: hxreborn <32096750+hxreborn@users.noreply.github.com> Date: Sat, 1 Nov 2025 08:32:26 +0100 Subject: [PATCH] fix(TikTok - Downloads): Fix download path setting (#6191) --- .../interaction/downloads/DownloadsPatch.kt | 83 +++++++++---------- 1 file changed, 37 insertions(+), 46 deletions(-) diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt index b80ceaed0..e6894b521 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt @@ -3,14 +3,20 @@ package app.revanced.patches.tiktok.interaction.downloads import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels -import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch import app.revanced.patches.tiktok.misc.settings.settingsPatch import app.revanced.patches.tiktok.misc.settings.settingsStatusLoadFingerprint +import app.revanced.util.findInstructionIndicesReversedOrThrow import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import app.revanced.util.returnEarly +import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.android.tools.smali.dexlib2.iface.reference.FieldReference + +private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/tiktok/download/DownloadsPatch;" @Suppress("unused") val downloadsPatch = bytecodePatch( @@ -28,60 +34,45 @@ val downloadsPatch = bytecodePatch( ) execute { - aclCommonShareFingerprint.method.replaceInstructions( - 0, - """ - const/4 v0, 0x0 - return v0 - """, - ) - - aclCommonShare2Fingerprint.method.replaceInstructions( - 0, - """ - const/4 v0, 0x2 - return v0 - """, - ) + aclCommonShareFingerprint.method.returnEarly(0) + aclCommonShare2Fingerprint.method.returnEarly(2) // Download videos without watermark. aclCommonShare3Fingerprint.method.addInstructionsWithLabels( 0, """ - invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->shouldRemoveWatermark()Z - move-result v0 - if-eqz v0, :noremovewatermark - const/4 v0, 0x1 - return v0 - :noremovewatermark - nop - """, + invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->shouldRemoveWatermark()Z + move-result v0 + if-eqz v0, :noremovewatermark + const/4 v0, 0x1 + return v0 + :noremovewatermark + nop + """, ) // Change the download path patch. downloadUriFingerprint.method.apply { - val firstIndex = indexOfFirstInstructionOrThrow { - getReference()?.name == "" - } - val secondIndex = indexOfFirstInstructionOrThrow { - getReference()?.returnType?.contains("Uri") == true - } + findInstructionIndicesReversedOrThrow { + getReference().let { + it?.definingClass == "Landroid/os/Environment;" && it.name.startsWith("DIRECTORY_") + } + }.forEach { fieldIndex -> + val pathRegister = getInstruction(fieldIndex).registerA + val builderRegister = getInstruction(fieldIndex + 1).registerC - addInstructions( - secondIndex, - """ - invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String; - move-result-object v0 - """, - ) + // Remove 'field load → append → "/Camera/" → append' block. + removeInstructions(fieldIndex, 4) - addInstructions( - firstIndex, - """ - invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String; - move-result-object v0 - """, - ) + addInstructions( + fieldIndex, + """ + invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->getDownloadPath()Ljava/lang/String; + move-result-object v$pathRegister + invoke-virtual { v$builderRegister, v$pathRegister }, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder; + """, + ) + } } settingsStatusLoadFingerprint.method.addInstruction(