From 301e72e816a2e3178a6a4c2bb4a5d0f69ae736a3 Mon Sep 17 00:00:00 2001 From: d4rkk3y <43563783+d4rkk3y@users.noreply.github.com> Date: Fri, 23 Sep 2022 12:40:16 +0700 Subject: [PATCH] feat(tiktok): adapt `tiktok-download` with `tiktok-settings`. (#586) --- .../downloads/patch/DownloadsPatch.kt | 54 ++++++++----------- 1 file changed, 23 insertions(+), 31 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/patch/DownloadsPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/patch/DownloadsPatch.kt index 3e2cb34a4..5bebe22cf 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/patch/DownloadsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/patch/DownloadsPatch.kt @@ -5,9 +5,13 @@ import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version import app.revanced.patcher.data.impl.BytecodeData import app.revanced.patcher.data.impl.toMethodWalker +import app.revanced.patcher.extensions.addInstruction +import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.extensions.replaceInstructions -import app.revanced.patcher.patch.* +import app.revanced.patcher.patch.PatchResult +import app.revanced.patcher.patch.PatchResultError +import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.Patch import app.revanced.patcher.patch.impl.BytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod @@ -16,6 +20,7 @@ import app.revanced.patches.tiktok.interaction.downloads.fingerprints.ACLCommonS import app.revanced.patches.tiktok.interaction.downloads.fingerprints.ACLCommonShareFingerprint2 import app.revanced.patches.tiktok.interaction.downloads.fingerprints.ACLCommonShareFingerprint3 import app.revanced.patches.tiktok.interaction.downloads.fingerprints.DownloadPathParentFingerprint +import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction @@ -31,7 +36,8 @@ class DownloadsPatch : BytecodePatch( ACLCommonShareFingerprint, ACLCommonShareFingerprint2, ACLCommonShareFingerprint3, - DownloadPathParentFingerprint + DownloadPathParentFingerprint, + SettingsStatusLoadFingerprint ) ) { override fun execute(data: BytecodeData): PatchResult { @@ -53,11 +59,16 @@ class DownloadsPatch : BytecodePatch( ) //Download videos without watermark. val method3 = ACLCommonShareFingerprint3.result!!.mutableMethod - method3.replaceInstructions( + method3.addInstructions( 0, """ + invoke-static {}, Lapp/revanced/tiktok/download/DownloadsPatch;->shouldRemoveWatermark()Z + move-result v0 + if-eqz v0, :noremovewatermark const/4 v0, 0x1 return v0 + :noremovewatermark + nop """ ) //Change the download path patch @@ -77,7 +88,6 @@ class DownloadsPatch : BytecodePatch( } if (targetOffset == -1) return PatchResultError("Can not find download path uri method.") //Change videos' download path. - val downloadPath = "$downloadPathParent/$downloadPathChild" val downloadUriMethod = data .toMethodWalker(DownloadPathParentFingerprint.result!!.method) .nextMethod(targetOffset, true) @@ -85,10 +95,11 @@ class DownloadsPatch : BytecodePatch( downloadUriMethod.implementation!!.instructions.forEachIndexed { index, instruction -> if (instruction.opcode == Opcode.SGET_OBJECT) { val overrideRegister = (instruction as OneRegisterInstruction).registerA - downloadUriMethod.replaceInstruction( - index, + downloadUriMethod.addInstructions( + index + 1, """ - const-string v$overrideRegister, "$downloadPath" + invoke-static {}, Lapp/revanced/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String; + move-result-object v$overrideRegister """ ) } @@ -106,30 +117,11 @@ class DownloadsPatch : BytecodePatch( } } } + val method5 = SettingsStatusLoadFingerprint.result!!.mutableMethod + method5.addInstruction( + 0, + "invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableDownload()V" + ) return PatchResultSuccess() } - - companion object : OptionsContainer() { - private var downloadPathParent: String? by option( - PatchOption.StringListOption( - key = "mediaFolder", - default = "DCIM", - options = listOf( - "DCIM", "Movies", "Pictures" - ), - title = "Media folder", - description = "The media root folder to download to.", - required = true - ) - ) - private var downloadPathChild: String? by option( - PatchOption.StringOption( - key = "downloadPath", - default = "TikTok", - title = "Download path", - description = "Download path relative to the media folder.", - required = true - ) - ) - } } \ No newline at end of file