refactor(hide-button-container): rewrite code, and restore previously removed button removal functionality (Experimental Flags)

This commit is contained in:
inotia00 2023-03-28 21:45:24 +09:00
parent 781df4ef8d
commit 49aca64088
5 changed files with 93 additions and 18 deletions

View File

@ -4,14 +4,18 @@ import app.revanced.patcher.annotation.Description
import app.revanced.patcher.annotation.Name
import app.revanced.patcher.annotation.Version
import app.revanced.patcher.data.ResourceContext
import app.revanced.patcher.extensions.addInstructions
import app.revanced.patcher.extensions.instruction
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.ResourcePatch
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.patch.annotations.Patch
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.youtube.misc.litho.patch.LithoFilterPatch
import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
import app.revanced.util.integrations.Constants.BOTTOM_LAYOUT
@Patch
@Name("hide-button-container")
@ -27,6 +31,42 @@ import app.revanced.patches.youtube.misc.settings.resource.patch.SettingsPatch
class ButtonContainerPatch : ResourcePatch {
override fun execute(context: ResourceContext): PatchResult {
val instructionList =
"""
move-object/from16 v3, p2
invoke-static {v3, v10}, $BOTTOM_LAYOUT->hideActionButtons(Ljava/lang/Object;Ljava/nio/ByteBuffer;)Z
move-result v10
if-eqz v10, :do_not_block
move-object/from16 v15, p1
invoke-static {v15}, ${LithoFilterPatch.builderMethodDescriptor}
move-result-object v0
iget-object v0, v0, ${LithoFilterPatch.emptyComponentFieldDescriptor}
return-object v0
"""
with(LithoFilterPatch.lithoMethod) {
if (LithoFilterPatch.bufferFingerprintResolved) {
// 18.11.35+
addInstructions(
0, """
move-object/from16 v10, p3
iget-object v10, v10, ${LithoFilterPatch.objectReference.definingClass}->${LithoFilterPatch.objectReference.name}:${LithoFilterPatch.objectReference.type}
if-eqz v10, :do_not_block
check-cast v10, ${LithoFilterPatch.bufferReference}
iget-object v10, v10, ${LithoFilterPatch.bufferReference}->b:Ljava/nio/ByteBuffer;
""" + instructionList,listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(0)))
)
} else {
val secondParameter = LithoFilterPatch.lithoMethod.parameters[2]
LithoFilterPatch.lithoMethod.addInstructions(
0, """
move-object/from16 v10, p3
iget-object v10, v10, $secondParameter->b:Ljava/nio/ByteBuffer;
""" + instructionList,listOf(ExternalLabel("do_not_block", LithoFilterPatch.lithoMethod.instruction(0)))
)
}
}
/*
* Add settings
*/

View File

@ -9,6 +9,7 @@ import app.revanced.patcher.patch.BytecodePatch
import app.revanced.patcher.patch.PatchResult
import app.revanced.patcher.patch.PatchResultSuccess
import app.revanced.patcher.patch.annotations.DependsOn
import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod
import app.revanced.patcher.util.smali.ExternalLabel
import app.revanced.patches.shared.annotation.YouTubeCompatibility
import app.revanced.patches.shared.fingerprints.LithoBufferFingerprint
@ -27,6 +28,7 @@ import org.jf.dexlib2.iface.instruction.TwoRegisterInstruction
import org.jf.dexlib2.iface.instruction.formats.Instruction31i
import org.jf.dexlib2.iface.reference.FieldReference
import org.jf.dexlib2.iface.reference.MethodReference
import kotlin.properties.Delegates
@DependsOn(
[
@ -62,32 +64,32 @@ class LithoFilterPatch : BytecodePatch(
LithoFingerprint.result?.let { result ->
val endIndex = result.scanResult.patternScanResult!!.endIndex
val method = result.mutableMethod
lithoMethod = result.mutableMethod
with (method.implementation!!.instructions) {
with (lithoMethod.implementation!!.instructions) {
// 18.06.41+
val bufferIndex = indexOfFirst {
it.opcode == Opcode.CONST &&
(it as Instruction31i).narrowLiteral == 168777401
}
val bufferRegister = (method.instruction(bufferIndex) as Instruction31i).registerA
val bufferRegister = (lithoMethod.instruction(bufferIndex) as Instruction31i).registerA
// 18.06.41+
val targetIndex = indexOfFirst {
it.opcode == Opcode.CONST_STRING &&
(it as BuilderInstruction21c).reference.toString() == "Element missing type extension"
} + 2
val builderMethodDescriptor = (elementAt(targetIndex) as ReferenceInstruction).reference as MethodReference
val emptyComponentFieldDescriptor = (elementAt(targetIndex + 2) as ReferenceInstruction).reference as FieldReference
builderMethodDescriptor = (elementAt(targetIndex) as ReferenceInstruction).reference as MethodReference
emptyComponentFieldDescriptor = (elementAt(targetIndex + 2) as ReferenceInstruction).reference as FieldReference
val identifierRegister = (method.instruction(endIndex) as OneRegisterInstruction).registerA
val identifierRegister = (lithoMethod.instruction(endIndex) as OneRegisterInstruction).registerA
filter { instruction ->
val fieldReference = (instruction as? ReferenceInstruction)?.reference as? FieldReference
fieldReference?.let { it.type == "Ljava/lang/StringBuilder;" } == true
}.forEach { instruction ->
val insertIndex = indexOf(instruction)
val stringBuilderRegister = (method.instruction(insertIndex) as TwoRegisterInstruction).registerA
val stringBuilderRegister = (lithoMethod.instruction(insertIndex) as TwoRegisterInstruction).registerA
val instructionList =
"""
@ -107,8 +109,8 @@ class LithoFilterPatch : BytecodePatch(
it.opcode == Opcode.CONST_STRING &&
(it as BuilderInstruction21c).reference.toString() == ""
} - 2
val objectReference = (elementAt(objectIndex) as ReferenceInstruction).reference as FieldReference
method.addInstructions(
objectReference = (elementAt(objectIndex) as ReferenceInstruction).reference as FieldReference
lithoMethod.addInstructions(
insertIndex + 1,
"""
move-object/from16 v$bufferRegister, p3
@ -116,16 +118,16 @@ class LithoFilterPatch : BytecodePatch(
if-eqz v$bufferRegister, :not_an_ad
check-cast v$bufferRegister, $bufferReference
iget-object v$bufferRegister, v$bufferRegister, $bufferReference->b:Ljava/nio/ByteBuffer;
""" + instructionList,listOf(ExternalLabel("not_an_ad", method.instruction(insertIndex + 1)))
""" + instructionList,listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1)))
)
} else {
val secondParameter = method.parameters[2]
method.addInstructions(
val secondParameter = lithoMethod.parameters[2]
lithoMethod.addInstructions(
insertIndex + 1,
"""
move-object/from16 v$bufferRegister, p3
iget-object v$bufferRegister, v$bufferRegister, $secondParameter->b:Ljava/nio/ByteBuffer;
""" + instructionList,listOf(ExternalLabel("not_an_ad", method.instruction(insertIndex + 1)))
""" + instructionList,listOf(ExternalLabel("not_an_ad", lithoMethod.instruction(insertIndex + 1)))
)
}
}
@ -136,10 +138,14 @@ class LithoFilterPatch : BytecodePatch(
return PatchResultSuccess()
}
private companion object {
private var objectRegister: Int = 3
private var bufferFingerprintResolved: Boolean = false
internal companion object {
var objectRegister by Delegates.notNull<Int>()
var bufferFingerprintResolved by Delegates.notNull<Boolean>()
private lateinit var bufferReference: String
lateinit var lithoMethod: MutableMethod
lateinit var bufferReference: String
lateinit var builderMethodDescriptor: MethodReference
lateinit var emptyComponentFieldDescriptor: FieldReference
lateinit var objectReference: FieldReference
}
}

View File

@ -11,6 +11,7 @@ internal object Constants {
const val GENERAL_LAYOUT = "$PATCHES_PATH/layout/GeneralLayoutPatch;"
const val PLAYER_LAYOUT = "$PATCHES_PATH/layout/PlayerLayoutPatch;"
const val FULLSCREEN_LAYOUT = "$PATCHES_PATH/layout/FullscreenLayoutPatch;"
const val BOTTOM_LAYOUT = "$PATCHES_PATH/layout/BottomLayoutPatch;"
const val FLYOUT_PANEL_LAYOUT = "$PATCHES_PATH/layout/FlyoutPanelLayoutPatch;"
const val SEEKBAR_LAYOUT = "$PATCHES_PATH/layout/SeekbarLayoutPatch;"

View File

@ -268,6 +268,8 @@ Is it ready to submit?"</string>
<string name="revanced_hide_action_buttons_summary_off">Action buttons are shown</string>
<string name="revanced_hide_action_buttons_summary_on">Action buttons are hidden</string>
<string name="revanced_hide_action_buttons_title">Hide action buttons</string>
<string name="revanced_hide_action_buttons_warning">"These features are outdated. So, even if a issue exists, there are no plans to fix it.
Please do not report any issues you encounter while using this feature."</string>
<string name="revanced_hide_autoplay_button_summary_off">Autoplay button is shown</string>
<string name="revanced_hide_autoplay_button_summary_on">Autoplay button is hidden</string>
<string name="revanced_hide_autoplay_button_title">Hide autoplay button</string>
@ -280,6 +282,9 @@ Is it ready to submit?"</string>
<string name="revanced_hide_auto_player_popup_panels_summary_off">Auto player popup panels are shown</string>
<string name="revanced_hide_auto_player_popup_panels_summary_on">Auto player popup panels are hidden</string>
<string name="revanced_hide_auto_player_popup_panels_title">Hide auto player popup panels</string>
<string name="revanced_hide_button_create_clip_summary_off">Clip button is shown</string>
<string name="revanced_hide_button_create_clip_summary_on">Clip button is hidden</string>
<string name="revanced_hide_button_create_clip_title">Hide clip button</string>
<string name="revanced_hide_button_dislike_summary_off">Dislike button is shown</string>
<string name="revanced_hide_button_dislike_summary_on">Dislike button is hidden</string>
<string name="revanced_hide_button_dislike_title">Hide dislike button</string>
@ -289,9 +294,24 @@ Is it ready to submit?"</string>
<string name="revanced_hide_button_like_summary_off">Like button is shown</string>
<string name="revanced_hide_button_like_summary_on">Like button is hidden</string>
<string name="revanced_hide_button_like_title">Hide like button</string>
<string name="revanced_hide_button_live_chat_summary_off">Live chat button is shown</string>
<string name="revanced_hide_button_live_chat_summary_on">Live chat button is hidden</string>
<string name="revanced_hide_button_live_chat_title">Hide live chat button</string>
<string name="revanced_hide_button_playlist_summary_off">Playlist button is shown</string>
<string name="revanced_hide_button_playlist_summary_on">Playlist button is hidden</string>
<string name="revanced_hide_button_playlist_title">Hide playlist button</string>
<string name="revanced_hide_button_remix_summary_off">Remix button is shown</string>
<string name="revanced_hide_button_remix_summary_on">Remix button is hidden</string>
<string name="revanced_hide_button_remix_title">Hide remix button</string>
<string name="revanced_hide_button_report_summary_off">Report button is shown</string>
<string name="revanced_hide_button_report_summary_on">Report button is hidden</string>
<string name="revanced_hide_button_report_title">Hide report button</string>
<string name="revanced_hide_button_share_summary_off">Share button is shown</string>
<string name="revanced_hide_button_share_summary_on">Share button is hidden</string>
<string name="revanced_hide_button_share_title">Hide share button</string>
<string name="revanced_hide_button_thanks_summary_off">Thanks button is shown</string>
<string name="revanced_hide_button_thanks_summary_on">Thanks button is hidden</string>
<string name="revanced_hide_button_thanks_title">Hide thanks button</string>
<string name="revanced_hide_captions_button_summary_off">Captions button is shown</string>
<string name="revanced_hide_captions_button_summary_on">Captions button is hidden</string>
<string name="revanced_hide_captions_button_title">Hide captions button</string>

View File

@ -245,7 +245,15 @@
<SwitchPreference android:title="@string/revanced_hide_button_dislike_title" android:key="revanced_hide_button_dislike" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_dislike_summary_on" android:summaryOff="@string/revanced_hide_button_dislike_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_action_buttons_title" android:key="revanced_hide_action_buttons" android:defaultValue="false" android:summaryOn="@string/revanced_hide_action_buttons_summary_on" android:summaryOff="@string/revanced_hide_action_buttons_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_download_title" android:key="revanced_hide_button_download" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_download_summary_on" android:summaryOff="@string/revanced_hide_button_download_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_playlist_title" android:key="revanced_hide_button_playlist" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_playlist_summary_on" android:summaryOff="@string/revanced_hide_button_playlist_summary_off" />SETTINGS: BUTTON_CONTAINER -->
<SwitchPreference android:title="@string/revanced_hide_button_playlist_title" android:key="revanced_hide_button_playlist" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_playlist_summary_on" android:summaryOff="@string/revanced_hide_button_playlist_summary_off" />
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_experimental_flag" />
<SwitchPreference android:title="@string/revanced_hide_button_share_title" android:key="revanced_hide_button_share" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_share_summary_on" android:summaryOff="@string/revanced_hide_button_share_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_live_chat_title" android:key="revanced_hide_button_live_chat" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_live_chat_summary_on" android:summaryOff="@string/revanced_hide_button_live_chat_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_report_title" android:key="revanced_hide_button_report" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_report_summary_on" android:summaryOff="@string/revanced_hide_button_report_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_remix_title" android:key="revanced_hide_button_remix" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_remix_summary_on" android:summaryOff="@string/revanced_hide_button_remix_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_thanks_title" android:key="revanced_hide_button_thanks" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_thanks_summary_on" android:summaryOff="@string/revanced_hide_button_thanks_summary_off" />
<SwitchPreference android:title="@string/revanced_hide_button_create_clip_title" android:key="revanced_hide_button_create_clip" android:defaultValue="false" android:summaryOn="@string/revanced_hide_button_create_clip_summary_on" android:summaryOff="@string/revanced_hide_button_create_clip_summary_off" />
<Preference android:title="@string/dialog_title_warning" android:selectable="false" android:summary="@string/revanced_hide_action_buttons_warning" />SETTINGS: BUTTON_CONTAINER -->
<!-- SETTINGS: COMMENT_COMPONENT_PARENT
<Preference android:title=" " android:selectable="false" android:summary="@string/revanced_comments_title" />SETTINGS: COMMENT_COMPONENT_PARENT -->