From 72adaf1a8ecd61ed96f7ea4e6882e6adef521eed Mon Sep 17 00:00:00 2001 From: inotia00 <108592928+inotia00@users.noreply.github.com> Date: Thu, 25 Jan 2024 06:56:12 +0900 Subject: [PATCH] chore: lint code --- .../music/account/handle/HideHandlePatch.kt | 36 +++++++++---------- .../utils/browseid/BrowseIdHookPatch.kt | 6 +--- .../SetToolBarPaddingFingerprint.kt | 16 --------- .../utils/resourceid/SharedResourceIdPatch.kt | 2 -- 4 files changed, 18 insertions(+), 42 deletions(-) delete mode 100644 src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/SetToolBarPaddingFingerprint.kt diff --git a/src/main/kotlin/app/revanced/patches/music/account/handle/HideHandlePatch.kt b/src/main/kotlin/app/revanced/patches/music/account/handle/HideHandlePatch.kt index 911db49d7..515ee4cfe 100644 --- a/src/main/kotlin/app/revanced/patches/music/account/handle/HideHandlePatch.kt +++ b/src/main/kotlin/app/revanced/patches/music/account/handle/HideHandlePatch.kt @@ -14,9 +14,10 @@ import app.revanced.patches.music.utils.resourceid.SharedResourceIdPatch import app.revanced.patches.music.utils.settings.CategoryType import app.revanced.patches.music.utils.settings.SettingsPatch import app.revanced.util.exception +import app.revanced.util.getReference +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.instruction.formats.Instruction35c import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -57,27 +58,24 @@ object HideHandlePatch : BytecodePatch( /** * Hide handle in account menu */ - AccountSwitcherAccessibilityLabelFingerprint.result?.let { - it.mutableMethod.apply { - val textColorIndex = implementation!!.instructions.indexOfFirst { instruction -> - ((instruction as? ReferenceInstruction)?.reference as? MethodReference)?.name == "setTextColor" + AccountSwitcherAccessibilityLabelFingerprint.result?.let { result -> + result.mutableMethod.apply { + + val textColorIndex = indexOfFirstInstruction { + getReference()?.name == "setTextColor" } - - for (index in textColorIndex until textColorIndex + 5) { - if (getInstruction(index).opcode != Opcode.INVOKE_VIRTUAL) continue - - if ((getInstruction(index).reference as MethodReference).name == "setVisibility") { - - val textViewInstruction = getInstruction(index) - - replaceInstruction( - index, - "invoke-static {v${textViewInstruction.registerC}, v${textViewInstruction.registerD}}, $ACCOUNT->hideHandle(Landroid/widget/TextView;I)V" - ) - - break + val setTextIndex = implementation!!.instructions.let { + textColorIndex + it.subList(textColorIndex, textColorIndex + 10).indexOfFirst { instruction -> + instruction.opcode == Opcode.INVOKE_VIRTUAL + && instruction.getReference()?.name == "setVisibility" } } + val textViewInstruction = getInstruction(setTextIndex) + + replaceInstruction( + setTextIndex, + "invoke-static {v${textViewInstruction.registerC}, v${textViewInstruction.registerD}}, $ACCOUNT->hideHandle(Landroid/widget/TextView;I)V" + ) } } ?: throw AccountSwitcherAccessibilityLabelFingerprint.exception diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt index bdf116d9e..63273d6e2 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/BrowseIdHookPatch.kt @@ -9,7 +9,6 @@ import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.annotation.Patch import app.revanced.patches.shared.patch.litho.ComponentParserPatch import app.revanced.patches.youtube.utils.browseid.fingerprints.BrowseIdClassFingerprint -import app.revanced.patches.youtube.utils.browseid.fingerprints.SetToolBarPaddingFingerprint import app.revanced.patches.youtube.utils.integrations.Constants.UTILS_PATH import app.revanced.patches.youtube.utils.litho.LithoFilterPatch import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch @@ -26,10 +25,7 @@ import com.android.tools.smali.dexlib2.iface.reference.FieldReference ] ) object BrowseIdHookPatch : BytecodePatch( - setOf( - BrowseIdClassFingerprint, - SetToolBarPaddingFingerprint - ) + setOf(BrowseIdClassFingerprint) ) { private const val INTEGRATIONS_CLASS_DESCRIPTOR = "$UTILS_PATH/BrowseIdPatch;" diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/SetToolBarPaddingFingerprint.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/SetToolBarPaddingFingerprint.kt deleted file mode 100644 index 81061cef0..000000000 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/browseid/fingerprints/SetToolBarPaddingFingerprint.kt +++ /dev/null @@ -1,16 +0,0 @@ -package app.revanced.patches.youtube.utils.browseid.fingerprints - -import app.revanced.patches.youtube.utils.resourceid.SharedResourceIdPatch.ToolBarPaddingHome -import app.revanced.util.fingerprint.LiteralValueFingerprint -import com.android.tools.smali.dexlib2.Opcode - -object SetToolBarPaddingFingerprint : LiteralValueFingerprint( - returnType = "V", - parameters = listOf("I", "I"), - opcodes = listOf( - Opcode.INVOKE_VIRTUAL, - Opcode.IGET_OBJECT, - Opcode.INVOKE_STATIC - ), - literalSupplier = { ToolBarPaddingHome } -) \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt index 5ded1a224..8a91c065c 100644 --- a/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt +++ b/src/main/kotlin/app/revanced/patches/youtube/utils/resourceid/SharedResourceIdPatch.kt @@ -78,7 +78,6 @@ object SharedResourceIdPatch : ResourcePatch() { var SubtitleMenuSettingsFooterInfo: Long = -1 var SuggestedAction: Long = -1 var TabsBarTextTabView: Long = -1 - var ToolBarPaddingHome: Long = -1 var ToolTipContentView: Long = -1 var TotalTime: Long = -1 var VideoQualityBottomSheet: Long = -1 @@ -162,7 +161,6 @@ object SharedResourceIdPatch : ResourcePatch() { SubtitleMenuSettingsFooterInfo = find(STRING, "subtitle_menu_settings_footer_info") SuggestedAction = find(LAYOUT, "suggested_action") TabsBarTextTabView = find(ID, "tabs_bar_text_tab_view") - ToolBarPaddingHome = find(DIMEN, "toolbar_padding_home_action_up") ToolTipContentView = find(LAYOUT, "tooltip_content_view") TotalTime = find(STRING, "total_time") VideoQualityBottomSheet = find(LAYOUT, "video_quality_bottom_sheet_list_fragment_title")