From 7f6d6f890c02d2fba6c7133108165e70b7697690 Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Sun, 17 Dec 2023 23:13:04 +0700 Subject: [PATCH 1/9] feat(Tiktok-ClearMode): Retains the clear mode configurations in between videos. --- api/revanced-patches.api | 6 ++ .../interaction/clearmode/ClearModePatch.kt | 61 +++++++++++++++++++ .../OnClearModeEventFingerprint.kt | 12 ++++ .../OnRenderFirstFrameFingerprint.kt | 10 +++ 4 files changed, 89 insertions(+) create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt create mode 100644 src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 50d757f7f7..8528d41293 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -818,6 +818,12 @@ public final class app/revanced/patches/tiktok/feedfilter/FeedFilterPatch : app/ public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } +public final class app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/clearmode/ClearModePatch; + 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/interaction/downloads/DownloadsPatch : app/revanced/patcher/patch/BytecodePatch { public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/downloads/DownloadsPatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt new file mode 100644 index 0000000000..85494ed44f --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt @@ -0,0 +1,61 @@ +package app.revanced.patches.tiktok.interaction.clearmode + +import app.revanced.patcher.data.BytecodeContext +import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +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.interaction.clearmode.fingerprints.OnClearModeEventFingerprint +import app.revanced.patches.tiktok.share.fingerprints.OnRenderFirstFrameFingerprint +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.formats.Instruction22c + +@Patch( + name = "Clear mode", + description = "Retains the clear mode configurations in between videos.", + compatiblePackages = [ + CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]), + CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"]) + ] +) +@Suppress("unused") +object ClearModePatch : BytecodePatch( + setOf( + OnClearModeEventFingerprint, + OnRenderFirstFrameFingerprint + ) +) { + override fun execute(context: BytecodeContext) { + OnClearModeEventFingerprint.result?.mutableMethod?.apply { + val injectIndex = indexOfFirstInstruction { + opcode == Opcode.IGET_BOOLEAN + } + 1 + val reg = (getInstruction(injectIndex - 1) as Instruction22c).registerA + addInstructions( + injectIndex, + """ + invoke-static { v$reg }, Lapp/revanced/tiktok/clearmode/ClearModePatch;->saveClearModeState(Z)V + """ + ) + + val clearModeEventClass = parameters[0].type + OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { + addInstructions( + 0, + """ + new-instance v0, $clearModeEventClass + const/4 v1, 0x0 + const-string v2, "long_press" + invoke-static {}, Lapp/revanced/tiktok/clearmode/ClearModePatch;->getClearModeState()Z + move-result v3 + invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V + invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + """ + ) + } ?: throw OnRenderFirstFrameFingerprint.exception + } ?: throw OnClearModeEventFingerprint.exception + } +} \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt new file mode 100644 index 0000000000..d72c274113 --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt @@ -0,0 +1,12 @@ +package app.revanced.patches.tiktok.interaction.clearmode.fingerprints + +import app.revanced.patcher.extensions.or +import app.revanced.patcher.fingerprint.MethodFingerprint +import com.android.tools.smali.dexlib2.AccessFlags + +internal object OnClearModeEventFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/ClearModePanelComponent;") && + methodDef.name == "onClearModeEvent" + } +) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt new file mode 100644 index 0000000000..016a047e7e --- /dev/null +++ b/src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt @@ -0,0 +1,10 @@ +package app.revanced.patches.tiktok.share.fingerprints + +import app.revanced.patcher.fingerprint.MethodFingerprint + +internal object OnRenderFirstFrameFingerprint : MethodFingerprint( + customFingerprint = { methodDef, _ -> + methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && + methodDef.name == "onRenderFirstFrame" + } +) \ No newline at end of file From 06c9701af7d27be86f340d8beeee46ca0b9c9ca3 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 17 Dec 2023 20:40:10 +0100 Subject: [PATCH 2/9] refactor --- .../interaction/clearmode/ClearModePatch.kt | 51 +++++++++---------- .../OnClearModeEventFingerprint.kt | 5 +- .../OnRenderFirstFrameFingerprint.kt | 5 +- 3 files changed, 28 insertions(+), 33 deletions(-) rename src/main/kotlin/app/revanced/patches/tiktok/{share => interaction/clearmode}/fingerprints/OnRenderFirstFrameFingerprint.kt (67%) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt index 85494ed44f..9108ba8b86 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt @@ -7,7 +7,7 @@ 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.interaction.clearmode.fingerprints.OnClearModeEventFingerprint -import app.revanced.patches.tiktok.share.fingerprints.OnRenderFirstFrameFingerprint +import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnRenderFirstFrameFingerprint import app.revanced.util.exception import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.Opcode @@ -29,33 +29,32 @@ object ClearModePatch : BytecodePatch( ) ) { override fun execute(context: BytecodeContext) { - OnClearModeEventFingerprint.result?.mutableMethod?.apply { - val injectIndex = indexOfFirstInstruction { - opcode == Opcode.IGET_BOOLEAN - } + 1 - val reg = (getInstruction(injectIndex - 1) as Instruction22c).registerA - addInstructions( - injectIndex, - """ - invoke-static { v$reg }, Lapp/revanced/tiktok/clearmode/ClearModePatch;->saveClearModeState(Z)V - """ - ) + OnClearModeEventFingerprint.result?.mutableMethod?.let { + + it.apply { + val injectIndex = indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 + val register = getInstruction(injectIndex - 1).registerA - val clearModeEventClass = parameters[0].type - OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { addInstructions( - 0, - """ - new-instance v0, $clearModeEventClass - const/4 v1, 0x0 - const-string v2, "long_press" - invoke-static {}, Lapp/revanced/tiktok/clearmode/ClearModePatch;->getClearModeState()Z - move-result v3 - invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V - invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; - """ + injectIndex, + "invoke-static { v$register }, " + + "Lapp/revanced/tiktok/clearmode/ClearModePatch;->saveClearModeState(Z)V" ) - } ?: throw OnRenderFirstFrameFingerprint.exception + } + + val clearModeEventClass = it.parameters[0].type + OnRenderFirstFrameFingerprint.result?.mutableMethod?.addInstructions( + 0, + """ + new-instance v0, $clearModeEventClass + const/4 v1, 0x0 + const-string v2, "long_press" + invoke-static {}, Lapp/revanced/tiktok/clearmode/ClearModePatch;->getClearModeState()Z + move-result v3 + invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V + invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + """ + ) ?: throw OnRenderFirstFrameFingerprint.exception } ?: throw OnClearModeEventFingerprint.exception } -} \ No newline at end of file +} diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt index d72c274113..f1ade3128b 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt @@ -1,12 +1,9 @@ package app.revanced.patches.tiktok.interaction.clearmode.fingerprints -import app.revanced.patcher.extensions.or import app.revanced.patcher.fingerprint.MethodFingerprint -import com.android.tools.smali.dexlib2.AccessFlags internal object OnClearModeEventFingerprint : MethodFingerprint( customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("/ClearModePanelComponent;") && - methodDef.name == "onClearModeEvent" + methodDef.definingClass.endsWith("/ClearModePanelComponent;") && methodDef.name == "onClearModeEvent" } ) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt similarity index 67% rename from src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt index 016a047e7e..e239229150 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/share/fingerprints/OnRenderFirstFrameFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt @@ -1,10 +1,9 @@ -package app.revanced.patches.tiktok.share.fingerprints +package app.revanced.patches.tiktok.interaction.clearmode.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint internal object OnRenderFirstFrameFingerprint : MethodFingerprint( customFingerprint = { methodDef, _ -> - methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && - methodDef.name == "onRenderFirstFrame" + methodDef.definingClass.endsWith("/BaseListFragmentPanel;") && methodDef.name == "onRenderFirstFrame" } ) \ No newline at end of file From ca016d6050056c765a6d619809d74784d5827e11 Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Mon, 18 Dec 2023 06:06:35 +0700 Subject: [PATCH 3/9] refactor: rename base on change request --- api/revanced-patches.api | 4 ++-- .../{ClearModePatch.kt => RememberClearModePatch.kt} | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/{ClearModePatch.kt => RememberClearModePatch.kt} (88%) diff --git a/api/revanced-patches.api b/api/revanced-patches.api index 8528d41293..792ed855a0 100644 --- a/api/revanced-patches.api +++ b/api/revanced-patches.api @@ -818,8 +818,8 @@ public final class app/revanced/patches/tiktok/feedfilter/FeedFilterPatch : app/ public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } -public final class app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch : app/revanced/patcher/patch/BytecodePatch { - public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/clearmode/ClearModePatch; +public final class app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch : app/revanced/patcher/patch/BytecodePatch { + public static final field INSTANCE Lapp/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch; public fun execute (Lapp/revanced/patcher/data/BytecodeContext;)V public synthetic fun execute (Lapp/revanced/patcher/data/Context;)V } diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt similarity index 88% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index 9108ba8b86..2e4d7550f0 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/ClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -14,15 +14,15 @@ import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c @Patch( - name = "Clear mode", - description = "Retains the clear mode configurations in between videos.", + name = "Clear display", + description = "Retains the clear display configurations in between videos.", compatiblePackages = [ CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]), CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"]) ] ) @Suppress("unused") -object ClearModePatch : BytecodePatch( +object RememberClearModePatch : BytecodePatch( setOf( OnClearModeEventFingerprint, OnRenderFirstFrameFingerprint @@ -38,7 +38,7 @@ object ClearModePatch : BytecodePatch( addInstructions( injectIndex, "invoke-static { v$register }, " + - "Lapp/revanced/tiktok/clearmode/ClearModePatch;->saveClearModeState(Z)V" + "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V" ) } @@ -49,7 +49,7 @@ object ClearModePatch : BytecodePatch( new-instance v0, $clearModeEventClass const/4 v1, 0x0 const-string v2, "long_press" - invoke-static {}, Lapp/revanced/tiktok/clearmode/ClearModePatch;->getClearModeState()Z + invoke-static {}, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z move-result v3 invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; From 0e32090ae00ccc419235fa8e7ef5b308ee195d0a Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Mon, 18 Dec 2023 06:07:47 +0700 Subject: [PATCH 4/9] refactor --- .../tiktok/interaction/clearmode/RememberClearModePatch.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index 2e4d7550f0..34b98bd0c3 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -15,7 +15,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c @Patch( name = "Clear display", - description = "Retains the clear display configurations in between videos.", + description = "Remembers the clear display configurations in between videos.", compatiblePackages = [ CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]), CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"]) From 5044a86f703997dd9bf803d44689c7b2d8fcb4b5 Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Mon, 18 Dec 2023 06:27:09 +0700 Subject: [PATCH 5/9] chore: add comments --- .../interaction/clearmode/RememberClearModePatch.kt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index 34b98bd0c3..255f9d4b21 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -31,6 +31,8 @@ object RememberClearModePatch : BytecodePatch( override fun execute(context: BytecodeContext) { OnClearModeEventFingerprint.result?.mutableMethod?.let { + // Catches the clear mode configuration changed event and saved that configuration + // to apply to other videos. it.apply { val injectIndex = indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 val register = getInstruction(injectIndex - 1).registerA @@ -42,13 +44,21 @@ object RememberClearModePatch : BytecodePatch( ) } + // Changes the clear mode configuration on the first frame of video. + // Because the default behavior of TikTok is turn off clear mode when swiping to next video. val clearModeEventClass = it.parameters[0].type OnRenderFirstFrameFingerprint.result?.mutableMethod?.addInstructions( 0, """ + # These instructions will create a clearModeEvent which will be posted to notify other + # app components. TikTok use https://github.com/greenrobot/EventBus + # To create a new clearModeEvent we need 3 arguments + # First is a Integer which present the type of clear mode such as 0 = LONG_PRESS, 1 = SCREEN_RECORD,... new-instance v0, $clearModeEventClass const/4 v1, 0x0 + # Second is a String which is similar to the first but as String. const-string v2, "long_press" + # Third is a Boolean which is the state of clear mode. invoke-static {}, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z move-result v3 invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V From bef4449d459cc2d1b5415236485957e8d5b592a8 Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Mon, 18 Dec 2023 07:07:12 +0700 Subject: [PATCH 6/9] fix: do not post event if clear mode not set. --- .../clearmode/RememberClearModePatch.kt | 42 +++++++++++-------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index 255f9d4b21..da0b93e1bc 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -2,10 +2,12 @@ package app.revanced.patches.tiktok.interaction.clearmode import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions +import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch +import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnClearModeEventFingerprint import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnRenderFirstFrameFingerprint import app.revanced.util.exception @@ -47,24 +49,28 @@ object RememberClearModePatch : BytecodePatch( // Changes the clear mode configuration on the first frame of video. // Because the default behavior of TikTok is turn off clear mode when swiping to next video. val clearModeEventClass = it.parameters[0].type - OnRenderFirstFrameFingerprint.result?.mutableMethod?.addInstructions( - 0, - """ - # These instructions will create a clearModeEvent which will be posted to notify other - # app components. TikTok use https://github.com/greenrobot/EventBus - # To create a new clearModeEvent we need 3 arguments - # First is a Integer which present the type of clear mode such as 0 = LONG_PRESS, 1 = SCREEN_RECORD,... - new-instance v0, $clearModeEventClass - const/4 v1, 0x0 - # Second is a String which is similar to the first but as String. - const-string v2, "long_press" - # Third is a Boolean which is the state of clear mode. - invoke-static {}, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z - move-result v3 - invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V - invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; - """ - ) ?: throw OnRenderFirstFrameFingerprint.exception + OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { + addInstructionsWithLabels( + 0, + """ + # These instructions will create a clearModeEvent which will be posted to notify other + # app components. TikTok use https://github.com/greenrobot/EventBus + # To create a new clearModeEvent we need 3 arguments + # Third is a Boolean which is the state of clear mode. + invoke-static {}, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z + move-result v3 + if-eqz v3, :not_post_event + # First is a Integer which present the type of clear mode such as 0 = LONG_PRESS, 1 = SCREEN_RECORD,... + new-instance v0, $clearModeEventClass + const/4 v1, 0x0 + # Second is a String which is similar to the first but as String. + const-string v2, "long_press" + invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V + invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + """, + ExternalLabel("not_post_event", getInstruction(0)) + ) + } ?: throw OnRenderFirstFrameFingerprint.exception } ?: throw OnClearModeEventFingerprint.exception } } From f8e4bbdfa6c45ea0c1ba2ef2d99b3544767563b2 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 19 Dec 2023 18:59:51 +0100 Subject: [PATCH 7/9] refactor: Improve code comments --- .../clearmode/RememberClearModePatch.kt | 53 ++++++++++--------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index da0b93e1bc..3b9bfed5aa 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -32,45 +32,48 @@ object RememberClearModePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { OnClearModeEventFingerprint.result?.mutableMethod?.let { + // region Hook the "Clear mode" configuration save event to remember the state of clear mode. - // Catches the clear mode configuration changed event and saved that configuration - // to apply to other videos. - it.apply { - val injectIndex = indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 - val register = getInstruction(injectIndex - 1).registerA + val isEnabledIndex = it.indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 + val isEnabledRegister = it.getInstruction(isEnabledIndex - 1).registerA - addInstructions( - injectIndex, - "invoke-static { v$register }, " + - "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V" - ) - } + it.addInstructions( + isEnabledIndex, + "invoke-static { v$isEnabledRegister }, " + + "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V" + ) + + // endregion + + // region Override the "Clear mode" configuration load event to load the state of clear mode. - // Changes the clear mode configuration on the first frame of video. - // Because the default behavior of TikTok is turn off clear mode when swiping to next video. val clearModeEventClass = it.parameters[0].type OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { addInstructionsWithLabels( 0, """ - # These instructions will create a clearModeEvent which will be posted to notify other - # app components. TikTok use https://github.com/greenrobot/EventBus - # To create a new clearModeEvent we need 3 arguments - # Third is a Boolean which is the state of clear mode. - invoke-static {}, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z + # Create a new clearModeEvent and post it to the EventBus (https://github.com/greenrobot/EventBus) + + # The state of clear mode. + invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z move-result v3 - if-eqz v3, :not_post_event - # First is a Integer which present the type of clear mode such as 0 = LONG_PRESS, 1 = SCREEN_RECORD,... - new-instance v0, $clearModeEventClass + if-eqz v3, :clear_mode_disabled + + # Clear mode type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. const/4 v1, 0x0 - # Second is a String which is similar to the first but as String. + + # Name of the clear mode type which is equivalent to the clear mode type. const-string v2, "long_press" - invoke-direct {v0, v1, v2, v3}, $clearModeEventClass->(ILjava/lang/String;Z)V - invoke-virtual {v0}, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + + new-instance v0, $clearModeEventClass + invoke-direct { v0, v1, v2, v3 }, $clearModeEventClass->(ILjava/lang/String;Z)V + invoke-virtual { v0 }, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; """, - ExternalLabel("not_post_event", getInstruction(0)) + ExternalLabel("clear_mode_disabled", getInstruction(0)) ) } ?: throw OnRenderFirstFrameFingerprint.exception + + // endregion } ?: throw OnClearModeEventFingerprint.exception } } From d8561414601801a4bb306aec6febfa81ed231ae8 Mon Sep 17 00:00:00 2001 From: d4rkk3y Date: Wed, 20 Dec 2023 04:28:05 +0700 Subject: [PATCH 8/9] refactor: rename `clear mode` to `clear display` --- .../RememberClearDisplayPatch.kt} | 36 +++++++++---------- .../OnClearModeEventFingerprint.kt | 2 +- .../OnRenderFirstFrameFingerprint.kt | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{clearmode/RememberClearModePatch.kt => cleardisplay/RememberClearDisplayPatch.kt} (61%) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{clearmode => cleardisplay}/fingerprints/OnClearModeEventFingerprint.kt (79%) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{clearmode => cleardisplay}/fingerprints/OnRenderFirstFrameFingerprint.kt (79%) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt similarity index 61% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt index 3b9bfed5aa..0ab605bfd6 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.clearmode +package app.revanced.patches.tiktok.interaction.cleardisplay import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions @@ -8,8 +8,8 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnClearModeEventFingerprint -import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnRenderFirstFrameFingerprint +import app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints.OnClearModeEventFingerprint +import app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints.OnRenderFirstFrameFingerprint import app.revanced.util.exception import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.Opcode @@ -24,7 +24,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction22c ] ) @Suppress("unused") -object RememberClearModePatch : BytecodePatch( +object RememberClearDisplayPatch : BytecodePatch( setOf( OnClearModeEventFingerprint, OnRenderFirstFrameFingerprint @@ -32,7 +32,7 @@ object RememberClearModePatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { OnClearModeEventFingerprint.result?.mutableMethod?.let { - // region Hook the "Clear mode" configuration save event to remember the state of clear mode. + // region Hook the "Clear display" configuration save event to remember the state of clear display. val isEnabledIndex = it.indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 val isEnabledRegister = it.getInstruction(isEnabledIndex - 1).registerA @@ -40,36 +40,36 @@ object RememberClearModePatch : BytecodePatch( it.addInstructions( isEnabledIndex, "invoke-static { v$isEnabledRegister }, " + - "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V" + "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearDisplayState(Z)V" ) // endregion - // region Override the "Clear mode" configuration load event to load the state of clear mode. + // region Override the "Clear display" configuration load event to load the state of clear display. - val clearModeEventClass = it.parameters[0].type + val clearDisplayEventClass = it.parameters[0].type OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { addInstructionsWithLabels( 0, """ - # Create a new clearModeEvent and post it to the EventBus (https://github.com/greenrobot/EventBus) + # Create a new clearDisplayEvent and post it to the EventBus (https://github.com/greenrobot/EventBus) - # The state of clear mode. - invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z + # The state of clear display. + invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearDisplayState()Z move-result v3 - if-eqz v3, :clear_mode_disabled + if-eqz v3, :clear_display_disabled - # Clear mode type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. + # Clear display type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. const/4 v1, 0x0 - # Name of the clear mode type which is equivalent to the clear mode type. + # Name of the clear display type which is equivalent to the clear display type. const-string v2, "long_press" - new-instance v0, $clearModeEventClass - invoke-direct { v0, v1, v2, v3 }, $clearModeEventClass->(ILjava/lang/String;Z)V - invoke-virtual { v0 }, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + new-instance v0, $clearDisplayEventClass + invoke-direct { v0, v1, v2, v3 }, $clearDisplayEventClass->(ILjava/lang/String;Z)V + invoke-virtual { v0 }, $clearDisplayEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; """, - ExternalLabel("clear_mode_disabled", getInstruction(0)) + ExternalLabel("clear_display_disabled", getInstruction(0)) ) } ?: throw OnRenderFirstFrameFingerprint.exception diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt index f1ade3128b..405da882b6 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.clearmode.fingerprints +package app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt index e239229150..d9e5a15ed0 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.clearmode.fingerprints +package app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint From 8f6553699f2bd3f2d2780b9d53d3e10c023987bd Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Thu, 21 Dec 2023 15:19:58 +0100 Subject: [PATCH 9/9] fix: Name the patch correctly --- .../RememberClearModePatch.kt} | 40 +++++++++---------- .../OnClearModeEventFingerprint.kt | 2 +- .../OnRenderFirstFrameFingerprint.kt | 2 +- 3 files changed, 22 insertions(+), 22 deletions(-) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{cleardisplay/RememberClearDisplayPatch.kt => clearmode/RememberClearModePatch.kt} (58%) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{cleardisplay => clearmode}/fingerprints/OnClearModeEventFingerprint.kt (79%) rename src/main/kotlin/app/revanced/patches/tiktok/interaction/{cleardisplay => clearmode}/fingerprints/OnRenderFirstFrameFingerprint.kt (79%) diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt similarity index 58% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt index 0ab605bfd6..ac8ad6ccac 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/RememberClearModePatch.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.cleardisplay +package app.revanced.patches.tiktok.interaction.clearmode import app.revanced.patcher.data.BytecodeContext import app.revanced.patcher.extensions.InstructionExtensions.addInstructions @@ -8,23 +8,23 @@ import app.revanced.patcher.patch.BytecodePatch import app.revanced.patcher.patch.annotation.CompatiblePackage import app.revanced.patcher.patch.annotation.Patch import app.revanced.patcher.util.smali.ExternalLabel -import app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints.OnClearModeEventFingerprint -import app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints.OnRenderFirstFrameFingerprint +import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnClearModeEventFingerprint +import app.revanced.patches.tiktok.interaction.clearmode.fingerprints.OnRenderFirstFrameFingerprint 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.formats.Instruction22c @Patch( - name = "Clear display", - description = "Remembers the clear display configurations in between videos.", + name = "Remember clear mode", + description = "Remembers the clear mode configurations in between videos.", compatiblePackages = [ CompatiblePackage("com.ss.android.ugc.trill", ["32.5.3"]), CompatiblePackage("com.zhiliaoapp.musically", ["32.5.3"]) ] ) @Suppress("unused") -object RememberClearDisplayPatch : BytecodePatch( +object RememberClearModePatch : BytecodePatch( setOf( OnClearModeEventFingerprint, OnRenderFirstFrameFingerprint @@ -32,7 +32,7 @@ object RememberClearDisplayPatch : BytecodePatch( ) { override fun execute(context: BytecodeContext) { OnClearModeEventFingerprint.result?.mutableMethod?.let { - // region Hook the "Clear display" configuration save event to remember the state of clear display. + // region Hook the "Clear mode" configuration save event to remember the state of clear mode. val isEnabledIndex = it.indexOfFirstInstruction { opcode == Opcode.IGET_BOOLEAN } + 1 val isEnabledRegister = it.getInstruction(isEnabledIndex - 1).registerA @@ -40,36 +40,36 @@ object RememberClearDisplayPatch : BytecodePatch( it.addInstructions( isEnabledIndex, "invoke-static { v$isEnabledRegister }, " + - "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearDisplayState(Z)V" + "Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->rememberClearModeState(Z)V" ) // endregion - // region Override the "Clear display" configuration load event to load the state of clear display. + // region Override the "Clear mode" configuration load event to load the state of clear mode. - val clearDisplayEventClass = it.parameters[0].type + val clearModeEventClass = it.parameters[0].type OnRenderFirstFrameFingerprint.result?.mutableMethod?.apply { addInstructionsWithLabels( 0, """ - # Create a new clearDisplayEvent and post it to the EventBus (https://github.com/greenrobot/EventBus) + # Create a new clearModeEvent and post it to the EventBus (https://github.com/greenrobot/EventBus) - # The state of clear display. - invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearDisplayState()Z + # The state of clear mode. + invoke-static { }, Lapp/revanced/tiktok/clearmode/RememberClearModePatch;->getClearModeState()Z move-result v3 - if-eqz v3, :clear_display_disabled + if-eqz v3, :clear_mode_disabled - # Clear display type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. + # Clear mode type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. const/4 v1, 0x0 - # Name of the clear display type which is equivalent to the clear display type. + # Name of the clear mode type which is equivalent to the clear mode type. const-string v2, "long_press" - new-instance v0, $clearDisplayEventClass - invoke-direct { v0, v1, v2, v3 }, $clearDisplayEventClass->(ILjava/lang/String;Z)V - invoke-virtual { v0 }, $clearDisplayEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + new-instance v0, $clearModeEventClass + invoke-direct { v0, v1, v2, v3 }, $clearModeEventClass->(ILjava/lang/String;Z)V + invoke-virtual { v0 }, $clearModeEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; """, - ExternalLabel("clear_display_disabled", getInstruction(0)) + ExternalLabel("clear_mode_disabled", getInstruction(0)) ) } ?: throw OnRenderFirstFrameFingerprint.exception diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt index 405da882b6..f1ade3128b 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnClearModeEventFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnClearModeEventFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints +package app.revanced.patches.tiktok.interaction.clearmode.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint diff --git a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt similarity index 79% rename from src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt rename to src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt index d9e5a15ed0..e239229150 100644 --- a/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/fingerprints/OnRenderFirstFrameFingerprint.kt +++ b/src/main/kotlin/app/revanced/patches/tiktok/interaction/clearmode/fingerprints/OnRenderFirstFrameFingerprint.kt @@ -1,4 +1,4 @@ -package app.revanced.patches.tiktok.interaction.cleardisplay.fingerprints +package app.revanced.patches.tiktok.interaction.clearmode.fingerprints import app.revanced.patcher.fingerprint.MethodFingerprint