From a12c4bb1610234d19b4ac86cd57bb09335566b68 Mon Sep 17 00:00:00 2001 From: KAZI MMT <82371061+kazimmt@users.noreply.github.com> Date: Tue, 30 May 2023 17:42:17 +0600 Subject: [PATCH] feat(tiktok): remove compatibility version constraints (#2306) Co-authored-by: oSumAtrIX --- .../annotations/FeedFilterCompatibility.kt | 4 +- .../annotations/DownloadsCompatibility.kt | 4 +- .../annotations/SettingsCompatibility.kt | 4 +- .../fingerprints/AboutPageFingerprint.kt | 17 ++ .../fingerprints/AboutViewFingerprint.kt | 37 ----- .../misc/settings/patch/SettingsPatch.kt | 147 +++++++++--------- .../sim/annotations/SpoofSimCompatibility.kt | 4 +- 7 files changed, 102 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..64d56b264 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"), + Package("com.zhiliaoapp.musically") ] ) @Target(AnnotationTarget.CLASS) 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..bb2920640 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"), + Package("com.zhiliaoapp.musically") ] ) @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..b139f1328 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"), + Package("com.zhiliaoapp.musically") ] ) @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..7ef0e7575 --- /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, // copyrightPolicyLabel resource id + Opcode.INVOKE_VIRTUAL, + Opcode.MOVE_RESULT_OBJECT, + Opcode.CONST_STRING + ), + customFingerprint = { methodDef, _ -> + methodDef.definingClass == "Lcom/ss/android/ugc/aweme/setting/page/AboutPage;" && + methodDef.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 42cd5a0d5..66b060494 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,7 +8,6 @@ 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 @@ -17,14 +16,14 @@ import app.revanced.patcher.patch.annotations.DependsOn import app.revanced.patcher.patch.annotations.Patch 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.iface.instruction.FiveRegisterInstruction import org.jf.dexlib2.iface.instruction.OneRegisterInstruction import org.jf.dexlib2.iface.instruction.ReferenceInstruction -import org.jf.dexlib2.iface.instruction.formats.Instruction35c -import org.jf.dexlib2.iface.reference.StringReference +import org.jf.dexlib2.iface.instruction.WideLiteralInstruction @Patch @DependsOn([IntegrationsPatch::class]) @@ -34,84 +33,92 @@ import org.jf.dexlib2.iface.reference.StringReference @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) - } - } - // Implement settings screen in `AdPersonalizationActivity` - with(AdPersonalizationActivityOnCreateFingerprint.result!!.mutableMethod) { - for ((index, instruction) in implementation!!.instructions.withIndex()) { - if (instruction.opcode != Opcode.INVOKE_SUPER) continue - val thisRegister = (instruction as Instruction35c).registerC - addInstructions( - index + 1, + SettingsOnViewCreatedFingerprint.result?.mutableMethod?.apply { + val instructions = implementation!!.instructions + + // Find the indices that need to be patched. + val copyrightPolicyLabelId = AboutPageFingerprint.result?.let { + val startIndex = it.scanResult.patternScanResult!!.startIndex + it.mutableMethod.instruction(startIndex).wideLiteral + } ?: return AboutPageFingerprint.toErrorResult() + + val copyrightIndex = instructions.indexOfFirst { + (it as? ReferenceInstruction)?.reference.toString() == "copyright_policy" + } - 6 + + + val copyrightPolicyIndex = instructions.indexOfFirst { + (it as? WideLiteralInstruction)?.wideLiteral == copyrightPolicyLabelId + } + 2 + + // Replace an existing settings entry with ReVanced settings entry. + arrayOf( + copyrightIndex, + copyrightPolicyIndex + ).forEach { index -> + val instruction = instruction(index) + if (instruction.opcode != Opcode.MOVE_RESULT_OBJECT) + return PatchResultError("Hardcoded offset changed.") + + val settingsEntryStringRegister = (instruction as OneRegisterInstruction).registerA + + // Replace the settings entry string with a custom one. + replaceInstruction( + index, """ - invoke-static {v$thisRegister}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->initializeSettings(Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;)V + const-string v$settingsEntryStringRegister, "ReVanced Settings" + """ + ) + + // Replace the OnClickListener class with a custom one. + val onClickListener = instruction(index + 4).reference.toString() + + context.findClass(onClickListener)?.mutableClass?.methods?.first { + it.name == "onClick" + }?.addInstructions( + 0, + """ + invoke-static {}, $INTEGRATIONS_CLASS_DESCRIPTOR->startSettingsActivity()V return-void """ - ) - break + ) ?: return PatchResultError("Could not find the onClick method.") } - } + + } ?: return SettingsOnViewCreatedFingerprint.toErrorResult() + + // Initialize the settings menu once the replaced setting entry is clicked. + AdPersonalizationActivityOnCreateFingerprint.result?.mutableMethod?.apply { + val initializeSettingsIndex = implementation!!.instructions.indexOfFirst { + it.opcode == Opcode.INVOKE_SUPER + } + 1 + + val thisRegister = instruction(initializeSettingsIndex - 1).registerC + + addInstructions( + initializeSettingsIndex, + """ + invoke-static {v$thisRegister}, $INITIALIZE_SETTINGS_METHOD_DESCRIPTOR + return-void + """ + ) + } ?: return AdPersonalizationActivityOnCreateFingerprint.toErrorResult() + return PatchResultSuccess() } - 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 { + private const val INTEGRATIONS_CLASS_DESCRIPTOR = + "Lapp/revanced/tiktok/settingsmenu/SettingsMenu;" - // 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).registerA - replaceInstruction( - index - 4, - """ - const-string v$overrideRegister, "Revanced Settings" - """ - ) - - // Patch option OnClick Event - val type = instruction(index).reference.toString() - context.findClass(type)!!.mutableClass.methods.first { type == "onClick" }.addInstructions( - 0, - """ - invoke-static {}, Lapp/revanced/tiktok/settingsmenu/SettingsMenu;->startSettingsActivity()V - return-void - """ - ) - } + private const val INITIALIZE_SETTINGS_METHOD_DESCRIPTOR = + "$INTEGRATIONS_CLASS_DESCRIPTOR->initializeSettings(" + + "Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;" + + ")V" } } \ No newline at end of file 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..b258cec9a 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"), + Package("com.zhiliaoapp.musically") ] ) @Target(AnnotationTarget.CLASS)