feat(tiktok): adapt tiktok-download with tiktok-settings. (#586)

This commit is contained in:
d4rkk3y 2022-09-23 12:40:16 +07:00 committed by GitHub
parent 4327ac1dc3
commit 876b726610
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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
)
)
}
}