Skip to content

Commit

Permalink
feat(tiktok): adapt tiktok-download with tiktok-settings. (#586)
Browse files Browse the repository at this point in the history
  • Loading branch information
d4rkk3y committed Sep 23, 2022
1 parent fcbe2da commit 301e72e
Showing 1 changed file with 23 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -31,7 +36,8 @@ class DownloadsPatch : BytecodePatch(
ACLCommonShareFingerprint,
ACLCommonShareFingerprint2,
ACLCommonShareFingerprint3,
DownloadPathParentFingerprint
DownloadPathParentFingerprint,
SettingsStatusLoadFingerprint
)
) {
override fun execute(data: BytecodeData): PatchResult {
Expand All @@ -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
Expand All @@ -77,18 +88,18 @@ 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)
.getMethod() as MutableMethod
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
"""
)
}
Expand All @@ -106,30 +117,11 @@ class DownloadsPatch : BytecodePatch(
}
}
}
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
)
val method5 = SettingsStatusLoadFingerprint.result!!.mutableMethod
method5.addInstruction(
0,
"invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableDownload()V"
)
return PatchResultSuccess()
}
}

0 comments on commit 301e72e

Please sign in to comment.