fix(TikTok - Downloads): Fix download path setting (#6191)

This commit is contained in:
hxreborn
2025-11-01 08:32:26 +01:00
committed by GitHub
parent 292fae440c
commit 3e4990afff

View File

@@ -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,27 +34,14 @@ 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
invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->shouldRemoveWatermark()Z
move-result v0
if-eqz v0, :noremovewatermark
const/4 v0, 0x1
@@ -60,29 +53,27 @@ val downloadsPatch = bytecodePatch(
// Change the download path patch.
downloadUriFingerprint.method.apply {
val firstIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.name == "<init>"
}
val secondIndex = indexOfFirstInstructionOrThrow {
getReference<MethodReference>()?.returnType?.contains("Uri") == true
findInstructionIndicesReversedOrThrow {
getReference<FieldReference>().let {
it?.definingClass == "Landroid/os/Environment;" && it.name.startsWith("DIRECTORY_")
}
}.forEach { fieldIndex ->
val pathRegister = getInstruction<OneRegisterInstruction>(fieldIndex).registerA
val builderRegister = getInstruction<FiveRegisterInstruction>(fieldIndex + 1).registerC
// Remove 'field load → append → "/Camera/" → append' block.
removeInstructions(fieldIndex, 4)
addInstructions(
secondIndex,
fieldIndex,
"""
invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String;
move-result-object v0
""",
)
addInstructions(
firstIndex,
"""
invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String;
move-result-object v0
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(
0,