From 7f3f75dc44cbe2d56c6b0e8d6dc495bec8c53e4a Mon Sep 17 00:00:00 2001 From: inotia00 Date: Sun, 7 May 2023 05:27:41 +0900 Subject: [PATCH] feat(tiktok): bump compatibility to `29.3.4` --- .../annotations/FeedFilterCompatibility.kt | 4 +- .../FeedApiServiceLIZFingerprint.kt | 12 +- .../feedfilter/patch/FeedFilterPatch.kt | 31 ++--- .../annotations/DownloadsCompatibility.kt | 4 +- .../annotations/SettingsCompatibility.kt | 4 +- .../fingerprints/AboutPageFingerprint.kt | 17 +++ .../fingerprints/AboutViewFingerprint.kt | 37 ------ .../misc/settings/patch/SettingsPatch.kt | 106 +++++++++--------- .../sim/annotations/SpoofSimCompatibility.kt | 4 +- 9 files changed, 104 insertions(+), 115 deletions(-) create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutPageFingerprint.kt delete mode 100644 src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutViewFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/annotations/FeedFilterCompatibility.kt b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/annotations/FeedFilterCompatibility.kt index a4c40c748..0e6e8e681 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/annotations/FeedFilterCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/annotations/FeedFilterCompatibility.kt @@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package @Compatibility( [ - Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), - Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) + Package("com.ss.android.ugc.trill", arrayOf("27.8.3", "29.3.4")), + Package("com.zhiliaoapp.musically", arrayOf("27.8.3", "29.3.4")) ] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/fingerprints/FeedApiServiceLIZFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/fingerprints/FeedApiServiceLIZFingerprint.kt index 667e5abcd..792680f22 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/fingerprints/FeedApiServiceLIZFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/fingerprints/FeedApiServiceLIZFingerprint.kt @@ -1,12 +1,12 @@ package app.revanced.patches.tiktok.feedfilter.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.AccessFlags +import org.jf.dexlib2.Opcode object FeedApiServiceLIZFingerprint : MethodFingerprint( - access = AccessFlags.PUBLIC or AccessFlags.STATIC or AccessFlags.SYNTHETIC, - customFingerprint = { methodDef -> - methodDef.definingClass.endsWith("/FeedApiService;") && methodDef.name == "LIZ" - } + opcodes = listOf( + Opcode.RETURN_OBJECT, + Opcode.MOVE_EXCEPTION + ), + customFingerprint = { it.definingClass.endsWith("/FeedApiService;") } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/patch/FeedFilterPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/patch/FeedFilterPatch.kt index fb6ba0b32..3d583ff96 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/patch/FeedFilterPatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/patch/FeedFilterPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.tiktok.feedfilter.patch +import app.revanced.extensions.toErrorResult import app.revanced.patcher.annotation.Description import app.revanced.patcher.annotation.Name import app.revanced.patcher.annotation.Version @@ -15,7 +16,6 @@ import app.revanced.patches.tiktok.feedfilter.fingerprints.FeedApiServiceLIZFing import app.revanced.patches.tiktok.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsStatusLoadFingerprint import app.revanced.patches.tiktok.misc.settings.patch.SettingsPatch -import org.jf.dexlib2.Opcode import org.jf.dexlib2.iface.instruction.OneRegisterInstruction @Patch @@ -31,21 +31,24 @@ class FeedFilterPatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext): PatchResult { - 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" - ) - break - } - val method2 = SettingsStatusLoadFingerprint.result!!.mutableMethod - method2.addInstruction( + + FeedApiServiceLIZFingerprint.result?.let { + val index = it.scanResult.patternScanResult!!.startIndex + + with (it.mutableMethod) { + val register = (this.implementation!!.instructions[index] as OneRegisterInstruction).registerA + addInstruction( + index, + "invoke-static {v$register}, Lapp/revanced/tiktok/feedfilter/FeedItemsFilter;->filter(Lcom/ss/android/ugc/aweme/feed/model/FeedItemList;)V" + ) + } + } ?: return FeedApiServiceLIZFingerprint.toErrorResult() + + SettingsStatusLoadFingerprint.result?.mutableMethod?.addInstruction( 0, "invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsStatus;->enableFeedFilter()V" - ) + ) ?: return SettingsStatusLoadFingerprint.toErrorResult() + return PatchResultSuccess() } } diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/annotations/DownloadsCompatibility.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/annotations/DownloadsCompatibility.kt index a193c100f..64a37aae2 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/annotations/DownloadsCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/annotations/DownloadsCompatibility.kt @@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package @Compatibility( [ - Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), - Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) + Package("com.ss.android.ugc.trill", arrayOf("27.8.3", "29.3.4")), + Package("com.zhiliaoapp.musically", arrayOf("27.8.3", "29.3.4")) ] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/annotations/SettingsCompatibility.kt b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/annotations/SettingsCompatibility.kt index cb994126b..c398752dd 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/annotations/SettingsCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/annotations/SettingsCompatibility.kt @@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package @Compatibility( [ - Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), - Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) + Package("com.ss.android.ugc.trill", arrayOf("27.8.3", "29.3.4")), + Package("com.zhiliaoapp.musically", arrayOf("27.8.3", "29.3.4")) ] ) @Target(AnnotationTarget.CLASS) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutPageFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutPageFingerprint.kt new file mode 100644 index 000000000..b7ecb1c3c --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutPageFingerprint.kt @@ -0,0 +1,17 @@ +package app.revanced.patches.tiktok.misc.settings.fingerprints + +import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint +import org.jf.dexlib2.Opcode + +object AboutPageFingerprint : MethodFingerprint( + opcodes = listOf( + Opcode.CONST, + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_STRING + ), + customFingerprint = { + it.definingClass == "Lcom/ss/android/ugc/aweme/setting/page/AboutPage;" && + it.name == "onViewCreated" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutViewFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutViewFingerprint.kt deleted file mode 100644 index e4b680c31..000000000 --- a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/fingerprints/AboutViewFingerprint.kt +++ /dev/null @@ -1,37 +0,0 @@ -package app.revanced.patches.tiktok.misc.settings.fingerprints - -import app.revanced.patcher.fingerprint.method.annotation.FuzzyPatternScanMethod -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint -import org.jf.dexlib2.Opcode - -@FuzzyPatternScanMethod(4) -object AboutViewFingerprint : MethodFingerprint( - opcodes = listOf( - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.INVOKE_DIRECT_RANGE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.NEW_INSTANCE, - Opcode.NEW_INSTANCE, - Opcode.CONST, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT_OBJECT, - Opcode.SGET_OBJECT, - Opcode.INVOKE_STATIC, - Opcode.MOVE_RESULT_OBJECT, - Opcode.NEW_INSTANCE, - Opcode.INVOKE_DIRECT, - Opcode.CONST_4, - Opcode.CONST_STRING, - Opcode.INVOKE_DIRECT_RANGE, - Opcode.INVOKE_DIRECT, - Opcode.IPUT_OBJECT, - Opcode.CONST, - Opcode.SGET_OBJECT, - Opcode.INVOKE_VIRTUAL, - Opcode.MOVE_RESULT, - Opcode.IF_EQZ, - Opcode.CONST - ) -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/patch/SettingsPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/patch/SettingsPatch.kt index 0fcd0943d..7b2823399 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/patch/SettingsPatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/patch/SettingsPatch.kt @@ -8,23 +8,24 @@ import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.instruction import app.revanced.patcher.extensions.replaceInstruction -import app.revanced.patcher.fingerprint.method.impl.MethodFingerprint.Companion.resolve import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.PatchResult import app.revanced.patcher.patch.PatchResultError import app.revanced.patcher.patch.PatchResultSuccess import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch +import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patches.tiktok.misc.integrations.patch.IntegrationsPatch import app.revanced.patches.tiktok.misc.settings.annotations.SettingsCompatibility -import app.revanced.patches.tiktok.misc.settings.fingerprints.AboutViewFingerprint +import app.revanced.patches.tiktok.misc.settings.fingerprints.AboutPageFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.AdPersonalizationActivityOnCreateFingerprint import app.revanced.patches.tiktok.misc.settings.fingerprints.SettingsOnViewCreatedFingerprint import org.jf.dexlib2.Opcode +import org.jf.dexlib2.builder.instruction.BuilderInstruction21c import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction import org.jf.dexlib2.iface.instruction.formats.Instruction35c -import org.jf.dexlib2.iface.reference.StringReference import org.jf.dexlib2.iface.reference.TypeReference @Patch @@ -35,77 +36,82 @@ import org.jf.dexlib2.iface.reference.TypeReference @Version("0.0.1") class SettingsPatch : BytecodePatch( listOf( + AboutPageFingerprint, AdPersonalizationActivityOnCreateFingerprint, SettingsOnViewCreatedFingerprint, ) ) { override fun execute(context: BytecodeContext): PatchResult { - SettingsOnViewCreatedFingerprint.result?.let { - AboutViewFingerprint.resolve(context, it.method, it.classDef) - } - // Patch Settings UI to add 'Revanced Settings'. - val targetIndexes = findOptionsOnClickIndex() - with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) { - for (index in targetIndexes) { - if ( - instruction(index).opcode != Opcode.NEW_INSTANCE || - instruction(index - 4).opcode != Opcode.MOVE_RESULT_OBJECT - ) - return PatchResultError("Hardcode offset changed.") - patchOptionNameAndOnClickEvent(index, context) + + AboutPageFingerprint.result?.let { + val startIndex = it.scanResult.patternScanResult!!.startIndex + + with(it.mutableMethod.implementation!!.instructions) { + copyrightPolicyLabelId = (this[startIndex] as WideLiteralInstruction).wideLiteral } - } - // Implement settings screen in `AdPersonalizationActivity` - with(AdPersonalizationActivityOnCreateFingerprint.result!!.mutableMethod) { - for ((index, instruction) in implementation!!.instructions.withIndex()) { + + } ?: return AboutPageFingerprint.toErrorResult() + + SettingsOnViewCreatedFingerprint.result?.mutableMethod?.let { method -> + val copyrightInstructions = method.implementation!!.instructions + + val copyrightIndex = copyrightInstructions.indexOfFirst { + it.opcode == Opcode.CONST_STRING && + (it as BuilderInstruction21c).reference.toString() == "copyright_policy" + } - 6 + + val copyrightPolicyIndex = copyrightInstructions.indexOfFirst { + it.opcode == Opcode.CONST && + (it as WideLiteralInstruction).wideLiteral == copyrightPolicyLabelId + } + 2 + + arrayOf( + copyrightIndex, + copyrightPolicyIndex + ).forEach { + if (method.instruction(it).opcode != Opcode.MOVE_RESULT_OBJECT) + return PatchResultError("Hardcode offset changed.") + val register = (method.instruction(it) as OneRegisterInstruction).registerA + + method.insertSettings(context, it, register) + } + + } ?: return SettingsOnViewCreatedFingerprint.toErrorResult() + + AdPersonalizationActivityOnCreateFingerprint.result?.mutableMethod?.let { + for ((index, instruction) in it.implementation!!.instructions.withIndex()) { if (instruction.opcode != Opcode.INVOKE_SUPER) continue val thisRegister = (instruction as Instruction35c).registerC - addInstructions( + it.addInstructions( index + 1, """ invoke-static {v$thisRegister}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->initializeSettings(Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;)V return-void """ ) - break + return PatchResultSuccess() } - } - return PatchResultSuccess() + } ?: return AdPersonalizationActivityOnCreateFingerprint.toErrorResult() + + return PatchResultError("Could not find the method to hook.") } - private fun findOptionsOnClickIndex(): IntArray { - val results = IntArray(2) - SettingsOnViewCreatedFingerprint.result?.apply { - for ((index, instruction) in mutableMethod.implementation!!.instructions.withIndex()) { - // Old UI settings option to replace to 'Revanced Settings' - if (instruction.opcode == Opcode.CONST_STRING) { - val string = ((instruction as ReferenceInstruction).reference as StringReference).string - if (string == "copyright_policy") { - results[0] = index - 2 - break - } - } - } + private companion object { + var copyrightPolicyLabelId: Long = -1 - // New UI settings option to replace to 'Revanced Settings' - results[1] = AboutViewFingerprint.result!!.scanResult.patternScanResult!!.startIndex - } ?: throw SettingsOnViewCreatedFingerprint.toErrorResult() - return results - } - - private fun patchOptionNameAndOnClickEvent(index: Int, context: BytecodeContext) { - with(SettingsOnViewCreatedFingerprint.result!!.mutableMethod) { - // Patch option name - val overrideRegister = (instruction(index - 4) as OneRegisterInstruction).registerA + fun MutableMethod.insertSettings( + context: BytecodeContext, + index: Int, + overrideRegister: Int + ) { replaceInstruction( - index - 4, + index, """ const-string v$overrideRegister, "Revanced Settings" """ ) - // Patch option OnClick Event - with(((instruction(index) as ReferenceInstruction).reference as TypeReference).type) { + with(((instruction(index + 4) as ReferenceInstruction).reference as TypeReference).type) { context.findClass(this)!!.mutableClass.methods.first { it.name == "onClick" } .addInstructions( 0, diff --git a/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/annotations/SpoofSimCompatibility.kt b/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/annotations/SpoofSimCompatibility.kt index 97b091e61..3888e6967 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/annotations/SpoofSimCompatibility.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/annotations/SpoofSimCompatibility.kt @@ -5,8 +5,8 @@ import app.revanced.patcher.annotation.Package @Compatibility( [ - Package("com.ss.android.ugc.trill", arrayOf("27.8.3")), - Package("com.zhiliaoapp.musically", arrayOf("27.8.3")) + Package("com.ss.android.ugc.trill", arrayOf("27.8.3", "29.3.4")), + Package("com.zhiliaoapp.musically", arrayOf("27.8.3", "29.3.4")) ] ) @Target(AnnotationTarget.CLASS)