Skip to content

Commit

Permalink
feat(Tiktok): Bump compatibility to 32.5.3 (#3389)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: This removes a patch but consolidates it into another.
  • Loading branch information
d4rkk3y authored Dec 12, 2023
1 parent b7e53fb commit 96cdc10
Show file tree
Hide file tree
Showing 13 changed files with 170 additions and 245 deletions.
6 changes: 0 additions & 6 deletions api/revanced-patches.api
Original file line number Diff line number Diff line change
Expand Up @@ -814,12 +814,6 @@ public final class app/revanced/patches/ticktick/misc/themeunlock/UnlockProPatch
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/tiktok/ad/HideAdsPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/tiktok/ad/HideAdsPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V
}

public final class app/revanced/patches/tiktok/feedfilter/FeedFilterPatch : app/revanced/patcher/patch/BytecodePatch {
public static final field INSTANCE Lapp/revanced/patches/tiktok/feedfilter/FeedFilterPatch;
public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V
Expand Down
51 changes: 0 additions & 51 deletions src/main/kotlin/app/revanced/patches/tiktok/ad/HideAdsPatch.kt

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,40 +1,44 @@
package app.revanced.patches.tiktok.feedfilter

import app.revanced.util.exception
import app.revanced.patcher.data.BytecodeContext
import app.revanced.patcher.extensions.InstructionExtensions.addInstruction
import app.revanced.patcher.extensions.InstructionExtensions.getInstructions
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patches.tiktok.feedfilter.fingerprints.FeedApiServiceLIZFingerprint
import app.revanced.patches.tiktok.misc.integrations.IntegrationsPatch
import app.revanced.patches.tiktok.misc.settings.SettingsPatch
import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint
import app.revanced.util.exception
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction

@Patch(
name = "Feed filter",
description = "Filters tiktok videos: removing ads, removing livestreams.",
description = "Removes ads, livestreams, stories, image videos " +
"and videos with a specific amount of views or likes from the feed.",
dependencies = [IntegrationsPatch::class, SettingsPatch::class],
compatiblePackages = [
CompatiblePackage("com.ss.android.ugc.trill"),
CompatiblePackage("com.zhiliaoapp.musically")
CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]),
CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"])
]
)
@Suppress("unused")
object FeedFilterPatch : BytecodePatch(setOf(FeedApiServiceLIZFingerprint, SettingsStatusLoadFingerprint)) {
object FeedFilterPatch : BytecodePatch(
setOf(FeedApiServiceLIZFingerprint, SettingsStatusLoadFingerprint)
) {
override fun execute(context: BytecodeContext) {
val method = FeedApiServiceLIZFingerprint.result!!.mutableMethod
for ((index, instruction) in method.implementation!!.instructions.withIndex()) {
if (instruction.opcode != Opcode.RETURN_OBJECT) continue
val feedItemsRegister = (instruction as OneRegisterInstruction).registerA
method.addInstruction(
index,
"invoke-static {v$feedItemsRegister}, Lapp/revanced/tiktok/feedfilter/FeedItemsFilter;->filter(Lcom/ss/android/ugc/aweme/feed/model/FeedItemList;)V"
FeedApiServiceLIZFingerprint.result?.mutableMethod?.apply {
val returnFeedItemInstruction = getInstructions().first { it.opcode == Opcode.RETURN_OBJECT }
val feedItemsRegister = (returnFeedItemInstruction as OneRegisterInstruction).registerA

addInstruction(
returnFeedItemInstruction.location.index,
"invoke-static { v$feedItemsRegister }, " +
"Lapp/revanced/tiktok/feedfilter/FeedItemsFilter;->filter(Lcom/ss/android/ugc/aweme/feed/model/FeedItemList;)V"
)
break
}
} ?: throw FeedApiServiceLIZFingerprint.exception

SettingsStatusLoadFingerprint.result?.mutableMethod?.addInstruction(
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package app.revanced.patches.tiktok.feedfilter.fingerprints

import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags

internal object FeedApiServiceLIZFingerprint : MethodFingerprint(
accessFlags = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.SYNTHETIC,
customFingerprint = { methodDef, _ ->
methodDef.definingClass.endsWith("/FeedApiService;") && methodDef.name == "LIZ"
methodDef.definingClass.endsWith("/FeedApiService;") && methodDef.name == "fetchFeedList"
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import app.revanced.patcher.data.BytecodeContext
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.replaceInstruction
import app.revanced.patcher.extensions.InstructionExtensions.replaceInstructions
import app.revanced.patcher.fingerprint.MethodFingerprint
import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchException
import app.revanced.patcher.patch.annotation.CompatiblePackage
import app.revanced.patcher.patch.annotation.Patch
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
Expand All @@ -18,18 +17,19 @@ import app.revanced.patches.tiktok.interaction.downloads.fingerprints.DownloadPa
import app.revanced.patches.tiktok.misc.integrations.IntegrationsPatch
import app.revanced.patches.tiktok.misc.settings.SettingsPatch
import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint
import app.revanced.util.exception
import app.revanced.util.indexOfFirstInstruction
import com.android.tools.smali.dexlib2.Opcode
import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction
import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction
import com.android.tools.smali.dexlib2.iface.reference.StringReference
import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c
import com.android.tools.smali.dexlib2.iface.reference.MethodReference

@Patch(
name = "Downloads",
description = "Removes download restrictions and changes the default path to download to.",
dependencies = [IntegrationsPatch::class, SettingsPatch::class],
compatiblePackages = [
CompatiblePackage("com.ss.android.ugc.trill", ["30.8.4"]),
CompatiblePackage("com.zhiliaoapp.musically", ["30.8.4"])
CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]),
CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"])
]
)
@Suppress("unused")
Expand All @@ -43,86 +43,83 @@ object DownloadsPatch : BytecodePatch(
)
) {
override fun execute(context: BytecodeContext) {
val method1 = ACLCommonShareFingerprint.result!!.mutableMethod
method1.replaceInstructions(
0,
"""
const/4 v0, 0x0
return v0
"""
)
val method2 = ACLCommonShareFingerprint2.result!!.mutableMethod
method2.replaceInstructions(
0,
"""
const/4 v0, 0x2
return v0
"""
)
//Download videos without watermark.
val method3 = ACLCommonShareFingerprint3.result!!.mutableMethod
method3.addInstructionsWithLabels(
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
val method4 = DownloadPathParentFingerprint.result!!.mutableMethod
val implementation4 = method4.implementation
val instructions = implementation4!!.instructions
var targetOffset = -1
//Search for the target method called instruction offset.
for ((index, instruction) in instructions.withIndex()) {
if (instruction.opcode != Opcode.CONST_STRING) continue
val reference = (instruction as ReferenceInstruction).reference as StringReference
if (reference.string != "video/mp4") continue
val targetInstruction = instructions[index + 1]
if (targetInstruction.opcode != Opcode.INVOKE_STATIC) continue
targetOffset = index + 1
break
}
if (targetOffset == -1) throw PatchException("Can not find download path uri method.")
//Change videos' download path.
val downloadUriMethod = context
.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.addInstructions(
index + 1,
fun MethodFingerprint.getMethod() = result?.mutableMethod ?: throw exception

mapOf<MethodFingerprint, MutableMethod.() -> Unit>(
ACLCommonShareFingerprint to {
replaceInstructions(
0,
"""
invoke-static {}, Lapp/revanced/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String;
move-result-object v$overrideRegister
const/4 v0, 0x0
return v0
"""
)
}
if (instruction.opcode == Opcode.CONST_STRING) {
val string = ((instruction as ReferenceInstruction).reference as StringReference).string
if (string.contains("/Camera")) {
val overrideRegister = (instruction as OneRegisterInstruction).registerA
val overrideString = string.replace("/Camera", "")
downloadUriMethod.replaceInstruction(
index,
"""
const-string v$overrideRegister, "$overrideString"
"""
},
ACLCommonShareFingerprint2 to {
replaceInstructions(
0,
"""
const/4 v0, 0x2
return v0
"""
)
},
// Download videos without watermark.
ACLCommonShareFingerprint3 to {
addInstructionsWithLabels(
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.
DownloadPathParentFingerprint to {
val targetIndex = indexOfFirstInstruction { opcode == Opcode.INVOKE_STATIC }
val downloadUriMethod = context
.toMethodWalker(this)
.nextMethod(targetIndex, true)
.getMethod() as MutableMethod

val firstIndex = downloadUriMethod.indexOfFirstInstruction {
opcode == Opcode.INVOKE_DIRECT && ((this as Instruction35c).reference as MethodReference).name == "<init>"
}
val secondIndex = downloadUriMethod.indexOfFirstInstruction {
opcode == Opcode.INVOKE_STATIC && ((this as Instruction35c).reference as MethodReference).returnType.contains(
"Uri"
)
}

downloadUriMethod.addInstructions(
secondIndex,
"""
invoke-static {}, Lapp/revanced/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String;
move-result-object v0
"""
)

downloadUriMethod.addInstructions(
firstIndex,
"""
invoke-static {}, Lapp/revanced/tiktok/download/DownloadsPatch;->getDownloadPath()Ljava/lang/String;
move-result-object v0
"""
)
},
SettingsStatusLoadFingerprint to {
addInstruction(
0,
"invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableDownload()V"
)
}
).forEach { (fingerprint, patch) ->
fingerprint.getMethod().patch()
}
val method5 = SettingsStatusLoadFingerprint.result!!.mutableMethod
method5.addInstruction(
0,
"invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableDownload()V"
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,22 @@ package app.revanced.patches.tiktok.interaction.downloads.fingerprints
import app.revanced.patcher.extensions.or
import app.revanced.patcher.fingerprint.MethodFingerprint
import com.android.tools.smali.dexlib2.AccessFlags
import com.android.tools.smali.dexlib2.Opcode

internal object DownloadPathParentFingerprint : MethodFingerprint(
"V",
AccessFlags.PUBLIC or AccessFlags.FINAL,
"L",
AccessFlags.PUBLIC or AccessFlags.STATIC,
strings = listOf(
"code",
"reason",
"params insufficient"
"video/mp4"
),
parameters = listOf(
"L",
"L"
),
opcodes = listOf(
Opcode.CONST_STRING,
Opcode.INVOKE_STATIC,
Opcode.MOVE_RESULT_OBJECT,
Opcode.RETURN_OBJECT
)
)
Loading

0 comments on commit 96cdc10

Please sign in to comment.