From 8da05ab46d77b143b5cbf4c2eb870048c3d91cd4 Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Tue, 5 Nov 2024 19:28:51 +0100 Subject: [PATCH] build: Bump ReVanced Patcher (#3862) Co-authored-by: Ushie --- gradle/libs.versions.toml | 4 +- patches/api/patches.api | 24 +--- patches/build.gradle.kts | 6 + .../exportall/ExportAllActivitiesPatch.kt | 4 +- .../debugging/EnableAndroidDebuggingPatch.kt | 4 +- .../gestures/PredictiveBackGesturePatch.kt | 4 +- .../OverrideCertificatePinningPatch.kt | 8 +- .../packagename/ChangePackageNamePatch.kt | 6 +- .../all/misc/resources/AddResourcesPatch.kt | 19 ++- .../RemoveScreenCaptureRestrictionPatch.kt | 4 +- .../sharetargets/RemoveShareTargetsPatch.kt | 4 +- .../TransformInstructionsPatch.kt | 13 +- .../versioncode/ChangeVersionCodePatch.kt | 4 +- .../patches/amazon/DeepLinkingPatch.kt | 4 +- .../backdrops/misc/pro/ProUnlockPatch.kt | 8 +- .../limitations/RemovePlayLimitsPatch.kt | 4 +- .../root/BypassRootChecksPatch.kt | 4 +- .../patches/duolingo/ad/DisableAdsPatch.kt | 6 +- .../duolingo/debug/EnableDebugMenuPatch.kt | 6 +- .../ads/mainfeed/HideSponsoredStoriesPatch.kt | 37 +++-- .../facebook/ads/story/HideStoryAdsPatch.kt | 10 +- .../bootloader/BootloaderDetectionPatch.kt | 7 +- .../detection/root/RootDetectionPatch.kt | 4 +- .../customtabs/EnableCustomTabsPatch.kt | 7 +- .../misc/features/SpoofFeaturesPatch.kt | 4 +- ...oreHiddenBackUpWhileChargingTogglePatch.kt | 7 +- .../restrictions/RemoveDeviceRestrictions.kt | 7 +- .../patches/hexeditor/ad/DisableAdsPatch.kt | 4 +- .../iconpackstudio/misc/pro/UnlockProPatch.kt | 4 +- .../detection/root/RootDetectionPatch.kt | 10 +- .../signature/SpoofSignaturePatch.kt | 4 +- .../patches/inshorts/ad/InshortsAdsPatch.kt | 4 +- .../patches/instagram/ads/HideAdsPatch.kt | 4 +- .../patches/irplus/ad/RemoveAdsPatch.kt | 4 +- .../misc/login/DisableMandatoryLoginPatch.kt | 4 +- .../misc/premium/UnlockPremiumPatch.kt | 4 +- .../license/LicenseValidationPatch.kt | 3 +- .../signature/SignatureVerificationPatch.kt | 3 +- .../misc/pro/UnlockProVersionPatch.kt | 4 +- .../messenger/inbox/HideInboxAdsPatch.kt | 4 +- .../messenger/inbox/HideInboxSubtabsPatch.kt | 4 +- .../DisableSwitchingEmojiToStickerPatch.kt | 8 +- .../inputfield/DisableTypingIndicatorPatch.kt | 4 +- .../messenger/inputfield/Fingerprints.kt | 2 +- .../misc/locale/ForceEnglishLocalePatch.kt | 10 +- .../mifitness/misc/login/FixLoginPatch.kt | 4 +- .../patches/music/ad/video/HideVideoAds.kt | 13 +- .../EnableExclusiveAudioPlayback.kt | 4 +- .../permanentrepeat/PermanentRepeatPatch.kt | 7 +- .../permanentshuffle/PermanentShufflePatch.kt | 4 +- .../layout/compactheader/HideCategoryBar.kt | 6 +- .../layout/premium/HideGetPremiumPatch.kt | 9 +- .../upgradebutton/RemoveUpgradeButtonPatch.kt | 8 +- .../BypassCertificateChecksPatch.kt | 10 +- .../BackgroundPlaybackPatch.kt | 7 +- .../myexpenses/misc/pro/UnlockProPatch.kt | 4 +- .../patches/myfitnesspal/ads/HideAdsPatch.kt | 7 +- .../RemoveBroadcastsRestrictionPatch.kt | 4 +- .../nfctoolsse/misc/pro/UnlockProPatch.kt | 4 +- .../patches/nyx/misc/pro/UnlockProPatch.kt | 4 +- .../misc/fix/crash/FixCrashPatch.kt | 8 +- .../detection/deviceid/SpoofDeviceIdPatch.kt | 4 +- .../signature/SignatureDetectionPatch.kt | 14 +- .../misc/annoyances/HideUpdatePopupPatch.kt | 4 +- .../unlock/bookpoint/EnableBookpointPatch.kt | 3 +- .../misc/unlock/plus/UnlockPlusPatch.kt | 4 +- .../misc/SpoofAndroidDeviceIdPatch.kt | 4 +- .../tracking/DisableTrackingPatch.kt | 10 +- .../patches/pixiv/ads/HideAdsPatch.kt | 4 +- .../HidePurchaseReminderPatch.kt | 4 +- .../reddit/ad/banner/HideBannerPatch.kt | 4 +- .../reddit/ad/comments/HideCommentAdsPatch.kt | 3 +- .../patches/reddit/ad/general/HideAdsPatch.kt | 10 +- .../baconreader/api/SpoofClientPatch.kt | 13 +- .../boostforreddit/ads/DisableAdsPatch.kt | 7 +- .../boostforreddit/api/SpoofClientPatch.kt | 7 +- .../FixAudioMissingInDownloadsPatch.kt | 6 +- .../fix/slink/FixSLinksPatch.kt | 7 +- .../infinityforreddit/api/SpoofClientPatch.kt | 4 +- .../subscription/UnlockSubscriptionPatch.kt | 8 +- .../joeyforreddit/ads/DisableAdsPatch.kt | 4 +- .../joeyforreddit/api/SpoofClientPatch.kt | 7 +- .../piracy/DisablePiracyDetectionPatch.kt | 3 +- .../redditisfun/api/SpoofClientPatch.kt | 17 +-- .../relayforreddit/api/SpoofClientPatch.kt | 29 ++-- .../slide/api/SpoofClientPatch.kt | 4 +- .../customclients/sync/ads/DisableAdsPatch.kt | 4 +- .../piracy/DisablePiracyDetectionPatch.kt | 3 +- .../DisableSyncForLemmyBottomSheetPatch.kt | 4 +- .../syncforreddit/api/SpoofClientPatch.kt | 21 +-- .../syncforreddit/fix/slink/FixSLinksPatch.kt | 9 +- .../fix/user/UseUserEndpointPatch.kt | 23 ++-- .../fix/video/FixVideoDownloadsPatch.kt | 9 +- .../DisableScreenshotPopupPatch.kt | 4 +- .../premiumicon/UnlockPremiumIconPatch.kt | 4 +- .../tracking/url/SanitizeUrlQueryPatch.kt | 4 +- .../detection/root/RootDetectionPatch.kt | 4 +- .../misc/checks/BaseCheckEnvironmentPatch.kt | 27 ++-- .../misc/extension/SharedExtensionPatch.kt | 28 ++-- .../fix/verticalscroll/VerticalScrollPatch.kt | 5 +- .../shared/misc/gms/GmsCoreSupportPatch.kt | 48 +++---- .../patches/shared/misc/hex/HexPatch.kt | 4 +- .../misc/mapping/ResourceMappingPatch.kt | 6 +- .../shared/misc/settings/SettingsPatch.kt | 10 +- .../filesize/RemoveFileSizeLimitPatch.kt | 6 +- .../patches/songpal/badge/BadgeTabPatch.kt | 4 +- .../badge/RemoveNotificationBadgePatch.kt | 4 +- .../patches/soundcloud/ad/HideAdsPatch.kt | 13 +- .../analytics/DisableTelemetryPatch.kt | 4 +- .../offlinesync/EnableOfflineSyncPatch.kt | 10 +- .../spotify/layout/theme/CustomThemePatch.kt | 4 +- .../spotify/lite/ondemand/OnDemandPatch.kt | 7 +- .../spotify/navbar/PremiumNavbarTabPatch.kt | 4 +- .../stocard/layout/HideOffersTabPatch.kt | 4 +- .../stocard/layout/HideStoryBubblesPatch.kt | 4 +- .../subscription/UnlockSubscriptionPatch.kt | 7 +- .../DisableSubscriptionSuggestionsPatch.kt | 10 +- .../RemoveGooglePlayIntegrityCheckPatch.kt | 9 +- .../misc/themeunlock/UnlockThemePatch.kt | 7 +- .../tiktok/feedfilter/FeedFilterPatch.kt | 7 +- .../cleardisplay/RememberClearDisplayPatch.kt | 39 +++--- .../interaction/downloads/DownloadsPatch.kt | 18 +-- .../interaction/seekbar/ShowSeekbarPatch.kt | 7 +- .../interaction/speed/PlaybackSpeedPatch.kt | 50 ++++--- .../DisableLoginRequirementPatch.kt | 11 +- .../login/fixgoogle/FixGoogleLoginPatch.kt | 7 +- .../tiktok/misc/settings/SettingsPatch.kt | 27 ++-- .../tiktok/misc/spoof/sim/SpoofSimPatch.kt | 10 +- .../revanced/patches/trakt/UnlockProPatch.kt | 37 ++--- .../lockscreen/ShowOnLockscreenPatch.kt | 4 +- .../DisableBlogNotificationReminderPatch.kt | 4 +- .../popups/DisableGiftMessagePopupPatch.kt | 4 +- .../featureflags/OverrideFeatureFlagsPatch.kt | 13 +- .../tumblr/fixes/FixOldVersionsPatch.kt | 9 +- .../FilterTimelineObjectsPatch.kt | 16 +-- .../patches/twitch/ad/audio/AudioAdsPatch.kt | 6 +- .../twitch/ad/embedded/EmbeddedAdsPatch.kt | 4 +- .../patches/twitch/ad/video/VideoAdsPatch.kt | 31 ++--- .../antidelete/ShowDeletedMessagesPatch.kt | 10 +- .../autoclaim/AutoClaimChannelPointsPatch.kt | 7 +- .../patches/twitch/debug/DebugModePatch.kt | 14 +- .../twitch/misc/settings/SettingsPatch.kt | 32 ++--- .../downloads/UnlockDownloadsPatch.kt | 30 ++-- .../layout/viewcount/HideViewCountPatch.kt | 4 +- .../misc/dynamiccolor/DynamicColorPatch.kt | 8 +- .../patches/twitter/misc/hook/HookPatch.kt | 4 +- .../twitter/misc/hook/json/JsonHookPatch.kt | 130 +++++++----------- .../links/ChangeLinkSharingDomainPatch.kt | 19 ++- .../links/OpenLinksWithAppChooserPatch.kt | 4 +- .../misc/links/SanitizeSharingLinksPatch.kt | 4 +- .../patches/vsco/misc/pro/UnlockProPatch.kt | 4 +- .../misc/firebasegetcert/Fingerprints.kt | 2 +- .../firebasegetcert/FirebaseGetCertPatch.kt | 7 +- .../misc/promocode/PromoCodeUnlockPatch.kt | 4 +- .../patches/willhaben/ads/HideAdsPatch.kt | 7 +- .../windyapp/misc/unlockpro/UnlockProPatch.kt | 4 +- .../youtube/ad/general/HideAdsPatch.kt | 6 +- .../ad/getpremium/HideGetPremiumPatch.kt | 6 +- .../patches/youtube/ad/video/VideoAdsPatch.kt | 6 +- .../copyvideourl/CopyVideoUrlPatch.kt | 4 +- .../RemoveViewerDiscretionDialogPatch.kt | 4 +- .../interaction/downloads/DownloadsPatch.kt | 11 +- .../DisablePreciseSeekingGesturePatch.kt | 19 +-- .../seekbar/EnableSeekbarTappingPatch.kt | 11 +- .../seekbar/EnableSlideToSeekPatch.kt | 47 +++---- .../seekbar/SeekbarThumbnailsPatch.kt | 8 +- .../swipecontrols/SwipeControlsPatch.kt | 20 +-- .../layout/autocaptions/AutoCaptionsPatch.kt | 14 +- .../layout/branding/CustomBrandingPatch.kt | 8 +- .../branding/header/ChangeHeaderPatch.kt | 10 +- .../navigation/NavigationButtonsPatch.kt | 10 +- .../overlay/HidePlayerOverlayButtonsPatch.kt | 18 +-- .../endscreencards/HideEndscreenCardsPatch.kt | 20 ++- .../DisableFullscreenAmbientModePatch.kt | 6 +- .../hide/general/HideLayoutComponentsPatch.kt | 54 +++----- .../hide/infocards/HideInfoCardsPatch.kt | 14 +- .../DisableRollingNumberAnimationPatch.kt | 7 +- .../layout/hide/seekbar/HideSeekbarPatch.kt | 7 +- .../hide/shorts/HideShortsComponentsPatch.kt | 65 ++++----- .../DisableSuggestedVideoEndScreenPatch.kt | 6 +- .../layout/hide/time/HideTimestampPatch.kt | 4 +- .../layout/miniplayer/MiniplayerPatch.kt | 77 +++++------ .../panels/popup/PlayerPopupPanelsPatch.kt | 4 +- .../PlayerControlsBackgroundPatch.kt | 4 +- .../CustomPlayerOverlayOpacityPatch.kt | 9 +- .../ReturnYouTubeDislikePatch.kt | 66 ++++----- .../layout/searchbar/WideSearchbarPatch.kt | 19 ++- .../RestoreOldSeekbarThumbnailsPatch.kt} | 0 .../layout/seekbar/SeekbarColorPatch.kt | 27 ++-- .../shortsautoplay/ShortsAutoplayPatch.kt | 14 +- .../layout/sponsorblock/SponsorBlockPatch.kt | 29 ++-- .../spoofappversion/SpoofAppVersionPatch.kt | 8 +- .../layout/startpage/ChangeStartPagePatch.kt | 9 +- .../DisableResumingShortsOnStartupPatch.kt | 13 +- .../layout/tablet/EnableTabletLayoutPatch.kt | 4 +- .../layout/theme/LithoColorHookPatch.kt | 6 +- .../youtube/layout/theme/ThemePatch.kt | 24 ++-- .../misc/announcements/AnnouncementsPatch.kt | 6 +- .../misc/autorepeat/AutoRepeatPatch.kt | 12 +- .../BackgroundPlaybackPatch.kt | 35 ++--- .../misc/debugging/EnableDebuggingPatch.kt | 29 ++-- .../spoof/SpoofDeviceDimensionsPatch.kt | 6 +- ...ckWatchHistoryDomainNameResolutionPatch.kt | 4 +- .../FixBackToExitGesturePatch.kt | 24 ++-- .../fix/cairo/DisableCairoSettingsPatch.kt | 4 +- .../fix/playback/SpoofVideoStreamsPatch.kt | 31 ++--- .../misc/imageurlhook/CronetImageUrlHook.kt | 19 +-- .../misc/links/BypassURLRedirectsPatch.kt | 19 +-- .../misc/litho/filter/LithoFilterPatch.kt | 32 ++--- .../misc/navigation/NavigationBarHookPatch.kt | 33 ++--- .../playercontrols/PlayerControlsPatch.kt | 43 +++--- .../misc/playertype/PlayerTypeHookPatch.kt | 9 +- .../misc/playservice/VersionCheckPatch.kt | 4 +- .../RemoveTrackingQueryParameterPatch.kt | 19 ++- .../hook/RecyclerViewTreeHookPatch.kt | 7 +- .../youtube/misc/settings/SettingsPatch.kt | 23 ++-- .../misc/zoomhaptics/ZoomHapticsPatch.kt | 6 +- .../information/VideoInformationPatch.kt | 60 ++++---- .../PlayerResponseMethodHookPatch.kt | 13 +- .../quality/RememberVideoQualityPatch.kt | 38 +++-- .../speed/button/PlaybackSpeedButtonPatch.kt | 4 +- .../speed/custom/CustomPlaybackSpeedPatch.kt | 27 ++-- .../remember/RememberPlaybackSpeedPatch.kt | 4 +- .../youtube/video/videoid/VideoIdPatch.kt | 10 +- .../RestoreOldVideoQualityMenuPatch.kt | 11 +- .../misc/unlockpremium/UnlockPremiumPatch.kt | 11 +- .../kotlin/app/revanced/util/BytecodeUtils.kt | 46 +------ .../kotlin/app/revanced/util/ResourceUtils.kt | 12 +- .../util/microg/MicroGBytecodeHelper.kt | 0 .../util/microg/MicroGResourceHelper.kt | 0 230 files changed, 1068 insertions(+), 1733 deletions(-) rename patches/src/main/kotlin/app/revanced/patches/{music/premium/backgroundplay/BackgroundPlayPatch.kt => youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt} (100%) delete mode 100644 patches/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt delete mode 100644 patches/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index abf731bd3..af87b2376 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,5 +1,5 @@ [versions] -revanced-patcher = "20.0.2" +revanced-patcher = "21.0.0" # Tracking https://github.com/google/smali/issues/64. #noinspection GradleDependency smali = "3.0.5" @@ -7,7 +7,7 @@ gson = "2.11.0" # 8.3.0 causes java verifier error: https://github.com/ReVanced/revanced-patches/issues/2818. #noinspection GradleDependency agp = "8.2.2" -annotation = "1.9.0" +annotation = "1.9.1" appcompat = "1.7.0" okhttp = "5.0.0-alpha.14" retrofit = "2.11.0" diff --git a/patches/api/patches.api b/patches/api/patches.api index 2e74b07c7..04e8b64e2 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -533,7 +533,7 @@ public final class app/revanced/patches/shared/misc/checks/BaseCheckEnvironmentP public final class app/revanced/patches/shared/misc/extension/ExtensionHook { public final fun getFingerprint ()Lapp/revanced/patcher/Fingerprint; - public final fun invoke (Ljava/lang/String;)V + public final fun invoke (Lapp/revanced/patcher/patch/BytecodePatchContext;Ljava/lang/String;)V } public final class app/revanced/patches/shared/misc/extension/SharedExtensionPatchKt { @@ -551,10 +551,10 @@ public final class app/revanced/patches/shared/misc/gms/FingerprintsKt { } public final class app/revanced/patches/shared/misc/gms/GmsCoreSupportPatchKt { - public static final fun gmsCoreSupportPatch (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/Fingerprint;Ljava/util/Set;Lapp/revanced/patcher/Fingerprint;Lapp/revanced/patcher/patch/Patch;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/BytecodePatch; - public static synthetic fun gmsCoreSupportPatch$default (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/Fingerprint;Ljava/util/Set;Lapp/revanced/patcher/Fingerprint;Lapp/revanced/patcher/patch/Patch;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/BytecodePatch; - public static final fun gmsCoreSupportResourcePatch (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/patch/Option;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/ResourcePatch; - public static synthetic fun gmsCoreSupportResourcePatch$default (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/patch/Option;Lkotlin/jvm/functions/Function2;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/ResourcePatch; + public static final fun gmsCoreSupportPatch (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/Fingerprint;Ljava/util/Set;Lapp/revanced/patcher/Fingerprint;Lapp/revanced/patcher/patch/Patch;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/BytecodePatch; + public static synthetic fun gmsCoreSupportPatch$default (Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/Fingerprint;Ljava/util/Set;Lapp/revanced/patcher/Fingerprint;Lapp/revanced/patcher/patch/Patch;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/BytecodePatch; + public static final fun gmsCoreSupportResourcePatch (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/patch/Option;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;)Lapp/revanced/patcher/patch/ResourcePatch; + public static synthetic fun gmsCoreSupportResourcePatch$default (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lapp/revanced/patcher/patch/Option;Lkotlin/jvm/functions/Function1;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lapp/revanced/patcher/patch/ResourcePatch; } public final class app/revanced/patches/shared/misc/hex/HexPatchKt { @@ -979,13 +979,8 @@ public final class app/revanced/patches/twitter/misc/hook/json/JsonHook { public fun (Lapp/revanced/patcher/patch/BytecodePatchContext;Ljava/lang/String;)V } -public final class app/revanced/patches/twitter/misc/hook/json/JsonHookPatchHook : java/io/Closeable { - public fun (Lapp/revanced/patcher/Fingerprint;)V - public final fun addHook (Lapp/revanced/patches/twitter/misc/hook/json/JsonHook;)V - public fun close ()V -} - public final class app/revanced/patches/twitter/misc/hook/json/JsonHookPatchKt { + public static final fun addJsonHook (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patches/twitter/misc/hook/json/JsonHook;)V public static final fun getJsonHookPatch ()Lapp/revanced/patcher/patch/BytecodePatch; } @@ -1432,7 +1427,6 @@ public final class app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPat } public final class app/revanced/util/BytecodeUtilsKt { - public static final fun applyMatch (Lapp/revanced/patcher/Fingerprint;Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/Match;)Lapp/revanced/patcher/Match; public static final fun containsLiteralInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;J)Z public static final fun findInstructionIndicesReversed (Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/Opcode;)Ljava/util/List; public static final fun findInstructionIndicesReversed (Lcom/android/tools/smali/dexlib2/iface/Method;Lkotlin/jvm/functions/Function1;)Ljava/util/List; @@ -1440,8 +1434,6 @@ public final class app/revanced/util/BytecodeUtilsKt { public static final fun findInstructionIndicesReversedOrThrow (Lcom/android/tools/smali/dexlib2/iface/Method;Lkotlin/jvm/functions/Function1;)Ljava/util/List; public static final fun findMutableMethodOf (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lcom/android/tools/smali/dexlib2/iface/Method;)Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod; public static final fun forEachLiteralValueInstruction (Lapp/revanced/patcher/patch/BytecodePatchContext;JLkotlin/jvm/functions/Function2;)V - public static final fun getException (Lapp/revanced/patcher/Fingerprint;)Lapp/revanced/patcher/patch/PatchException; - public static final fun getMatchOrThrow (Lapp/revanced/patcher/Fingerprint;)Lapp/revanced/patcher/Match; public static final fun indexOfFirstInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;ILcom/android/tools/smali/dexlib2/Opcode;)I public static final fun indexOfFirstInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;ILkotlin/jvm/functions/Function1;)I public static final fun indexOfFirstInstruction (Lcom/android/tools/smali/dexlib2/iface/Method;Lcom/android/tools/smali/dexlib2/Opcode;)I @@ -1468,12 +1460,8 @@ public final class app/revanced/util/BytecodeUtilsKt { public static final fun indexOfFirstResourceIdOrThrow (Lcom/android/tools/smali/dexlib2/iface/Method;Ljava/lang/String;)I public static final fun injectHideViewCall (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;IILjava/lang/String;Ljava/lang/String;)V public static final fun literal (Lapp/revanced/patcher/FingerprintBuilder;Lkotlin/jvm/functions/Function0;)V - public static final fun returnEarly (Lapp/revanced/patcher/Fingerprint;Z)V public static final fun returnEarly (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;Z)V - public static final fun returnEarly (Ljava/lang/Iterable;Z)V - public static synthetic fun returnEarly$default (Lapp/revanced/patcher/Fingerprint;ZILjava/lang/Object;)V public static synthetic fun returnEarly$default (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableMethod;ZILjava/lang/Object;)V - public static synthetic fun returnEarly$default (Ljava/lang/Iterable;ZILjava/lang/Object;)V public static final fun transformMethods (Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lkotlin/jvm/functions/Function1;)V public static final fun traverseClassHierarchy (Lapp/revanced/patcher/patch/BytecodePatchContext;Lapp/revanced/patcher/util/proxy/mutableTypes/MutableClass;Lkotlin/jvm/functions/Function1;)V } diff --git a/patches/build.gradle.kts b/patches/build.gradle.kts index dab82da23..459d50a0c 100644 --- a/patches/build.gradle.kts +++ b/patches/build.gradle.kts @@ -21,6 +21,12 @@ dependencies { compileOnly(project(":patches:stub")) } +kotlin { + compilerOptions { + freeCompilerArgs = listOf("-Xcontext-receivers") + } +} + publishing { repositories { maven { diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/activity/exportall/ExportAllActivitiesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/activity/exportall/ExportAllActivitiesPatch.kt index 35c7b24f7..30193b704 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/activity/exportall/ExportAllActivitiesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/activity/exportall/ExportAllActivitiesPatch.kt @@ -8,10 +8,10 @@ val exportAllActivitiesPatch = resourcePatch( description = "Makes all app activities exportable.", use = false, ) { - execute { context -> + execute { val exportedFlag = "android:exported" - context.document["AndroidManifest.xml"].use { document -> + document("AndroidManifest.xml").use { document -> val activities = document.getElementsByTagName("activity") for (i in 0..activities.length) { diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch.kt index 885537ebb..fc7e33c5d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/debugging/EnableAndroidDebuggingPatch.kt @@ -8,8 +8,8 @@ val enableAndroidDebuggingPatch = resourcePatch( description = "Enables Android debugging capabilities. This can slow down the app.", use = false, ) { - execute { context -> - context.document["AndroidManifest.xml"].use { document -> + execute { + document("AndroidManifest.xml").use { document -> val applicationNode = document .getElementsByTagName("application") diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/interaction/gestures/PredictiveBackGesturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/interaction/gestures/PredictiveBackGesturePatch.kt index abf7f002c..29f644435 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/interaction/gestures/PredictiveBackGesturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/interaction/gestures/PredictiveBackGesturePatch.kt @@ -8,10 +8,10 @@ val predictiveBackGesturePatch = resourcePatch( description = "Enables the predictive back gesture introduced on Android 13.", use = false, ) { - execute { context -> + execute { val flag = "android:enableOnBackInvokedCallback" - context.document["AndroidManifest.xml"].use { document -> + document("AndroidManifest.xml").use { document -> with(document.getElementsByTagName("application").item(0)) { if (attributes.getNamedItem(flag) != null) return@with diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt index f5f6a5fb2..c85f4c3ba 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/network/OverrideCertificatePinningPatch.kt @@ -14,11 +14,11 @@ val overrideCertificatePinningPatch = resourcePatch( ) { dependsOn(enableAndroidDebuggingPatch) - execute { context -> - val resXmlDirectory = context["res/xml"] + execute { + val resXmlDirectory = get("res/xml") // Add android:networkSecurityConfig="@xml/network_security_config" and the "networkSecurityConfig" attribute if it does not exist. - context.document["AndroidManifest.xml"].use { document -> + document("AndroidManifest.xml").use { document -> val applicationNode = document.getElementsByTagName("application").item(0) as Element if (!applicationNode.hasAttribute("networkSecurityConfig")) { @@ -54,4 +54,4 @@ val overrideCertificatePinningPatch = resourcePatch( ) } } -} \ No newline at end of file +} diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/packagename/ChangePackageNamePatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/packagename/ChangePackageNamePatch.kt index 228fc8e19..48f951633 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/packagename/ChangePackageNamePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/packagename/ChangePackageNamePatch.kt @@ -41,8 +41,8 @@ val changePackageNamePatch = resourcePatch( it == "Default" || it!!.matches(Regex("^[a-z]\\w*(\\.[a-z]\\w*)+\$")) } - finalize { context -> - context.document["AndroidManifest.xml"].use { document -> + finalize { + document("AndroidManifest.xml").use { document -> val replacementPackageName = packageNameOption.value @@ -57,4 +57,4 @@ val changePackageNamePatch = resourcePatch( ) } } -} \ No newline at end of file +} diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt index 9c13b7034..fed38b963 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/resources/AddResourcesPatch.kt @@ -275,7 +275,7 @@ val addResourcesPatch = resourcePatch( After all patches that depend on addResourcesPatch have been executed, addResourcesPatch#finalize is finally called to add all staged resources to the app. */ - execute { context -> + execute { stagedResources = buildMap { /** * Puts resources under `/resources/addresources//.xml` into the map. @@ -299,7 +299,7 @@ val addResourcesPatch = resourcePatch( // instead of overwriting it. // This covers the example case such as adding strings and arrays of the same value. getOrPut(destValue, ::mutableMapOf).apply { - context.document[stream].use { document -> + document(stream).use { document -> document.getElementsByTagName("app").asSequence().forEach { app -> val appId = app.attributes.getNamedItem("id").textContent @@ -343,7 +343,7 @@ val addResourcesPatch = resourcePatch( * Adds all resources staged in [addResourcesPatch] to the app. * This is called after all patches that depend on [addResourcesPatch] have been executed. */ - finalize { context -> + finalize { operator fun MutableMap>.invoke( value: Value, resource: BaseResource, @@ -359,16 +359,15 @@ val addResourcesPatch = resourcePatch( } getOrPut(resourceFileName) { - val targetFile = - context["res/$value/$resourceFileName.xml"].also { - it.parentFile?.mkdirs() + val targetFile = this@finalize["res/$value/$resourceFileName.xml"].also { + it.parentFile?.mkdirs() - if (it.createNewFile()) { - it.writeText("\n\n") - } + if (it.createNewFile()) { + it.writeText("\n\n") } + } - context.document[targetFile.path].let { document -> + document(targetFile.path).let { document -> // Save the target node here as well // in order to avoid having to call document.getNode("resources") diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/screencapture/RemoveScreenCaptureRestrictionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/screencapture/RemoveScreenCaptureRestrictionPatch.kt index 3633541e7..5eef83ac0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/screencapture/RemoveScreenCaptureRestrictionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/screencapture/RemoveScreenCaptureRestrictionPatch.kt @@ -10,8 +10,8 @@ import org.w3c.dom.Element private val removeCaptureRestrictionResourcePatch = resourcePatch( description = "Sets allowAudioPlaybackCapture in manifest to true.", ) { - execute { context -> - context.document["AndroidManifest.xml"].use { document -> + execute { + document("AndroidManifest.xml").use { document -> // Get the application node. val applicationNode = document diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/shortcut/sharetargets/RemoveShareTargetsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/shortcut/sharetargets/RemoveShareTargetsPatch.kt index c2e39dc24..6b07c7dc6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/shortcut/sharetargets/RemoveShareTargetsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/shortcut/sharetargets/RemoveShareTargetsPatch.kt @@ -13,9 +13,9 @@ val removeShareTargetsPatch = resourcePatch( description = "Removes share targets like directly sharing to a frequent contact.", use = false, ) { - execute { context -> + execute { try { - context.document["res/xml/shortcuts.xml"] + document("res/xml/shortcuts.xml") } catch (_: FileNotFoundException) { return@execute Logger.getLogger(this::class.java.name).warning("The app has no shortcuts") }.use { document -> diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/transformation/TransformInstructionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/transformation/TransformInstructionsPatch.kt index 48d9ffa58..6564f4f26 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/transformation/TransformInstructionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/transformation/TransformInstructionsPatch.kt @@ -12,16 +12,15 @@ fun transformInstructionsPatch( transform: (MutableMethod, T) -> Unit, ) = bytecodePatch { // Returns the patch indices as a Sequence, which will execute lazily. - fun findPatchIndices(classDef: ClassDef, method: Method): Sequence? { - return method.implementation?.instructions?.asSequence()?.withIndex()?.mapNotNull { (index, instruction) -> - filterMap(classDef, method, instruction, index) - } + fun findPatchIndices(classDef: ClassDef, method: Method): Sequence? = + method.implementation?.instructions?.asSequence()?.withIndex()?.mapNotNull { (index, instruction) -> + filterMap(classDef, method, instruction, index) } - execute { context -> + execute { // Find all methods to patch buildMap { - context.classes.forEach { classDef -> + classes.forEach { classDef -> val methods = buildList { classDef.methods.forEach { method -> // Since the Sequence executes lazily, @@ -37,7 +36,7 @@ fun transformInstructionsPatch( } }.forEach { (classDef, methods) -> // And finally transform the methods... - val mutableClass = context.proxy(classDef).mutableClass + val mutableClass = proxy(classDef).mutableClass methods.map(mutableClass::findMutableMethodOf).forEach methods@{ mutableMethod -> val patchIndices = findPatchIndices(mutableClass, mutableMethod)?.toCollection(ArrayDeque()) diff --git a/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt b/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt index b8bfb4432..617f18a42 100644 --- a/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/all/misc/versioncode/ChangeVersionCodePatch.kt @@ -25,8 +25,8 @@ val changeVersionCodePatch = resourcePatch( required = true, ) { versionCode -> versionCode!! >= 1 } - execute { context -> - context.document["AndroidManifest.xml"].use { document -> + execute { + document("AndroidManifest.xml").use { document -> val manifestElement = document.getNode("manifest") as Element manifestElement.setAttribute("android:versionCode", "$versionCode") } diff --git a/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt index 5a726b791..bf53d8622 100644 --- a/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/amazon/DeepLinkingPatch.kt @@ -10,10 +10,8 @@ val deepLinkingPatch = bytecodePatch( ) { compatibleWith("com.amazon.mShop.android.shopping") - val deepLinkingMatch by deepLinkingFingerprint() - execute { - deepLinkingMatch.mutableMethod.addInstructions( + deepLinkingFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/backdrops/misc/pro/ProUnlockPatch.kt b/patches/src/main/kotlin/app/revanced/patches/backdrops/misc/pro/ProUnlockPatch.kt index 144f165de..70bbcd9fd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/backdrops/misc/pro/ProUnlockPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/backdrops/misc/pro/ProUnlockPatch.kt @@ -11,15 +11,13 @@ val proUnlockPatch = bytecodePatch( ) { compatibleWith("com.backdrops.wallpapers") - val proUnlockMatch by proUnlockFingerprint() - execute { - val registerIndex = proUnlockMatch.patternMatch!!.endIndex - 1 + val registerIndex = proUnlockFingerprint.patternMatch!!.endIndex - 1 - proUnlockMatch.mutableMethod.apply { + proUnlockFingerprint.method.apply { val register = getInstruction(registerIndex).registerA addInstruction( - proUnlockMatch.patternMatch!!.endIndex, + proUnlockFingerprint.patternMatch!!.endIndex, "const/4 v$register, 0x1", ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/bandcamp/limitations/RemovePlayLimitsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/bandcamp/limitations/RemovePlayLimitsPatch.kt index 88302ef4c..9ba60935f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/bandcamp/limitations/RemovePlayLimitsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/bandcamp/limitations/RemovePlayLimitsPatch.kt @@ -10,9 +10,7 @@ val removePlayLimitsPatch = bytecodePatch( ) { compatibleWith("com.bandcamp.android") - val handlePlaybackLimitsMatch by handlePlaybackLimitsFingerprint() - execute { - handlePlaybackLimitsMatch.mutableMethod.addInstructions(0, "return-void") + handlePlaybackLimitsFingerprint.method.addInstructions(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt index a0a79f6db..c2abcc5b6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/cieid/restrictions/root/BypassRootChecksPatch.kt @@ -10,9 +10,7 @@ val bypassRootChecksPatch = bytecodePatch( ) { compatibleWith("it.ipzs.cieid") - val checkRootMatch by checkRootFingerprint() - execute { - checkRootMatch.mutableMethod.addInstruction(1, "return-void") + checkRootFingerprint.method.addInstruction(1, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt index fa9eaf009..a5c56ddb0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/ad/DisableAdsPatch.kt @@ -11,8 +11,6 @@ val disableAdsPatch = bytecodePatch( ) { compatibleWith("com.duolingo") - val initializeMonetizationDebugSettingsMatch by initializeMonetizationDebugSettingsFingerprint() - execute { // Couple approaches to remove ads exist: // @@ -21,8 +19,8 @@ val disableAdsPatch = bytecodePatch( // SharedPreferences has a debug boolean value with key "disable_ads", which maps to "DebugCategory.DISABLE_ADS". // // MonetizationDebugSettings seems to be the most general setting to work fine. - initializeMonetizationDebugSettingsMatch.mutableMethod.apply { - val insertIndex = initializeMonetizationDebugSettingsMatch.patternMatch!!.startIndex + initializeMonetizationDebugSettingsFingerprint.method.apply { + val insertIndex = initializeMonetizationDebugSettingsFingerprint.patternMatch!!.startIndex val register = getInstruction(insertIndex).registerA addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt index 609b03cf1..833f9dd7d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/duolingo/debug/EnableDebugMenuPatch.kt @@ -12,11 +12,9 @@ val enableDebugMenuPatch = bytecodePatch( ) { compatibleWith("com.duolingo"("5.158.4")) - val initializeBuildConfigProviderMatch by initializeBuildConfigProviderFingerprint() - execute { - initializeBuildConfigProviderMatch.mutableMethod.apply { - val insertIndex = initializeBuildConfigProviderMatch.patternMatch!!.startIndex + initializeBuildConfigProviderFingerprint.method.apply { + val insertIndex = initializeBuildConfigProviderFingerprint.patternMatch!!.startIndex val register = getInstruction(insertIndex).registerA addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/facebook/ads/mainfeed/HideSponsoredStoriesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/facebook/ads/mainfeed/HideSponsoredStoriesPatch.kt index 0c201f9fc..e8a406587 100644 --- a/patches/src/main/kotlin/app/revanced/patches/facebook/ads/mainfeed/HideSponsoredStoriesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/facebook/ads/mainfeed/HideSponsoredStoriesPatch.kt @@ -19,13 +19,9 @@ val hideSponsoredStoriesPatch = bytecodePatch( ) { compatibleWith("com.facebook.katana") - val getStoryVisibilityMatch by getStoryVisibilityFingerprint() - val getSponsoredDataModelTemplateMatch by getSponsoredDataModelTemplateFingerprint() - val baseModelMapperMatch by baseModelMapperFingerprint() - execute { - val sponsoredDataModelTemplateMethod = getSponsoredDataModelTemplateMatch.method - val baseModelMapperMethod = baseModelMapperMatch.method + val sponsoredDataModelTemplateMethod = getSponsoredDataModelTemplateFingerprint.originalMethod + val baseModelMapperMethod = baseModelMapperFingerprint.originalMethod val baseModelWithTreeType = baseModelMapperMethod.returnType val graphQlStoryClassDescriptor = "Lcom/facebook/graphql/model/GraphQLStory;" @@ -33,8 +29,9 @@ val hideSponsoredStoriesPatch = bytecodePatch( // The "SponsoredDataModelTemplate" methods has the ids in its body to extract sponsored data // from GraphQL models, but targets the wrong derived type of "BaseModelWithTree". Since those ids // could change in future version, we need to extract them and call the base implementation directly. + val getSponsoredDataHelperMethod = ImmutableMethod( - getStoryVisibilityMatch.classDef.type, + getStoryVisibilityFingerprint.originalClassDef.type, "getSponsoredData", listOf(ImmutableMethodParameter(graphQlStoryClassDescriptor, null, null)), baseModelWithTreeType, @@ -68,23 +65,23 @@ val hideSponsoredStoriesPatch = bytecodePatch( ) } - getStoryVisibilityMatch.mutableClass.methods.add(getSponsoredDataHelperMethod) + getStoryVisibilityFingerprint.classDef.methods.add(getSponsoredDataHelperMethod) // Check if the parameter type is GraphQLStory and if sponsoredDataModelGetter returns a non-null value. // If so, hide the story by setting the visibility to StoryVisibility.GONE. - getStoryVisibilityMatch.mutableMethod.addInstructionsWithLabels( - getStoryVisibilityMatch.patternMatch!!.startIndex, + getStoryVisibilityFingerprint.method.addInstructionsWithLabels( + getStoryVisibilityFingerprint.patternMatch!!.startIndex, """ - instance-of v0, p0, $graphQlStoryClassDescriptor - if-eqz v0, :resume_normal - invoke-static {p0}, $getSponsoredDataHelperMethod - move-result-object v0 - if-eqz v0, :resume_normal - const-string v0, "GONE" - return-object v0 - :resume_normal - nop - """, + instance-of v0, p0, $graphQlStoryClassDescriptor + if-eqz v0, :resume_normal + invoke-static {p0}, $getSponsoredDataHelperMethod + move-result-object v0 + if-eqz v0, :resume_normal + const-string v0, "GONE" + return-object v0 + :resume_normal + nop + """, ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt index 7699b7be1..ec811fc3c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/facebook/ads/story/HideStoryAdsPatch.kt @@ -10,12 +10,12 @@ val hideStoryAdsPatch = bytecodePatch( ) { compatibleWith("com.facebook.katana") - val fetchMoreAdsMatch by fetchMoreAdsFingerprint() - val adsInsertionMatch by adsInsertionFingerprint() - execute { - setOf(fetchMoreAdsMatch, adsInsertionMatch).forEach { match -> - match.mutableMethod.replaceInstruction(0, "return-void") + setOf( + fetchMoreAdsFingerprint, + adsInsertionFingerprint, + ).forEach { fingerprint -> + fingerprint.method.replaceInstruction(0, "return-void") } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt index 4bdeaf4a5..76dc2413f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/bootloader/BootloaderDetectionPatch.kt @@ -10,12 +10,9 @@ val bootloaderDetectionPatch = bytecodePatch( ) { compatibleWith("at.gv.bmf.bmf2go") - val createKeyMatch by createKeyFingerprint() - val bootStateMatch by bootStateFingerprint() - execute { - setOf(createKeyMatch, bootStateMatch).forEach { match -> - match.mutableMethod.addInstructions( + setOf(createKeyFingerprint, bootStateFingerprint).forEach { fingerprint -> + fingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/RootDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/RootDetectionPatch.kt index 9144bf749..e2b7b0616 100644 --- a/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/RootDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/finanzonline/detection/root/RootDetectionPatch.kt @@ -10,10 +10,8 @@ val rootDetectionPatch = bytecodePatch( ) { compatibleWith("at.gv.bmf.bmf2go") - val rootDetectionMatch by rootDetectionFingerprint() - execute { - rootDetectionMatch.mutableMethod.addInstructions( + rootDetectionFingerprint.method.addInstructions( 0, """ sget-object v0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean; diff --git a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt index 81cbb8c58..0e84ec6df 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlenews/customtabs/EnableCustomTabsPatch.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction @Suppress("unused") val enableCustomTabsPatch = bytecodePatch( @@ -12,11 +13,9 @@ val enableCustomTabsPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.magazines") - val launchCustomTabMatch by launchCustomTabFingerprint() - execute { - launchCustomTabMatch.mutableMethod.apply { - val checkIndex = launchCustomTabMatch.patternMatch!!.endIndex + 1 + launchCustomTabFingerprint.method.apply { + val checkIndex = launchCustomTabFingerprint.patternMatch!!.endIndex + 1 val register = getInstruction(checkIndex).registerA replaceInstruction(checkIndex, "const/4 v$register, 0x1") diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt index f0aaad890..4c0be2b77 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/features/SpoofFeaturesPatch.kt @@ -54,8 +54,6 @@ val spoofFeaturesPatch = bytecodePatch( required = true, ) - val initializeFeaturesEnumMatch by initializeFeaturesEnumFingerprint() - execute { @Suppress("NAME_SHADOWING") val featuresToEnable = featuresToEnable!!.toSet() @@ -63,7 +61,7 @@ val spoofFeaturesPatch = bytecodePatch( @Suppress("NAME_SHADOWING") val featuresToDisable = featuresToDisable!!.toSet() - initializeFeaturesEnumMatch.mutableMethod.apply { + initializeFeaturesEnumFingerprint.method.apply { instructions.filter { it.opcode == Opcode.CONST_STRING }.forEach { val feature = it.getReference()!!.string diff --git a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt index 91693d047..1d8717115 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlephotos/misc/preferences/RestoreHiddenBackUpWhileChargingTogglePatch.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction @Suppress("unused") val restoreHiddenBackUpWhileChargingTogglePatch = bytecodePatch( @@ -12,12 +13,10 @@ val restoreHiddenBackUpWhileChargingTogglePatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.photos") - val backupPreferencesMatch by backupPreferencesFingerprint() - execute { // Patches 'backup_prefs_had_backup_only_when_charging_enabled' to always be true. - val chargingPrefStringIndex = backupPreferencesMatch.stringMatches!!.first().index - backupPreferencesMatch.mutableMethod.apply { + val chargingPrefStringIndex = backupPreferencesFingerprint.stringMatches!!.first().index + backupPreferencesFingerprint.method.apply { // Get the register of move-result. val resultRegister = getInstruction(chargingPrefStringIndex + 2).registerA // Insert const after move-result to override register as true. diff --git a/patches/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions.kt b/patches/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions.kt index 2c5a0aec1..2cf32adef 100644 --- a/patches/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions.kt +++ b/patches/src/main/kotlin/app/revanced/patches/googlerecorder/restrictions/RemoveDeviceRestrictions.kt @@ -5,6 +5,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction @Suppress("unused") val removeDeviceRestrictionsPatch = bytecodePatch( @@ -13,12 +14,10 @@ val removeDeviceRestrictionsPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.recorder") - val onApplicationCreateMatch by onApplicationCreateFingerprint() - execute { - val featureStringIndex = onApplicationCreateMatch.stringMatches!!.first().index + val featureStringIndex = onApplicationCreateFingerprint.stringMatches!!.first().index - onApplicationCreateMatch.mutableMethod.apply { + onApplicationCreateFingerprint.method.apply { // Remove check for device restrictions. removeInstructions(featureStringIndex - 2, 5) diff --git a/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt index ae269f817..1132a5ad9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/hexeditor/ad/DisableAdsPatch.kt @@ -9,10 +9,8 @@ val disableAdsPatch = bytecodePatch( ) { compatibleWith("com.myprog.hexedit") - val primaryAdsMatch by primaryAdsFingerprint() - execute { - primaryAdsMatch.mutableMethod.replaceInstructions( + primaryAdsFingerprint.method.replaceInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/iconpackstudio/misc/pro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/iconpackstudio/misc/pro/UnlockProPatch.kt index daea6581c..c1e4719b7 100644 --- a/patches/src/main/kotlin/app/revanced/patches/iconpackstudio/misc/pro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/iconpackstudio/misc/pro/UnlockProPatch.kt @@ -9,10 +9,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("ginlemon.iconpackstudio"("2.2 build 016")) - val checkProMatch by checkProFingerprint() - execute { - checkProMatch.mutableMethod.addInstructions( + checkProFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/root/RootDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/root/RootDetectionPatch.kt index 9440e20d3..6c79650d9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/root/RootDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/root/RootDetectionPatch.kt @@ -10,11 +10,11 @@ val rootDetectionPatch = bytecodePatch( ) { compatibleWith("at.gv.oe.app") - attestationSupportedCheckFingerprint() - bootloaderCheckFingerprint() - rootCheckFingerprint() - execute { - setOf(attestationSupportedCheckFingerprint, bootloaderCheckFingerprint, rootCheckFingerprint).returnEarly(true) + setOf( + attestationSupportedCheckFingerprint, + bootloaderCheckFingerprint, + rootCheckFingerprint, + ).forEach { it.method.returnEarly(true) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/signature/SpoofSignaturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/signature/SpoofSignaturePatch.kt index 12295f90c..e6b312792 100644 --- a/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/signature/SpoofSignaturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/idaustria/detection/signature/SpoofSignaturePatch.kt @@ -10,8 +10,6 @@ val spoofSignaturePatch = bytecodePatch( ) { compatibleWith("at.gv.oe.app") - val spoofSignatureMatch by spoofSignatureFingerprint() - execute { val expectedSignature = "OpenSSLRSAPublicKey{modulus=ac3e6fd6050aa7e0d6010ae58190404cd89a56935b44f6fee" + @@ -26,7 +24,7 @@ val spoofSignaturePatch = bytecodePatch( "77ef1be61b2c01ebdabddcbf53cc4b6fd9a3c445606ee77b3758162c80ad8f8137b3c6864e92db904807dcb2be9d7717dd21" + "bf42c121d620ddfb7914f7a95c713d9e1c1b7bdb4a03d618e40cf7e9e235c0b5687e03b7ab3,publicExponent=10001}" - spoofSignatureMatch.mutableMethod.addInstructions( + spoofSignatureFingerprint.method.addInstructions( 0, """ const-string v0, "$expectedSignature" diff --git a/patches/src/main/kotlin/app/revanced/patches/inshorts/ad/InshortsAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/inshorts/ad/InshortsAdsPatch.kt index 3fff6a270..87fddcb78 100644 --- a/patches/src/main/kotlin/app/revanced/patches/inshorts/ad/InshortsAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/inshorts/ad/InshortsAdsPatch.kt @@ -9,10 +9,8 @@ val hideAdsPatch = bytecodePatch( ) { compatibleWith("com.nis.app") - val inshortsAdsMatch by inshortsAdsFingerprint() - execute { - inshortsAdsMatch.mutableMethod.addInstruction( + inshortsAdsFingerprint.method.addInstruction( 0, """ return-void diff --git a/patches/src/main/kotlin/app/revanced/patches/instagram/ads/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/instagram/ads/HideAdsPatch.kt index 1291c4212..29aeccc1b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/instagram/ads/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/instagram/ads/HideAdsPatch.kt @@ -11,10 +11,8 @@ val hideAdsPatch = bytecodePatch( ) { compatibleWith("com.instagram.android") - val adInjectorMatch by adInjectorFingerprint() - execute { - adInjectorMatch.mutableMethod.addInstructions( + adInjectorFingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/irplus/ad/RemoveAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/irplus/ad/RemoveAdsPatch.kt index a0a6e0170..44b76f5fc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/irplus/ad/RemoveAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/irplus/ad/RemoveAdsPatch.kt @@ -9,11 +9,9 @@ val removeAdsPatch = bytecodePatch( ) { compatibleWith("net.binarymode.android.irplus") - val irplusAdsMatch by irplusAdsFingerprint() - execute { // By overwriting the second parameter of the method, // the view which holds the advertisement is removed. - irplusAdsMatch.mutableMethod.addInstruction(0, "const/4 p2, 0x0") + irplusAdsFingerprint.method.addInstruction(0, "const/4 p2, 0x0") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt index 79d41368e..a5a1cf8f3 100644 --- a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/login/DisableMandatoryLoginPatch.kt @@ -9,10 +9,8 @@ val disableMandatoryLoginPatch = bytecodePatch( ) { compatibleWith("com.adobe.lrmobile") - val isLoggedInMatch by isLoggedInFingerprint() - execute { - isLoggedInMatch.mutableMethod.apply { + isLoggedInFingerprint.method.apply { val index = implementation!!.instructions.lastIndex - 1 // Set isLoggedIn = true. replaceInstruction(index, "const/4 v0, 0x1") diff --git a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/premium/UnlockPremiumPatch.kt b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/premium/UnlockPremiumPatch.kt index 730c523d4..b9187af27 100644 --- a/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/premium/UnlockPremiumPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/lightroom/misc/premium/UnlockPremiumPatch.kt @@ -9,10 +9,8 @@ val unlockPremiumPatch = bytecodePatch( ) { compatibleWith("com.adobe.lrmobile") - val hasPurchasedMatch by hasPurchasedFingerprint() - execute { // Set hasPremium = true. - hasPurchasedMatch.mutableMethod.replaceInstruction(2, "const/4 v2, 0x1") + hasPurchasedFingerprint.method.replaceInstruction(2, "const/4 v2, 0x1") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/LicenseValidationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/LicenseValidationPatch.kt index 171186e1a..8b4a41734 100644 --- a/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/LicenseValidationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/license/LicenseValidationPatch.kt @@ -6,10 +6,9 @@ import app.revanced.patcher.patch.bytecodePatch val licenseValidationPatch = bytecodePatch( description = "Disables Firebase license validation.", ) { - val licenseValidationMatch by licenseValidationFingerprint() execute { - licenseValidationMatch.mutableMethod.replaceInstructions( + licenseValidationFingerprint.method.replaceInstructions( 0, """ const/4 p0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/SignatureVerificationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/SignatureVerificationPatch.kt index 6aca2b7a7..c6b05ae8d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/SignatureVerificationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/memegenerator/detection/signature/SignatureVerificationPatch.kt @@ -6,10 +6,9 @@ import app.revanced.patcher.patch.bytecodePatch val signatureVerificationPatch = bytecodePatch( description = "Disables detection of incorrect signature.", ) { - val verifySignatureMatch by verifySignatureFingerprint() execute { - verifySignatureMatch.mutableMethod.replaceInstructions( + verifySignatureFingerprint.method.replaceInstructions( 0, """ const/4 p0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/UnlockProVersionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/UnlockProVersionPatch.kt index fa475fbbc..b74e2d3a8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/UnlockProVersionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/memegenerator/misc/pro/UnlockProVersionPatch.kt @@ -13,10 +13,8 @@ val unlockProVersionPatch = bytecodePatch( compatibleWith("com.zombodroid.MemeGenerator"("4.6364", "4.6370", "4.6375", "4.6377")) - val isFreeVersionMatch by isFreeVersionFingerprint() - execute { - isFreeVersionMatch.mutableMethod.replaceInstructions( + isFreeVersionFingerprint.method.replaceInstructions( 0, """ sget-object p0, Ljava/lang/Boolean;->FALSE:Ljava/lang/Boolean; diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxAdsPatch.kt index ca13b71c8..090ffd9f8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxAdsPatch.kt @@ -10,9 +10,7 @@ val hideInboxAdsPatch = bytecodePatch( ) { compatibleWith("com.facebook.orca") - val loadInboxAdsMatch by loadInboxAdsFingerprint() - execute { - loadInboxAdsMatch.mutableMethod.replaceInstruction(0, "return-void") + loadInboxAdsFingerprint.method.replaceInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxSubtabsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxSubtabsPatch.kt index 24d3f8192..2d190615f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxSubtabsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/inbox/HideInboxSubtabsPatch.kt @@ -10,9 +10,7 @@ val hideInboxSubtabsPatch = bytecodePatch( ) { compatibleWith("com.facebook.orca") - val createInboxSubTabsMatch by createInboxSubTabsFingerprint() - execute { - createInboxSubTabsMatch.mutableMethod.replaceInstruction(2, "const/4 v0, 0x0") + createInboxSubTabsFingerprint.method.replaceInstruction(2, "const/4 v0, 0x0") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableSwitchingEmojiToStickerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableSwitchingEmojiToStickerPatch.kt index 3d4e223f6..716b40e1d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableSwitchingEmojiToStickerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableSwitchingEmojiToStickerPatch.kt @@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction @Suppress("unused") val disableSwitchingEmojiToStickerPatch = bytecodePatch( @@ -12,12 +13,9 @@ val disableSwitchingEmojiToStickerPatch = bytecodePatch( ) { compatibleWith("com.facebook.orca"("439.0.0.29.119")) - val switchMessangeInputEmojiButtonMatch by switchMessangeInputEmojiButtonFingerprint() - execute { - val setStringIndex = switchMessangeInputEmojiButtonMatch.patternMatch!!.startIndex + 2 - - switchMessangeInputEmojiButtonMatch.mutableMethod.apply { + switchMessengeInputEmojiButtonFingerprint.method.apply { + val setStringIndex = switchMessengeInputEmojiButtonFingerprint.patternMatch!!.startIndex + 2 val targetRegister = getInstruction(setStringIndex).registerA replaceInstruction(setStringIndex, "const-string v$targetRegister, \"expression\"") diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableTypingIndicatorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableTypingIndicatorPatch.kt index 651491ca6..0d5bfd58c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableTypingIndicatorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/DisableTypingIndicatorPatch.kt @@ -10,9 +10,7 @@ val disableTypingIndicatorPatch = bytecodePatch( ) { compatibleWith("com.facebook.orca") - val sendTypingIndicatorMatch by sendTypingIndicatorFingerprint() - execute { - sendTypingIndicatorMatch.mutableMethod.replaceInstruction(0, "return-void") + sendTypingIndicatorFingerprint.method.replaceInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/Fingerprints.kt index 0a1d181d2..75fd54f7d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/messenger/inputfield/Fingerprints.kt @@ -16,7 +16,7 @@ internal val sendTypingIndicatorFingerprint = fingerprint { } } -internal val switchMessangeInputEmojiButtonFingerprint = fingerprint { +internal val switchMessengeInputEmojiButtonFingerprint = fingerprint { returns("V") parameters("L", "Z") opcodes( diff --git a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt index bb038f26b..a2a53caba 100644 --- a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/locale/ForceEnglishLocalePatch.kt @@ -15,14 +15,10 @@ val forceEnglishLocalePatch = bytecodePatch( dependsOn(fixLoginPatch) - val syncBluetoothLanguageMatch by syncBluetoothLanguageFingerprint() - execute { - val resolvePhoneLocaleInstruction = syncBluetoothLanguageMatch.patternMatch!!.startIndex - - syncBluetoothLanguageMatch.mutableMethod.apply { - val registerIndexToUpdate = - getInstruction(resolvePhoneLocaleInstruction).registerA + syncBluetoothLanguageFingerprint.method.apply { + val resolvePhoneLocaleInstruction = syncBluetoothLanguageFingerprint.patternMatch!!.startIndex + val registerIndexToUpdate = getInstruction(resolvePhoneLocaleInstruction).registerA replaceInstruction( resolvePhoneLocaleInstruction, diff --git a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/login/FixLoginPatch.kt b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/login/FixLoginPatch.kt index f07ca5f13..093a5d4f1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/login/FixLoginPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/mifitness/misc/login/FixLoginPatch.kt @@ -9,9 +9,7 @@ val fixLoginPatch = bytecodePatch( ) { compatibleWith("com.xiaomi.wearable") - val xiaomiAccountManagerConstructorMatch by xiaomiAccountManagerConstructorFingerprint() - execute { - xiaomiAccountManagerConstructorMatch.mutableMethod.addInstruction(0, "const/16 p2, 0x0") + xiaomiAccountManagerConstructorFingerprint.method.addInstruction(0, "const/16 p2, 0x0") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt index b39b2822f..27c981256 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/ad/video/HideVideoAds.kt @@ -10,13 +10,10 @@ val hideVideoAdsPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val showVideoAdsParentMatch by showVideoAdsParentFingerprint() - - execute { context -> - val showVideoAdsMethod = context - .navigate(showVideoAdsParentMatch.mutableMethod) - .at(showVideoAdsParentMatch.patternMatch!!.startIndex + 1).mutable() - - showVideoAdsMethod.addInstruction(0, "const/4 p1, 0x0") + execute { + navigate(showVideoAdsParentFingerprint.originalMethod) + .to(showVideoAdsParentFingerprint.patternMatch!!.startIndex + 1) + .stop() + .addInstruction(0, "const/4 p1, 0x0") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/EnableExclusiveAudioPlayback.kt b/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/EnableExclusiveAudioPlayback.kt index 6d09557c8..466e81aeb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/EnableExclusiveAudioPlayback.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/audio/exclusiveaudio/EnableExclusiveAudioPlayback.kt @@ -10,10 +10,8 @@ val enableExclusiveAudioPlaybackPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val allowExclusiveAudioPlaybackMatch by allowExclusiveAudioPlaybackFingerprint() - execute { - allowExclusiveAudioPlaybackMatch.mutableMethod.apply { + allowExclusiveAudioPlaybackFingerprint.method.apply { addInstructions( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt index 7e46fd88f..c6617664f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentrepeat/PermanentRepeatPatch.kt @@ -13,13 +13,12 @@ val permanentRepeatPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val repeatTrackMatch by repeatTrackFingerprint() - execute { - val startIndex = repeatTrackMatch.patternMatch!!.endIndex + + val startIndex = repeatTrackFingerprint.patternMatch!!.endIndex val repeatIndex = startIndex + 1 - repeatTrackMatch.mutableMethod.apply { + repeatTrackFingerprint.method.apply { addInstructionsWithLabels( startIndex, "goto :repeat", diff --git a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentshuffle/PermanentShufflePatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentshuffle/PermanentShufflePatch.kt index f4d754216..8d044de2c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentshuffle/PermanentShufflePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/interaction/permanentshuffle/PermanentShufflePatch.kt @@ -20,9 +20,7 @@ val permanentShufflePatch = bytecodePatch( ), ) - val disableShuffleMatch by disableShuffleFingerprint() - execute { - disableShuffleMatch.mutableMethod.addInstruction(0, "return-void") + disableShuffleFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt index 0dc7e02e4..b0021b966 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/compactheader/HideCategoryBar.kt @@ -13,11 +13,9 @@ val hideCategoryBar = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val constructCategoryBarMatch by constructCategoryBarFingerprint() - execute { - constructCategoryBarMatch.mutableMethod.apply { - val insertIndex = constructCategoryBarMatch.patternMatch!!.startIndex + constructCategoryBarFingerprint.method.apply { + val insertIndex = constructCategoryBarFingerprint.patternMatch!!.startIndex val register = getInstruction(insertIndex - 1).registerA addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt index 08711e1fb..892dac76a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/premium/HideGetPremiumPatch.kt @@ -14,12 +14,9 @@ val hideGetPremiumPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val hideGetPremiumMatch by hideGetPremiumFingerprint() - val membershipSettingsMatch by membershipSettingsFingerprint() - execute { - hideGetPremiumMatch.mutableMethod.apply { - val insertIndex = hideGetPremiumMatch.patternMatch!!.endIndex + hideGetPremiumFingerprint.method.apply { + val insertIndex = hideGetPremiumFingerprint.patternMatch!!.endIndex val setVisibilityInstruction = getInstruction(insertIndex) val getPremiumViewRegister = setVisibilityInstruction.registerC @@ -37,7 +34,7 @@ val hideGetPremiumPatch = bytecodePatch( ) } - membershipSettingsMatch.mutableMethod.addInstructions( + membershipSettingsFingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/RemoveUpgradeButtonPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/RemoveUpgradeButtonPatch.kt index 01167b6e4..22878b05f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/RemoveUpgradeButtonPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/layout/upgradebutton/RemoveUpgradeButtonPatch.kt @@ -20,12 +20,10 @@ val removeUpgradeButtonPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val pivotBarConstructorMatch by pivotBarConstructorFingerprint() - execute { - pivotBarConstructorMatch.mutableMethod.apply { + pivotBarConstructorFingerprint.method.apply { val pivotBarElementFieldReference = - getInstruction(pivotBarConstructorMatch.patternMatch!!.endIndex - 1) + getInstruction(pivotBarConstructorFingerprint.patternMatch!!.endIndex - 1) .getReference() val register = getInstruction(0).registerC @@ -39,7 +37,7 @@ val removeUpgradeButtonPatch = bytecodePatch( iput-object v0, v$register, $pivotBarElementFieldReference """.toInstructions().toMutableList() - val endIndex = pivotBarConstructorMatch.patternMatch!!.endIndex + val endIndex = pivotBarConstructorFingerprint.patternMatch!!.endIndex // Replace the instruction to retain the label at given index. replaceInstruction( diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/androidauto/BypassCertificateChecksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/androidauto/BypassCertificateChecksPatch.kt index b499cdbc7..d53691886 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/androidauto/BypassCertificateChecksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/androidauto/BypassCertificateChecksPatch.kt @@ -10,15 +10,13 @@ val bypassCertificateChecksPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val checkCertificateMatch by checkCertificateFingerprint() - execute { - checkCertificateMatch.mutableMethod.addInstructions( + checkCertificateFingerprint.method.addInstructions( 0, """ - const/4 v0, 0x1 - return v0 - """, + const/4 v0, 0x1 + return v0 + """, ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt index 7e791af12..9561d9ff8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/music/misc/backgroundplayback/BackgroundPlaybackPatch.kt @@ -11,16 +11,13 @@ val backgroundPlaybackPatch = bytecodePatch( ) { compatibleWith("com.google.android.apps.youtube.music") - val kidsBackgroundPlaybackPolicyControllerMatch by kidsBackgroundPlaybackPolicyControllerFingerprint() - val backgroundPlaybackDisableMatch by backgroundPlaybackDisableFingerprint() - execute { - kidsBackgroundPlaybackPolicyControllerMatch.mutableMethod.addInstruction( + kidsBackgroundPlaybackPolicyControllerFingerprint.method.addInstruction( 0, "return-void", ) - backgroundPlaybackDisableMatch.mutableMethod.addInstructions( + backgroundPlaybackDisableFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/myexpenses/misc/pro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/myexpenses/misc/pro/UnlockProPatch.kt index 6f3fd4a1b..4365c2c2c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/myexpenses/misc/pro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/myexpenses/misc/pro/UnlockProPatch.kt @@ -9,10 +9,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("org.totschnig.myexpenses") - val isEnabledMatch by isEnabledFingerprint() - execute { - isEnabledMatch.mutableMethod.addInstructions( + isEnabledFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/myfitnesspal/ads/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/myfitnesspal/ads/HideAdsPatch.kt index f2bb4b4ef..a9428b29e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/myfitnesspal/ads/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/myfitnesspal/ads/HideAdsPatch.kt @@ -10,12 +10,9 @@ val hideAdsPatch = bytecodePatch( ) { compatibleWith("com.myfitnesspal.android"("24.14.2")) - val isPremiumUseCaseImplMatch by isPremiumUseCaseImplFingerprint() - val mainActivityNavigateToNativePremiumUpsellMatch by mainActivityNavigateToNativePremiumUpsellFingerprint() - execute { // Overwrite the premium status specifically for ads. - isPremiumUseCaseImplMatch.mutableMethod.replaceInstructions( + isPremiumUseCaseImplFingerprint.method.replaceInstructions( 0, """ sget-object v0, Ljava/lang/Boolean;->TRUE:Ljava/lang/Boolean; @@ -25,7 +22,7 @@ val hideAdsPatch = bytecodePatch( // Prevent the premium upsell dialog from showing when the main activity is launched. // In other places that are premium-only the dialog will still show. - mainActivityNavigateToNativePremiumUpsellMatch.mutableMethod.replaceInstructions( + mainActivityNavigateToNativePremiumUpsellFingerprint.method.replaceInstructions( 0, "return-void", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch.kt index c747f426e..b4f675ed7 100644 --- a/patches/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/netguard/broadcasts/removerestriction/RemoveBroadcastsRestrictionPatch.kt @@ -10,8 +10,8 @@ val removeBroadcastsRestrictionPatch = resourcePatch( ) { compatibleWith("eu.faircode.netguard") - execute { context -> - context.document["AndroidManifest.xml"].use { document -> + execute { + document("AndroidManifest.xml").use { document -> val applicationNode = document .getElementsByTagName("application") diff --git a/patches/src/main/kotlin/app/revanced/patches/nfctoolsse/misc/pro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/nfctoolsse/misc/pro/UnlockProPatch.kt index c44f91116..55276126e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/nfctoolsse/misc/pro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/nfctoolsse/misc/pro/UnlockProPatch.kt @@ -9,10 +9,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("com.wakdev.apps.nfctools.se") - val isLicenseRegisteredMatch by isLicenseRegisteredFingerprint() - execute { - isLicenseRegisteredMatch.mutableMethod.addInstructions( + isLicenseRegisteredFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/nyx/misc/pro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/nyx/misc/pro/UnlockProPatch.kt index a8a1f3a18..65040b32a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/nyx/misc/pro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/nyx/misc/pro/UnlockProPatch.kt @@ -9,10 +9,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("com.awedea.nyx") - val checkProMatch by checkProFingerprint() - execute { - checkProMatch.mutableMethod.addInstructions( + checkProFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt b/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt index a24ba416f..db38e6161 100644 --- a/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/openinghours/misc/fix/crash/FixCrashPatch.kt @@ -17,10 +17,8 @@ val fixCrashPatch = bytecodePatch( ) { compatibleWith("de.simon.openinghours"("1.0")) - val setPlaceMatch by setPlaceFingerprint() - execute { - val indexedInstructions = setPlaceMatch.mutableMethod.instructions.withIndex().toList() + val indexedInstructions = setPlaceFingerprint.method.instructions.withIndex().toList() /** * This function replaces all `checkNotNull` instructions in the integer interval @@ -29,7 +27,7 @@ val fixCrashPatch = bytecodePatch( * the value is indeed null, we jump to a newly created label at `endIndex + 1`. */ fun avoidNullPointerException(startIndex: Int, endIndex: Int) { - val continueLabel = setPlaceMatch.mutableMethod.newLabel(endIndex + 1) + val continueLabel = setPlaceFingerprint.method.newLabel(endIndex + 1) for (index in startIndex..endIndex) { val instruction = indexedInstructions[index].value @@ -41,7 +39,7 @@ val fixCrashPatch = bytecodePatch( val checkNotNullInstruction = instruction as FiveRegisterInstruction val originalRegister = checkNotNullInstruction.registerC - setPlaceMatch.mutableMethod.replaceInstruction( + setPlaceFingerprint.method.replaceInstruction( index, BuilderInstruction21t( Opcode.IF_EQZ, diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/SpoofDeviceIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/SpoofDeviceIdPatch.kt index 152ee8edd..16c84b056 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/SpoofDeviceIdPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/deviceid/SpoofDeviceIdPatch.kt @@ -14,10 +14,8 @@ val getDeviceIdPatch = bytecodePatch( compatibleWith("com.microblink.photomath"("8.37.0")) - val getDeviceIdMatch by getDeviceIdFingerprint() - execute { - getDeviceIdMatch.mutableMethod.replaceInstructions( + getDeviceIdFingerprint.method.replaceInstructions( 0, """ const-string v0, "${Random.nextLong().toString(16)}" diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt index 29e424596..00b47e516 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/detection/signature/SignatureDetectionPatch.kt @@ -8,17 +8,11 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction val signatureDetectionPatch = bytecodePatch( description = "Disables detection of incorrect signature.", ) { - val checkSignatureMatch by checkSignatureFingerprint() execute { - val signatureCheckInstruction = checkSignatureMatch.mutableMethod.getInstruction( - checkSignatureMatch.patternMatch!!.endIndex, - ) - val checkRegister = (signatureCheckInstruction as OneRegisterInstruction).registerA - - checkSignatureMatch.mutableMethod.replaceInstruction( - signatureCheckInstruction.location.index, - "const/4 v$checkRegister, 0x1", - ) + val replacementIndex = checkSignatureFingerprint.patternMatch!!.endIndex + val checkRegister = + checkSignatureFingerprint.method.getInstruction(replacementIndex).registerA + checkSignatureFingerprint.method.replaceInstruction(replacementIndex, "const/4 v$checkRegister, 0x1") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/annoyances/HideUpdatePopupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/annoyances/HideUpdatePopupPatch.kt index 00d0caa18..a3586de1c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/annoyances/HideUpdatePopupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/annoyances/HideUpdatePopupPatch.kt @@ -13,10 +13,8 @@ val hideUpdatePopupPatch = bytecodePatch( compatibleWith("com.microblink.photomath"("8.32.0")) - val hideUpdatePopupMatch by hideUpdatePopupFingerprint() - execute { - hideUpdatePopupMatch.mutableMethod.addInstructions( + hideUpdatePopupFingerprint.method.addInstructions( 2, // Insert after the null check. "return-void", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/bookpoint/EnableBookpointPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/bookpoint/EnableBookpointPatch.kt index 52fa7a09f..6e3da9802 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/bookpoint/EnableBookpointPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/bookpoint/EnableBookpointPatch.kt @@ -6,10 +6,9 @@ import app.revanced.patcher.patch.bytecodePatch val enableBookpointPatch = bytecodePatch( description = "Enables textbook access", ) { - val isBookpointEnabledMatch by isBookpointEnabledFingerprint() execute { - isBookpointEnabledMatch.mutableMethod.replaceInstructions( + isBookpointEnabledFingerprint.method.replaceInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/plus/UnlockPlusPatch.kt b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/plus/UnlockPlusPatch.kt index f62533e0c..8cc80c72e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/plus/UnlockPlusPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/photomath/misc/unlock/plus/UnlockPlusPatch.kt @@ -13,10 +13,8 @@ val unlockPlusPatch = bytecodePatch( compatibleWith("com.microblink.photomath"("8.37.0")) - val isPlusUnlockedMatch by isPlusUnlockedFingerprint() - execute { - isPlusUnlockedMatch.mutableMethod.addInstructions( + isPlusUnlockedFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/piccomafr/misc/SpoofAndroidDeviceIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/piccomafr/misc/SpoofAndroidDeviceIdPatch.kt index 6d9e4dc5c..a2b327135 100644 --- a/patches/src/main/kotlin/app/revanced/patches/piccomafr/misc/SpoofAndroidDeviceIdPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/piccomafr/misc/SpoofAndroidDeviceIdPatch.kt @@ -30,8 +30,6 @@ val spoofAndroidDeviceIdPatch = bytecodePatch( ), ) - val getAndroidIDMatch by getAndroidIdFingerprint() - val androidDeviceId by stringOption( key = "android-device-id", default = "0011223344556677", @@ -41,7 +39,7 @@ val spoofAndroidDeviceIdPatch = bytecodePatch( ) { it!!.matches("[A-Fa-f0-9]{16}".toRegex()) } execute { - getAndroidIDMatch.mutableMethod.addInstructions( + getAndroidIdFingerprint.method.addInstructions( 0, """ const-string v0, "$androidDeviceId" diff --git a/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt index cf4ba8b08..32e02f37a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/piccomafr/tracking/DisableTrackingPatch.kt @@ -33,12 +33,8 @@ val disableTrackingPatch = bytecodePatch( ), ) - val facebookSDKMatch by facebookSDKFingerprint() - val firebaseInstallMatch by firebaseInstallFingerprint() - val appMeasurementMatch by appMeasurementFingerprint() - execute { - facebookSDKMatch.mutableMethod.apply { + facebookSDKFingerprint.method.apply { instructions.filter { instruction -> instruction.opcode == Opcode.CONST_STRING }.forEach { instruction -> @@ -51,7 +47,7 @@ val disableTrackingPatch = bytecodePatch( } } - firebaseInstallMatch.mutableMethod.apply { + firebaseInstallFingerprint.method.apply { instructions.filter { it.opcode == Opcode.CONST_STRING }.filter { @@ -66,6 +62,6 @@ val disableTrackingPatch = bytecodePatch( } } - appMeasurementMatch.mutableMethod.addInstruction(0, "return-void") + appMeasurementFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt index 584d2f48a..29f63e9cf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/pixiv/ads/HideAdsPatch.kt @@ -9,10 +9,8 @@ val hideAdsPatch = bytecodePatch( ) { compatibleWith("jp.pxv.android") - val shouldShowAdsMatch by shouldShowAdsFingerprint() - execute { - shouldShowAdsMatch.mutableMethod.addInstructions( + shouldShowAdsFingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/rar/misc/annoyances/purchasereminder/HidePurchaseReminderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/rar/misc/annoyances/purchasereminder/HidePurchaseReminderPatch.kt index 32957d5bd..885c2400f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/rar/misc/annoyances/purchasereminder/HidePurchaseReminderPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/rar/misc/annoyances/purchasereminder/HidePurchaseReminderPatch.kt @@ -11,9 +11,7 @@ val hidePurchaseReminderPatch = bytecodePatch( ) { compatibleWith("com.rarlab.rar") - val showReminderMatch by showReminderFingerprint() - execute { - showReminderMatch.mutableMethod.addInstruction(0, "return-void") + showReminderFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/banner/HideBannerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/banner/HideBannerPatch.kt index 663eedc1d..62e8d5d84 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/banner/HideBannerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/banner/HideBannerPatch.kt @@ -8,10 +8,10 @@ import app.revanced.patcher.patch.resourcePatch val hideBannerPatch = resourcePatch( description = "Hides banner ads from comments on subreddits.", ) { - execute { context -> + execute { val resourceFilePath = "res/layout/merge_listheader_link_detail.xml" - context.document[resourceFilePath].use { document -> + document(resourceFilePath).use { document -> document.getElementsByTagName("merge").item(0).childNodes.apply { val attributes = arrayOf("height", "width") diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/comments/HideCommentAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/comments/HideCommentAdsPatch.kt index d86b00c9b..e2c53d332 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/comments/HideCommentAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/comments/HideCommentAdsPatch.kt @@ -6,10 +6,9 @@ import app.revanced.patcher.patch.bytecodePatch val hideCommentAdsPatch = bytecodePatch( description = "Removes ads in the comments.", ) { - val hideCommentAdsMatch by hideCommentAdsFingerprint() execute { - hideCommentAdsMatch.mutableMethod.addInstructions( + hideCommentAdsFingerprint.method.addInstructions( 0, """ new-instance v0, Ljava/lang/Object; diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt index fae110042..c3e47f8f8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/ad/general/HideAdsPatch.kt @@ -25,9 +25,6 @@ val hideAdsPatch = bytecodePatch( // This constraint is necessary due to dependency on hideBannerPatch. compatibleWith("com.reddit.frontpage"("2024.17.0")) - val adPostMatch by adPostFingerprint() - val newAdPostMatch by newAdPostFingerprint() - execute { // region Filter promoted ads (does not work in popular or latest feed) @@ -35,7 +32,7 @@ val hideAdsPatch = bytecodePatch( "Lapp/revanced/extension/reddit/patches/FilterPromotedLinksPatch;" + "->filterChildren(Ljava/lang/Iterable;)Ljava/util/List;" - adPostMatch.mutableMethod.apply { + adPostFingerprint.method.apply { val setPostsListChildren = implementation!!.instructions.first { instruction -> if (instruction.opcode != Opcode.IPUT_OBJECT) return@first false @@ -66,7 +63,8 @@ val hideAdsPatch = bytecodePatch( // The new feeds work by inserting posts into lists. // AdElementConverter is conveniently responsible for inserting all feed ads. // By removing the appending instruction no ad posts gets appended to the feed. - val index = newAdPostMatch.method.implementation!!.instructions.indexOfFirst { + + val index = newAdPostFingerprint.originalMethod.implementation!!.instructions.indexOfFirst { if (it.opcode != Opcode.INVOKE_VIRTUAL) return@indexOfFirst false val reference = (it as ReferenceInstruction).reference as MethodReference @@ -74,7 +72,7 @@ val hideAdsPatch = bytecodePatch( reference.name == "add" && reference.definingClass == "Ljava/util/ArrayList;" } - newAdPostMatch.mutableMethod.removeInstruction(index) + newAdPostFingerprint.method.removeInstruction(index) } // endregion diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt index 3eded43b0..d9cfa994f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/baconreader/api/SpoofClientPatch.kt @@ -1,6 +1,6 @@ package app.revanced.patches.reddit.customclients.baconreader.api -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patches.reddit.customclients.spoofClientPatch @@ -12,16 +12,13 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/au "com.onelouder.baconreader.premium", ) - val getAuthorizationUrlMatch by getAuthorizationUrlFingerprint() - val requestTokenMatch by requestTokenFingerprint() - val clientId by clientIdOption execute { - fun Match.patch(replacementString: String) { + fun Fingerprint.patch(replacementString: String) { val clientIdIndex = stringMatches!!.first().index - mutableMethod.apply { + method.apply { val clientIdRegister = getInstruction(clientIdIndex).registerA replaceInstruction( clientIdIndex, @@ -31,9 +28,9 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://baconreader.com/au } // Patch client id in authorization url. - getAuthorizationUrlMatch.patch("client_id=$clientId") + getAuthorizationUrlFingerprint.patch("client_id=$clientId") // Patch client id for access token request. - requestTokenMatch.patch(clientId!!) + requestTokenFingerprint.patch(clientId!!) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/ads/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/ads/DisableAdsPatch.kt index fefe25160..fc5cabd21 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/ads/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/ads/DisableAdsPatch.kt @@ -9,12 +9,9 @@ val disableAdsPatch = bytecodePatch( ) { compatibleWith("com.rubenmayayo.reddit") - val maxMediationMatch by maxMediationFingerprint() - val admobMediationMatch by admobMediationFingerprint() - execute { - arrayOf(maxMediationMatch, admobMediationMatch).forEach { - it.mutableMethod.addInstructions(0, "return-void") + arrayOf(maxMediationFingerprint, admobMediationFingerprint).forEach { fingerprint -> + fingerprint.method.addInstructions(0, "return-void") } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt index 4bfe0ac1d..389facb95 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/api/SpoofClientPatch.kt @@ -6,15 +6,12 @@ import app.revanced.patches.reddit.customclients.spoofClientPatch val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") { clientIdOption -> compatibleWith("com.rubenmayayo.reddit") - val getClientIdMatch by getClientIdFingerprint() - val buildUserAgentMatch by buildUserAgentFingerprint() - val clientId by clientIdOption execute { // region Patch client id. - getClientIdMatch.mutableMethod.addInstructions( + getClientIdFingerprint.method.addInstructions( 0, """ const-string v0, "$clientId" @@ -30,7 +27,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "http://rubenmayayo.com") val platformName = (0..100000).random() val platformParameter = 0 - buildUserAgentMatch.mutableMethod.addInstructions( + buildUserAgentFingerprint.method.addInstructions( 0, "const-string p$platformParameter, \"$platformName\"", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt index 31975f44b..8cb3f5518 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/downloads/FixAudioMissingInDownloadsPatch.kt @@ -12,16 +12,14 @@ val fixAudioMissingInDownloadsPatch = bytecodePatch( ) { compatibleWith("com.rubenmayayo.reddit") - val downloadAudioMatch by downloadAudioFingerprint() - execute { val endpointReplacements = mapOf( "/DASH_audio.mp4" to "/DASH_AUDIO_128.mp4", "/audio" to "/DASH_AUDIO_64.mp4", ) - downloadAudioMatch.stringMatches!!.forEach { match -> - downloadAudioMatch.mutableMethod.apply { + downloadAudioFingerprint.method.apply { + downloadAudioFingerprint.stringMatches!!.forEach { match -> val replacement = endpointReplacements[match.string] val register = getInstruction(match.index).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch.kt index b35a85320..076221e47 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/boostforreddit/fix/slink/FixSLinksPatch.kt @@ -17,13 +17,10 @@ val fixSlinksPatch = fixSLinksPatch( ) { compatibleWith("com.rubenmayayo.reddit") - val handleNavigationMatch by handleNavigationFingerprint() - val setAccessTokenMatch by getOAuthAccessTokenFingerprint() - execute { // region Patch navigation handler. - handleNavigationMatch.mutableMethod.apply { + handleNavigationFingerprint.method.apply { val urlRegister = "p1" val tempRegister = "v1" @@ -43,7 +40,7 @@ val fixSlinksPatch = fixSLinksPatch( // region Patch set access token. - setAccessTokenMatch.mutableMethod.addInstruction( + getOAuthAccessTokenFingerprint.method.addInstruction( 3, "invoke-static { v0 }, $EXTENSION_CLASS_DESCRIPTOR->$SET_ACCESS_TOKEN_METHOD", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt index 5094c1864..d19ddbfed 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/api/SpoofClientPatch.kt @@ -10,12 +10,10 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodImplementation val spoofClientPatch = spoofClientPatch(redirectUri = "infinity://localhost") { clientIdOption -> compatibleWith("ml.docilealligator.infinityforreddit") - val apiUtilsMatch by apiUtilsFingerprint() - val clientId by clientIdOption execute { - apiUtilsMatch.mutableClass.methods.apply { + apiUtilsFingerprint.classDef.methods.apply { val getClientIdMethod = single { it.name == "getId" }.also(::remove) val newGetClientIdMethod = ImmutableMethod( diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/subscription/UnlockSubscriptionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/subscription/UnlockSubscriptionPatch.kt index 1c427c967..ab9b07c1b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/subscription/UnlockSubscriptionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/infinityforreddit/subscription/UnlockSubscriptionPatch.kt @@ -13,10 +13,10 @@ val unlockSubscriptionPatch = bytecodePatch( compatibleWith("ml.docilealligator.infinityforreddit") - startSubscriptionActivityFingerprint() - billingClientOnServiceConnectedFingerprint() - execute { - setOf(startSubscriptionActivityFingerprint, billingClientOnServiceConnectedFingerprint).returnEarly() + setOf( + startSubscriptionActivityFingerprint, + billingClientOnServiceConnectedFingerprint, + ).forEach { it.method.returnEarly() } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/ads/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/ads/DisableAdsPatch.kt index c6498ee00..0c7508758 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/ads/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/ads/DisableAdsPatch.kt @@ -12,10 +12,8 @@ val disableAdsPatch = bytecodePatch( compatibleWith("o.o.joey") - val isAdFreeUserMatch by isAdFreeUserFingerprint() - execute { - isAdFreeUserMatch.mutableMethod.addInstructions( + isAdFreeUserFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt index d03c6efe0..44d7f6e3e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/api/SpoofClientPatch.kt @@ -14,15 +14,12 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "https://127.0.0.1:65023/a "o.o.joey.dev", ) - val getClientIdMatch by getClientIdFingerprint() - val authUtilityUserAgentMatch by authUtilityUserAgentFingerprint() - val clientId by clientIdOption execute { // region Patch client id. - getClientIdMatch.mutableMethod.addInstructions( + getClientIdFingerprint.method.addInstructions( 0, """ const-string v0, "$clientId" @@ -38,7 +35,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "https://127.0.0.1:65023/a val randomName = (0..100000).random() val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" - authUtilityUserAgentMatch.mutableMethod.replaceInstructions( + authUtilityUserAgentFingerprint.method.replaceInstructions( 0, """ const-string v0, "$userAgent" diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/detection/piracy/DisablePiracyDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/detection/piracy/DisablePiracyDetectionPatch.kt index b8d7889fb..a6871dbc0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/detection/piracy/DisablePiracyDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/joeyforreddit/detection/piracy/DisablePiracyDetectionPatch.kt @@ -4,9 +4,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.patch.bytecodePatch val disablePiracyDetectionPatch = bytecodePatch { - val piracyDetectionMatch by piracyDetectionFingerprint() execute { - piracyDetectionMatch.mutableMethod.addInstruction(0, "return-void") + piracyDetectionFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt index 9f7d5a57e..440b1fe2a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/redditisfun/api/SpoofClientPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.reddit.customclients.redditisfun.api +import app.revanced.patcher.Fingerprint import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -16,10 +17,6 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl "com.andrewshu.android.redditdonation", ) - val buildAuthorizationStringMatch by buildAuthorizationStringFingerprint() - val basicAuthorizationMatch by basicAuthorizationFingerprint() - val getUserAgentMatch by getUserAgentFingerprint() - val clientId by clientIdOption execute { @@ -33,10 +30,10 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl * @param getReplacementIndex A function that returns the index of the instruction to replace * using the [Match.StringMatch] list from the [Match]. */ - fun Match.replaceWith( + fun Fingerprint.replaceWith( string: String, getReplacementIndex: List.() -> Int, - ) = mutableMethod.apply { + ) = method.apply { val replacementIndex = stringMatches!!.getReplacementIndex() val clientIdRegister = getInstruction(replacementIndex).registerA @@ -44,10 +41,10 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl } // Patch OAuth authorization. - buildAuthorizationStringMatch.replaceWith(clientId!!) { first().index + 4 } + buildAuthorizationStringFingerprint.replaceWith(clientId!!) { first().index + 4 } // Path basic authorization. - basicAuthorizationMatch.replaceWith("$clientId:") { last().index + 7 } + basicAuthorizationFingerprint.replaceWith("$clientId:") { last().index + 7 } // endregion @@ -57,7 +54,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl val randomName = (0..100000).random() val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" - getUserAgentMatch.mutableMethod.addInstructions( + getUserAgentFingerprint.method.addInstructions( 0, """ const-string v0, "$userAgent" @@ -71,7 +68,7 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "redditisfun://auth") { cl // Reddit messed up and does not append a redirect uri to the authorization url to old.reddit.com/login. // Replace old.reddit.com with ssl.reddit.com to fix this. - buildAuthorizationStringMatch.mutableMethod.apply { + buildAuthorizationStringFingerprint.method.apply { val index = indexOfFirstInstructionOrThrow { getReference()?.contains("old.reddit.com") == true } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt index d3ad4b9d2..854b7cfa5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/relayforreddit/api/SpoofClientPatch.kt @@ -15,29 +15,22 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "dbrady://relay") { "reddit.news", ) - val loginActivityClientIdMatch by loginActivityClientIdFingerprint() - val getLoggedInBearerTokenMatch by getLoggedInBearerTokenFingerprint() - val getLoggedOutBearerTokenMatch by getLoggedOutBearerTokenFingerprint() - val getRefreshTokenMatch by getRefreshTokenFingerprint() - val setRemoteConfigMatch by setRemoteConfigFingerprint() - val redditCheckDisableAPIMatch by redditCheckDisableAPIFingerprint() - val clientId by it execute { // region Patch client id. setOf( - loginActivityClientIdMatch, - getLoggedInBearerTokenMatch, - getLoggedOutBearerTokenMatch, - getRefreshTokenMatch, - ).forEach { match -> - val clientIdIndex = match.stringMatches!!.first().index - match.mutableMethod.apply { + loginActivityClientIdFingerprint, + getLoggedInBearerTokenFingerprint, + getLoggedOutBearerTokenFingerprint, + getRefreshTokenFingerprint, + ).forEach { fingerprint -> + val clientIdIndex = fingerprint.stringMatches!!.first().index + fingerprint.method.apply { val clientIdRegister = getInstruction(clientIdIndex).registerA - match.mutableMethod.replaceInstruction( + fingerprint.method.replaceInstruction( clientIdIndex, "const-string v$clientIdRegister, \"$clientId\"", ) @@ -49,12 +42,12 @@ val spoofClientPatch = spoofClientPatch(redirectUri = "dbrady://relay") { // region Patch miscellaneous. // Do not load remote config which disables OAuth login remotely. - setRemoteConfigMatch.mutableMethod.addInstructions(0, "return-void") + setRemoteConfigFingerprint.method.addInstructions(0, "return-void") // Prevent OAuth login being disabled remotely. - val checkIsOAuthRequestIndex = redditCheckDisableAPIMatch.patternMatch!!.startIndex + val checkIsOAuthRequestIndex = redditCheckDisableAPIFingerprint.patternMatch!!.startIndex - redditCheckDisableAPIMatch.mutableMethod.apply { + redditCheckDisableAPIFingerprint.method.apply { val returnNextChain = getInstruction(checkIsOAuthRequestIndex).target replaceInstruction(checkIsOAuthRequestIndex, BuilderInstruction10t(Opcode.GOTO, returnNextChain)) } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt index 00b6f54fc..62f0ccf38 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/slide/api/SpoofClientPatch.kt @@ -6,12 +6,10 @@ import app.revanced.patches.reddit.customclients.spoofClientPatch val spoofClientPatch = spoofClientPatch(redirectUri = "http://www.ccrama.me") { clientIdOption -> compatibleWith("me.ccrama.redditslide") - val getClientIdMatch by getClientIdFingerprint() - val clientId by clientIdOption execute { - getClientIdMatch.mutableMethod.addInstructions( + getClientIdFingerprint.method.addInstructions( 0, """ const-string v0, "$clientId" diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/ads/DisableAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/ads/DisableAdsPatch.kt index d9b5b9fd4..f210a6adb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/ads/DisableAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/ads/DisableAdsPatch.kt @@ -7,10 +7,8 @@ import app.revanced.util.returnEarly fun disableAdsPatch(block: BytecodePatchBuilder.() -> Unit = {}) = bytecodePatch( name = "Disable ads", ) { - isAdsEnabledFingerprint() - execute { - isAdsEnabledFingerprint.returnEarly() + isAdsEnabledFingerprint.method.returnEarly() } block() diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt index a4c70539b..fa797c693 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/detection/piracy/DisablePiracyDetectionPatch.kt @@ -6,11 +6,10 @@ import app.revanced.patcher.patch.bytecodePatch val disablePiracyDetectionPatch = bytecodePatch( description = "Disables detection of modified versions.", ) { - val piracyDetectionMatch by piracyDetectionFingerprint() execute { // Do not throw an error if the fingerprint is not resolved. // This is fine because new versions of the target app do not need this patch. - piracyDetectionMatch.mutableMethod.addInstruction(0, "return-void") + piracyDetectionFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/annoyances/startup/DisableSyncForLemmyBottomSheetPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/annoyances/startup/DisableSyncForLemmyBottomSheetPatch.kt index 85d51573c..0bfbe74d0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/annoyances/startup/DisableSyncForLemmyBottomSheetPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/annoyances/startup/DisableSyncForLemmyBottomSheetPatch.kt @@ -14,10 +14,8 @@ val disableSyncForLemmyBottomSheetPatch = bytecodePatch( "com.laurencedawson.reddit_sync.dev"(), // Version unknown. ) - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - execute { - mainActivityOnCreateMatch.mutableMethod.apply { + mainActivityOnCreateFingerprint.method.apply { val showBottomSheetIndex = implementation!!.instructions.lastIndex - 1 removeInstruction(showBottomSheetIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt index 86f27b134..3f9cbf9e9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/api/SpoofClientPatch.kt @@ -5,7 +5,6 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patches.reddit.customclients.spoofClientPatch import app.revanced.patches.reddit.customclients.sync.detection.piracy.disablePiracyDetectionPatch -import app.revanced.util.matchOrThrow 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.reference.StringReference @@ -22,18 +21,12 @@ val spoofClientPatch = spoofClientPatch( "com.laurencedawson.reddit_sync.dev", ) - val imgurImageAPIMatch by imgurImageAPIFingerprint() - val getAuthorizationStringMatch by getAuthorizationStringFingerprint() - val getUserAgentMatch by getUserAgentFingerprint() - val clientId by clientIdOption - execute { context -> + execute { // region Patch client id. - getBearerTokenFingerprint.apply { - match(context, getAuthorizationStringMatch.classDef) - }.matchOrThrow.mutableMethod.apply { + getBearerTokenFingerprint.match(getAuthorizationStringFingerprint.originalClassDef).method.apply { val auth = Base64.getEncoder().encodeToString("$clientId:".toByteArray(Charsets.UTF_8)) addInstructions( 0, @@ -43,9 +36,9 @@ val spoofClientPatch = spoofClientPatch( """, ) val occurrenceIndex = - getAuthorizationStringMatch.stringMatches!!.first().index + getAuthorizationStringFingerprint.stringMatches!!.first().index - getAuthorizationStringMatch.mutableMethod.apply { + getAuthorizationStringFingerprint.method.apply { val authorizationStringInstruction = getInstruction(occurrenceIndex) val targetRegister = (authorizationStringInstruction as OneRegisterInstruction).registerA val reference = authorizationStringInstruction.reference as StringReference @@ -70,7 +63,7 @@ val spoofClientPatch = spoofClientPatch( val randomName = (0..100000).random() val userAgent = "$randomName:app.revanced.$randomName:v1.0.0 (by /u/revanced)" - imgurImageAPIMatch.mutableMethod.replaceInstruction( + imgurImageAPIFingerprint.method.replaceInstruction( 0, """ const-string v0, "$userAgent" @@ -82,8 +75,8 @@ val spoofClientPatch = spoofClientPatch( // region Patch Imgur API URL. - val apiUrlIndex = getUserAgentMatch.stringMatches!!.first().index - getUserAgentMatch.mutableMethod.replaceInstruction( + val apiUrlIndex = getUserAgentFingerprint.stringMatches!!.first().index + getUserAgentFingerprint.method.replaceInstruction( apiUrlIndex, "const-string v1, \"https://api.imgur.com/3/image\"", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/slink/FixSLinksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/slink/FixSLinksPatch.kt index 80da3f6bc..a640936a2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/slink/FixSLinksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/slink/FixSLinksPatch.kt @@ -6,6 +6,8 @@ import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.reddit.customclients.RESOLVE_S_LINK_METHOD import app.revanced.patches.reddit.customclients.SET_ACCESS_TOKEN_METHOD +import app.revanced.patches.reddit.customclients.boostforreddit.fix.slink.getOAuthAccessTokenFingerprint +import app.revanced.patches.reddit.customclients.boostforreddit.fix.slink.handleNavigationFingerprint import app.revanced.patches.reddit.customclients.fixSLinksPatch import app.revanced.patches.reddit.customclients.sync.syncforreddit.extension.sharedExtensionPatch @@ -21,13 +23,10 @@ val fixSLinksPatch = fixSLinksPatch( "com.laurencedawson.reddit_sync.dev", ) - val handleNavigationMatch by linkHelperOpenLinkFingerprint() - val setAccessTokenMatch by setAuthorizationHeaderFingerprint() - execute { // region Patch navigation handler. - handleNavigationMatch.mutableMethod.apply { + handleNavigationFingerprint.method.apply { val urlRegister = "p3" val tempRegister = "v2" @@ -47,7 +46,7 @@ val fixSLinksPatch = fixSLinksPatch( // region Patch set access token. - setAccessTokenMatch.mutableMethod.addInstruction( + getOAuthAccessTokenFingerprint.method.addInstruction( 0, "invoke-static { p0 }, $EXTENSION_CLASS_DESCRIPTOR->$SET_ACCESS_TOKEN_METHOD", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/user/UseUserEndpointPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/user/UseUserEndpointPatch.kt index a53007045..2d46c284c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/user/UseUserEndpointPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/sync/syncforreddit/fix/user/UseUserEndpointPatch.kt @@ -20,22 +20,17 @@ val useUserEndpointPatch = bytecodePatch( "com.laurencedawson.reddit_sync.dev", ) - val oAuthFriendRequestMatch by oAuthFriendRequestFingerprint() - val oAuthSubredditInfoRequestConstructorMatch by oAuthSubredditInfoRequestConstructorFingerprint() - val oAuthSubredditInfoRequestHelperMatch by oAuthSubredditInfoRequestHelperFingerprint() - val oAuthUnfriendRequestMatch by oAuthUnfriendRequestFingerprint() - val oAuthUserIdRequestMatch by oAuthUserIdRequestFingerprint() - val oAuthUserInfoRequestMatch by oAuthUserInfoRequestFingerprint() - execute { arrayOf( - oAuthFriendRequestMatch, - oAuthSubredditInfoRequestConstructorMatch, - oAuthSubredditInfoRequestHelperMatch, - oAuthUnfriendRequestMatch, - oAuthUserIdRequestMatch, - oAuthUserInfoRequestMatch, - ).map { it.stringMatches!!.first().index to it.mutableMethod }.forEach { (userPathStringIndex, method) -> + oAuthFriendRequestFingerprint, + oAuthSubredditInfoRequestConstructorFingerprint, + oAuthSubredditInfoRequestHelperFingerprint, + oAuthUnfriendRequestFingerprint, + oAuthUserIdRequestFingerprint, + oAuthUserInfoRequestFingerprint, + ).map { fingerprint -> + fingerprint.stringMatches!!.first().index to fingerprint.method + }.forEach { (userPathStringIndex, method) -> val userPathStringInstruction = method.getInstruction(userPathStringIndex) val userPathStringRegister = userPathStringInstruction.registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch.kt index a43e13fe6..9990af83f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/customclients/syncforreddit/fix/video/FixVideoDownloadsPatch.kt @@ -23,16 +23,15 @@ val fixVideoDownloadsPatch = bytecodePatch( "com.laurencedawson.reddit_sync.dev", ) - val parseRedditVideoNetworkResponseMatch by parseRedditVideoNetworkResponseFingerprint() - execute { - val scanResult = parseRedditVideoNetworkResponseMatch.patternMatch!! + val scanResult = parseRedditVideoNetworkResponseFingerprint.patternMatch!! val newInstanceIndex = scanResult.startIndex val invokeDirectIndex = scanResult.endIndex - 1 - val buildResponseInstruction = parseRedditVideoNetworkResponseMatch.mutableMethod.getInstruction(invokeDirectIndex) + val buildResponseInstruction = + parseRedditVideoNetworkResponseFingerprint.method.getInstruction(invokeDirectIndex) - parseRedditVideoNetworkResponseMatch.mutableMethod.addInstructions( + parseRedditVideoNetworkResponseFingerprint.method.addInstructions( newInstanceIndex + 1, """ # Get byte array from response. diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/DisableScreenshotPopupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/DisableScreenshotPopupPatch.kt index 116205a34..84ee7e2fd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/DisableScreenshotPopupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/disablescreenshotpopup/DisableScreenshotPopupPatch.kt @@ -10,9 +10,7 @@ val disableScreenshotPopupPatch = bytecodePatch( ) { compatibleWith("com.reddit.frontpage") - val disableScreenshotPopupMatch by disableScreenshotPopupFingerprint() - execute { - disableScreenshotPopupMatch.mutableMethod.addInstruction(0, "return-void") + disableScreenshotPopupFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/UnlockPremiumIconPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/UnlockPremiumIconPatch.kt index 8a3a0f810..bde2b52b9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/UnlockPremiumIconPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/layout/premiumicon/UnlockPremiumIconPatch.kt @@ -10,10 +10,8 @@ val unlockPremiumIconPatch = bytecodePatch( ) { compatibleWith("com.reddit.frontpage") - val hasPremiumIconAccessMatch by hasPremiumIconAccessFingerprint() - execute { - hasPremiumIconAccessMatch.mutableMethod.addInstructions( + hasPremiumIconAccessFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt b/patches/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt index fb14ca80c..26ed42660 100644 --- a/patches/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/reddit/misc/tracking/url/SanitizeUrlQueryPatch.kt @@ -10,10 +10,8 @@ val sanitizeUrlQueryPatch = bytecodePatch( ) { compatibleWith("com.reddit.frontpage") - val shareLinkFormatterMatch by shareLinkFormatterFingerprint() - execute { - shareLinkFormatterMatch.mutableMethod.addInstructions( + shareLinkFormatterFingerprint.method.addInstructions( 0, "return-object p0", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/serviceportalbund/detection/root/RootDetectionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/serviceportalbund/detection/root/RootDetectionPatch.kt index 40723ca27..43ebaa19f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/serviceportalbund/detection/root/RootDetectionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/serviceportalbund/detection/root/RootDetectionPatch.kt @@ -10,9 +10,7 @@ val rootDetectionPatch = bytecodePatch( ) { compatibleWith("at.gv.bka.serviceportal") - val rootDetectionMatch by rootDetectionFingerprint() - execute { - rootDetectionMatch.mutableMethod.addInstruction(0, "return-void") + rootDetectionFingerprint.method.addInstruction(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/checks/BaseCheckEnvironmentPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/checks/BaseCheckEnvironmentPatch.kt index 8c3066c91..3ede5d48a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/checks/BaseCheckEnvironmentPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/checks/BaseCheckEnvironmentPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.shared.misc.checks import android.os.Build.* import app.revanced.patcher.Fingerprint -import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.Patch import app.revanced.patcher.patch.bytecodePatch @@ -35,20 +34,24 @@ fun checkEnvironmentPatch( addResourcesPatch, ) - val patchInfoMatch by patchInfoFingerprint() - val patchInfoBuildMatch by patchInfoBuildFingerprint() - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - execute { addResources("shared", "misc.checks.checkEnvironmentPatch") fun setPatchInfo() { - patchInfoMatch.setClassFields( + fun Fingerprint.setClassFields(vararg fieldNameValues: Pair) { + val fieldNameValueMap = mapOf(*fieldNameValues) + + classDef.fields.forEach { field -> + field.initialValue = fieldNameValueMap[field.name] ?: return@forEach + } + } + + patchInfoFingerprint.setClassFields( "PATCH_TIME" to System.currentTimeMillis().encoded, ) fun setBuildInfo() { - patchInfoBuildMatch.setClassFields( + patchInfoBuildFingerprint.setClassFields( "PATCH_BOARD" to BOARD.encodedAndHashed, "PATCH_BOOTLOADER" to BOOTLOADER.encodedAndHashed, "PATCH_BRAND" to BRAND.encodedAndHashed, @@ -79,7 +82,7 @@ fun checkEnvironmentPatch( } } - fun invokeCheck() = mainActivityOnCreateMatch.mutableMethod?.addInstructions( + fun invokeCheck() = mainActivityOnCreateFingerprint.method.addInstructions( 0, "invoke-static/range { p0 .. p0 },$EXTENSION_CLASS_DESCRIPTOR->check(Landroid/app/Activity;)V", ) @@ -101,11 +104,3 @@ private val String.encodedAndHashed ) private val Long.encoded get() = MutableLongEncodedValue(ImmutableLongEncodedValue(this)) - -private fun Match.setClassFields(vararg fieldNameValues: Pair) { - val fieldNameValueMap = mapOf(*fieldNameValues) - - mutableClass.fields.forEach { field -> - field.initialValue = fieldNameValueMap[field.name] ?: return@forEach - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt index a53102f9e..33c3ddf15 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/extension/SharedExtensionPatch.kt @@ -5,9 +5,9 @@ import app.revanced.patcher.FingerprintBuilder import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.fingerprint +import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.matchOrThrow import com.android.tools.smali.dexlib2.iface.Method import java.net.URLDecoder import java.util.jar.JarFile @@ -19,11 +19,8 @@ fun sharedExtensionPatch( ) = bytecodePatch { extendWith("extensions/shared.rve") - val revancedUtilsPatchesVersionMatch by revancedUtilsPatchesVersionFingerprint() - hooks.forEach { it.fingerprint() } - - execute { context -> - if (context.classBy { EXTENSION_CLASS_DESCRIPTOR in it.type } == null) { + execute { + if (classBy { EXTENSION_CLASS_DESCRIPTOR in it.type } == null) { throw PatchException( "Shared extension has not been merged yet. This patch can not succeed without merging it.", ) @@ -32,7 +29,7 @@ fun sharedExtensionPatch( hooks.forEach { hook -> hook(EXTENSION_CLASS_DESCRIPTOR) } // Modify Utils method to include the patches release version. - revancedUtilsPatchesVersionMatch.mutableMethod.apply { + revancedUtilsPatchesVersionFingerprint.method.apply { /** * @return The file path for the jar this classfile is contained inside. */ @@ -79,17 +76,16 @@ class ExtensionHook internal constructor( private val insertIndexResolver: ((Method) -> Int), private val contextRegisterResolver: (Method) -> String, ) { + context(BytecodePatchContext) operator fun invoke(extensionClassDescriptor: String) { - fingerprint.matchOrThrow.mutableMethod.let { method -> - val insertIndex = insertIndexResolver(method) - val contextRegister = contextRegisterResolver(method) + val insertIndex = insertIndexResolver(fingerprint.method) + val contextRegister = contextRegisterResolver(fingerprint.method) - method.addInstruction( - insertIndex, - "invoke-static/range { $contextRegister .. $contextRegister }, " + - "$extensionClassDescriptor->setContext(Landroid/content/Context;)V", - ) - } + fingerprint.method.addInstruction( + insertIndex, + "invoke-static/range { $contextRegister .. $contextRegister }, " + + "$extensionClassDescriptor->setContext(Landroid/content/Context;)V", + ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch.kt index 182e3bd13..a01839c10 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/fix/verticalscroll/VerticalScrollPatch.kt @@ -8,11 +8,10 @@ import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction val verticalScrollPatch = bytecodePatch( description = "Fixes issues with refreshing the feed when the first component is of type EmptyComponent.", ) { - val canScrollVerticallyMatch by canScrollVerticallyFingerprint() execute { - canScrollVerticallyMatch.mutableMethod.apply { - val moveResultIndex = canScrollVerticallyMatch.patternMatch!!.endIndex + canScrollVerticallyFingerprint.method.apply { + val moveResultIndex = canScrollVerticallyFingerprint.patternMatch!!.endIndex val moveResultRegister = getInstruction(moveResultIndex).registerA val insertIndex = moveResultIndex + 1 diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt index c338385bf..0e54bb691 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/gms/GmsCoreSupportPatch.kt @@ -12,10 +12,7 @@ import app.revanced.patches.all.misc.resources.addResourcesPatch import app.revanced.patches.shared.misc.gms.Constants.ACTIONS import app.revanced.patches.shared.misc.gms.Constants.AUTHORITIES import app.revanced.patches.shared.misc.gms.Constants.PERMISSIONS -import app.revanced.util.exception -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstruction -import app.revanced.util.returnEarly +import app.revanced.util.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.builder.instruction.BuilderInstruction21c import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -52,7 +49,7 @@ fun gmsCoreSupportPatch( mainActivityOnCreateFingerprint: Fingerprint, extensionPatch: Patch<*>, gmsCoreSupportResourcePatchFactory: (gmsCoreVendorGroupIdOption: Option) -> Patch<*>, - executeBlock: Patch.(BytecodePatchContext) -> Unit = {}, + executeBlock: BytecodePatchContext.() -> Unit = {}, block: BytecodePatchBuilder.() -> Unit = {}, ) = bytecodePatch( name = "GmsCore support", @@ -79,17 +76,10 @@ fun gmsCoreSupportPatch( val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption - val gmsCoreSupportMatch by gmsCoreSupportFingerprint() - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - primeMethodFingerprint?.invoke() - googlePlayUtilityFingerprint() - serviceCheckFingerprint() - earlyReturnFingerprints.forEach { it() } - - execute { context -> - fun transformStringReferences(transform: (str: String) -> String?) = context.classes.forEach { + execute { + fun transformStringReferences(transform: (str: String) -> String?) = classes.forEach { val mutableClass by lazy { - context.proxy(it).mutableClass + proxy(it).mutableClass } it.methods.forEach classLoop@{ method -> @@ -169,7 +159,7 @@ fun gmsCoreSupportPatch( } fun transformPrimeMethod(packageName: String) { - primeMethodFingerprint!!.match?.mutableMethod?.apply { + primeMethodFingerprint!!.method.apply { var register = 2 val index = instructions.indexOfFirst { @@ -180,7 +170,7 @@ fun gmsCoreSupportPatch( } replaceInstruction(index, "const-string v$register, \"$packageName\"") - } ?: throw primeMethodFingerprint.exception + } } // endregion @@ -205,16 +195,16 @@ fun gmsCoreSupportPatch( primeMethodFingerprint?.let { transformPrimeMethod(packageName) } // Return these methods early to prevent the app from crashing. - earlyReturnFingerprints.returnEarly() - serviceCheckFingerprint.returnEarly() + earlyReturnFingerprints.forEach { it.method.returnEarly() } + serviceCheckFingerprint.method.returnEarly() // Google Play Utility is not present in all apps, so we need to check if it's present. - if (googlePlayUtilityFingerprint.match != null) { - googlePlayUtilityFingerprint.returnEarly() + if (googlePlayUtilityFingerprint.methodOrNull != null) { + googlePlayUtilityFingerprint.method.returnEarly() } // Verify GmsCore is installed and whitelisted for power optimizations and background usage. - mainActivityOnCreateMatch.mutableMethod.apply { + mainActivityOnCreateFingerprint.method.apply { // Temporary fix for patches with an extension patch that hook the onCreate method as well. val setContextIndex = indexOfFirstInstruction { val reference = getReference() ?: return@indexOfFirstInstruction false @@ -231,11 +221,11 @@ fun gmsCoreSupportPatch( } // Change the vendor of GmsCore in the extension. - gmsCoreSupportMatch.mutableClass.methods + gmsCoreSupportFingerprint.classDef.methods .single { it.name == GET_GMS_CORE_VENDOR_GROUP_ID_METHOD_NAME } .replaceInstruction(0, "const-string v0, \"$gmsCoreVendorGroupId\"") - executeBlock(context) + executeBlock() } block() @@ -525,7 +515,7 @@ fun gmsCoreSupportResourcePatch( toPackageName: String, spoofedPackageSignature: String, gmsCoreVendorGroupIdOption: Option, - executeBlock: Patch.(ResourcePatchContext) -> Unit = {}, + executeBlock: ResourcePatchContext.() -> Unit = {}, block: ResourcePatchBuilder.() -> Unit = {}, ) = resourcePatch { dependsOn( @@ -535,7 +525,7 @@ fun gmsCoreSupportResourcePatch( val gmsCoreVendorGroupId by gmsCoreVendorGroupIdOption - execute { context -> + execute { addResources("shared", "misc.gms.gmsCoreSupportResourcePatch") /** @@ -551,7 +541,7 @@ fun gmsCoreSupportResourcePatch( appendChild(child) } - context.document["AndroidManifest.xml"].use { document -> + document("AndroidManifest.xml").use { document -> val applicationNode = document .getElementsByTagName("application") @@ -593,7 +583,7 @@ fun gmsCoreSupportResourcePatch( "" to "", ) - val manifest = context["AndroidManifest.xml"] + val manifest = get("AndroidManifest.xml") manifest.writeText( transformations.entries.fold(manifest.readText()) { acc, (from, to) -> acc.replace( @@ -607,7 +597,7 @@ fun gmsCoreSupportResourcePatch( patchManifest() addSpoofingMetadata() - executeBlock(context) + executeBlock() } block() diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/hex/HexPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/hex/HexPatch.kt index e372d926c..d361a5571 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/hex/HexPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/hex/HexPatch.kt @@ -10,10 +10,10 @@ import kotlin.math.max // Without the function, the replacements would be evaluated at the time of patch creation. // This isn't possible because the delegated property is not accessible at that time. fun hexPatch(replacementsSupplier: () -> Set) = rawResourcePatch { - execute { context -> + execute { replacementsSupplier().groupBy { it.targetFilePath }.forEach { (targetFilePath, replacements) -> val targetFile = try { - context[targetFilePath, true] + get(targetFilePath, true) } catch (e: Exception) { throw PatchException("Could not find target file: $targetFilePath") } diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt index ef198b491..4368bace0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/mapping/ResourceMappingPatch.kt @@ -17,13 +17,13 @@ val resourceMappingPatch = resourcePatch { val resourceMappings = Collections.synchronizedList(mutableListOf()) - execute { context -> + execute { // Save the file in memory to concurrently read from it. - val resourceXmlFile = context["res/values/public.xml"].readBytes() + val resourceXmlFile = get("res/values/public.xml").readBytes() for (threadIndex in 0 until threadCount) { threadPoolExecutor.execute thread@{ - context.document[resourceXmlFile.inputStream()].use { document -> + document(resourceXmlFile.inputStream()).use { document -> val resources = document.documentElement.childNodes val resourcesLength = resources.length diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/settings/SettingsPatch.kt index ea14b4a7b..7c343961c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/settings/SettingsPatch.kt @@ -25,8 +25,8 @@ fun settingsPatch( ) = resourcePatch { dependsOn(addResourcesPatch) - execute { context -> - context.copyResources( + execute { + copyResources( "settings", ResourceGroup("xml", "revanced_prefs.xml"), ) @@ -34,7 +34,7 @@ fun settingsPatch( addResources("shared", "misc.settings.settingsResourcePatch") } - finalize { context -> + finalize { fun Node.addPreference(preference: BasePreference, prepend: Boolean = false) { preference.serialize(ownerDocument) { resource -> // TODO: Currently, resources can only be added to "values", which may not be the correct place. @@ -47,13 +47,13 @@ fun settingsPatch( // Add the root preference to an existing fragment if needed. rootPreference?.let { (intentPreference, fragment) -> - context.document["res/xml/$fragment.xml"].use { document -> + document("res/xml/$fragment.xml").use { document -> document.getNode("PreferenceScreen").addPreference(intentPreference, true) } } // Add all preferences to the ReVanced fragment. - context.document["res/xml/revanced_prefs.xml"].use { document -> + document("res/xml/revanced_prefs.xml").use { document -> val revancedPreferenceScreenNode = document.getNode("PreferenceScreen") preferences.forEach { revancedPreferenceScreenNode.addPreference(it) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/RemoveFileSizeLimitPatch.kt b/patches/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/RemoveFileSizeLimitPatch.kt index 39a8ae64f..7ef509301 100644 --- a/patches/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/RemoveFileSizeLimitPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/solidexplorer2/functionality/filesize/RemoveFileSizeLimitPatch.kt @@ -12,11 +12,9 @@ val removeFileSizeLimitPatch = bytecodePatch( ) { compatibleWith("pl.solidexplorer2") - val onReadyMatch by onReadyFingerprint() - execute { - onReadyMatch.mutableMethod.apply { - val cmpIndex = onReadyMatch.patternMatch!!.startIndex + 1 + onReadyFingerprint.method.apply { + val cmpIndex = onReadyFingerprint.patternMatch!!.startIndex + 1 val cmpResultRegister = getInstruction(cmpIndex).registerA replaceInstruction(cmpIndex, "const/4 v$cmpResultRegister, 0x0") diff --git a/patches/src/main/kotlin/app/revanced/patches/songpal/badge/BadgeTabPatch.kt b/patches/src/main/kotlin/app/revanced/patches/songpal/badge/BadgeTabPatch.kt index d93b31af4..f37ebe71e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/songpal/badge/BadgeTabPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/songpal/badge/BadgeTabPatch.kt @@ -13,12 +13,10 @@ val badgeTabPatch = bytecodePatch( ) { compatibleWith("com.sony.songpal.mdr") - val createTabsMatch by createTabsFingerprint() - val arrayTabs = listOf("Log", "HealthCare") execute { - createTabsMatch.mutableMethod.apply { + createTabsFingerprint.method.apply { removeInstructions(0, 2) val arrayRegister = 0 diff --git a/patches/src/main/kotlin/app/revanced/patches/songpal/badge/RemoveNotificationBadgePatch.kt b/patches/src/main/kotlin/app/revanced/patches/songpal/badge/RemoveNotificationBadgePatch.kt index 4f59c5f6a..eae07fc91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/songpal/badge/RemoveNotificationBadgePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/songpal/badge/RemoveNotificationBadgePatch.kt @@ -10,9 +10,7 @@ val removeNotificationBadgePatch = bytecodePatch( ) { compatibleWith("com.sony.songpal.mdr"("10.1.0")) - val showNotificationMatch by showNotificationFingerprint() - execute { - showNotificationMatch.mutableMethod.addInstructions(0, "return-void") + showNotificationFingerprint.method.addInstructions(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/ad/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/ad/HideAdsPatch.kt index 19d692863..3e56ed727 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/ad/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/ad/HideAdsPatch.kt @@ -14,16 +14,12 @@ val hideAdsPatch = bytecodePatch( ) { compatibleWith("com.soundcloud.android") - val featureConstructorMatch by featureConstructorFingerprint() - val userConsumerPlanConstructorMatch by userConsumerPlanConstructorFingerprint() - val interceptMatch by interceptFingerprint() - execute { // Enable a preset feature to disable audio ads by modifying the JSON server response. // This method is the constructor of a class representing a "Feature" object parsed from JSON data. // p1 is the name of the feature. // p2 is true if the feature is enabled, false otherwise. - featureConstructorMatch.mutableMethod.apply { + featureConstructorFingerprint.method.apply { val afterCheckNotNullIndex = 2 addInstructionsWithLabels( afterCheckNotNullIndex, @@ -45,7 +41,7 @@ val hideAdsPatch = bytecodePatch( // p4 is the "consumerPlanUpsells" value, a list of plans to try to sell to the user. // p5 is the "currentConsumerPlan" value, the type of plan currently subscribed to. // p6 is the "currentConsumerPlanTitle" value, the name of the plan currently subscribed to, shown to the user. - userConsumerPlanConstructorMatch.mutableMethod.addInstructions( + userConsumerPlanConstructorFingerprint.method.addInstructions( 0, """ const-string p1, "high_tier" @@ -57,8 +53,9 @@ val hideAdsPatch = bytecodePatch( ) // Prevent verification of an HTTP header containing the user's current plan, which would contradict the previous patch. - val conditionIndex = interceptMatch.patternMatch!!.endIndex + 1 - interceptMatch.mutableMethod.addInstruction( + + val conditionIndex = interceptFingerprint.patternMatch!!.endIndex + 1 + interceptFingerprint.method.addInstruction( conditionIndex, "return-object p1", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/analytics/DisableTelemetryPatch.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/analytics/DisableTelemetryPatch.kt index 16485a195..8614aca3b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/analytics/DisableTelemetryPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/analytics/DisableTelemetryPatch.kt @@ -10,10 +10,8 @@ val disableTelemetryPatch = bytecodePatch( ) { compatibleWith("com.soundcloud.android") - val createTrackingApiMatch by createTrackingApiFingerprint() - execute { // Empty the "backend" argument to abort the initializer. - createTrackingApiMatch.mutableMethod.addInstruction(0, "const-string p1, \"\"") + createTrackingApiFingerprint.method.addInstruction(0, "const-string p1, \"\"") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt index 89a2ff5fc..ff54b06dc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/soundcloud/offlinesync/EnableOfflineSyncPatch.kt @@ -19,16 +19,12 @@ val enableOfflineSync = bytecodePatch( ) { compatibleWith("com.soundcloud.android") - val featureConstructorMatch by featureConstructorFingerprint() - val downloadOperationsURLBuilderMatch by downloadOperationsURLBuilderFingerprint() - val downloadOperationsHeaderVerificationMatch by downloadOperationsHeaderVerificationFingerprint() - execute { // Enable the feature to allow offline track syncing by modifying the JSON server response. // This method is the constructor of a class representing a "Feature" object parsed from JSON data. // p1 is the name of the feature. // p2 is true if the feature is enabled, false otherwise. - featureConstructorMatch.mutableMethod.apply { + featureConstructorFingerprint.method.apply { val afterCheckNotNullIndex = 2 addInstructionsWithLabels( @@ -46,7 +42,7 @@ val enableOfflineSync = bytecodePatch( // Patch the URL builder to use the HTTPS_STREAM endpoint // instead of the offline sync endpoint to downloading the track. - downloadOperationsURLBuilderMatch.mutableMethod.apply { + downloadOperationsURLBuilderFingerprint.method.apply { val getEndpointsEnumFieldIndex = 1 val getEndpointsEnumFieldInstruction = getInstruction(getEndpointsEnumFieldIndex) @@ -62,7 +58,7 @@ val enableOfflineSync = bytecodePatch( // The HTTPS_STREAM endpoint does not return the necessary headers for offline sync. // Mock the headers to prevent the app from crashing by setting them to empty strings. // The headers are all cosmetic and do not affect the functionality of the app. - downloadOperationsHeaderVerificationMatch.mutableMethod.apply { + downloadOperationsHeaderVerificationFingerprint.method.apply { // The first three null checks need to be patched. instructions.asSequence().filter { it.opcode == Opcode.IF_EQZ diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt index 30d8a0bb4..4c17ebce6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/layout/theme/CustomThemePatch.kt @@ -47,13 +47,13 @@ val customThemePatch = resourcePatch( required = true, ) - execute { context -> + execute { val backgroundColor = backgroundColor!! val backgroundColorSecondary = backgroundColorSecondary!! val accentColor = accentColor!! val accentColorPressed = accentColorPressed!! - context.document["res/values/colors.xml"].use { document -> + document("res/values/colors.xml").use { document -> val resourcesNode = document.getElementsByTagName("resources").item(0) as Element for (i in 0 until resourcesNode.childNodes.length) { diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/lite/ondemand/OnDemandPatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/lite/ondemand/OnDemandPatch.kt index d8a8940d2..6444ff7fb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/lite/ondemand/OnDemandPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/lite/ondemand/OnDemandPatch.kt @@ -10,12 +10,11 @@ val onDemandPatch = bytecodePatch( ) { compatibleWith("com.spotify.lite") - val onDemandMatch by onDemandFingerprint() - execute { // Spoof a premium account - onDemandMatch.mutableMethod.addInstruction( - onDemandMatch.patternMatch!!.endIndex - 1, + + onDemandFingerprint.method.addInstruction( + onDemandFingerprint.patternMatch!!.endIndex - 1, "const/4 v0, 0x2", ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt b/patches/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt index 857842fc6..c191c676b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/spotify/navbar/PremiumNavbarTabPatch.kt @@ -34,11 +34,9 @@ val premiumNavbarTabPatch = bytecodePatch( compatibleWith("com.spotify.music") - val addNavbarItemMatch by addNavBarItemFingerprint() - // If the navigation bar item is the premium tab, do not add it. execute { - addNavbarItemMatch.mutableMethod.addInstructions( + addNavBarItemFingerprint.method.addInstructions( 0, """ const v1, $premiumTabId diff --git a/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideOffersTabPatch.kt b/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideOffersTabPatch.kt index 1991dbb82..b7831e14a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideOffersTabPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideOffersTabPatch.kt @@ -10,8 +10,8 @@ val hideOffersTabPatch = resourcePatch( ) { compatibleWith("de.stocard.stocard") - execute { context -> - context.document["res/menu/bottom_navigation_menu.xml"].use { document -> + execute { + document("res/menu/bottom_navigation_menu.xml").use { document -> document.getNode("menu").apply { removeChild( childElementsSequence().first { diff --git a/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideStoryBubblesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideStoryBubblesPatch.kt index 80894391e..aab14bae9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideStoryBubblesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/stocard/layout/HideStoryBubblesPatch.kt @@ -9,8 +9,8 @@ val hideStoryBubblesPatch = resourcePatch( ) { compatibleWith("de.stocard.stocard") - execute { context -> - context.document["res/layout/rv_story_bubbles_list.xml"].use { document -> + execute { + document("res/layout/rv_story_bubbles_list.xml").use { document -> document.getNode("androidx.recyclerview.widget.RecyclerView").apply { arrayOf( "android:layout_width", diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/subscription/UnlockSubscriptionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/strava/subscription/UnlockSubscriptionPatch.kt index 0d96767a2..e59660472 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/subscription/UnlockSubscriptionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/subscription/UnlockSubscriptionPatch.kt @@ -1,4 +1,5 @@ package app.revanced.patches.strava.subscription + import app.revanced.patcher.extensions.InstructionExtensions.replaceInstruction import app.revanced.patcher.patch.bytecodePatch @@ -9,11 +10,9 @@ val unlockSubscriptionPatch = bytecodePatch( ) { compatibleWith("com.strava") - val getSubscribedMatch by getSubscribedFingerprint() - execute { - getSubscribedMatch.mutableMethod.replaceInstruction( - getSubscribedMatch.patternMatch!!.startIndex, + getSubscribedFingerprint.method.replaceInstruction( + getSubscribedFingerprint.patternMatch!!.startIndex, "const/4 v0, 0x1", ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt index c1af24825..73246fa21 100644 --- a/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/strava/upselling/DisableSubscriptionSuggestionsPatch.kt @@ -14,18 +14,16 @@ val disableSubscriptionSuggestionsPatch = bytecodePatch( ) { compatibleWith("com.strava"("320.12")) - val getModulesMatch by getModulesFingerprint() - execute { val helperMethodName = "getModulesIfNotUpselling" val pageSuffix = "_upsell" val label = "original" - val className = getModulesMatch.classDef.type - val originalMethod = getModulesMatch.mutableMethod + val className = getModulesFingerprint.originalClassDef.type + val originalMethod = getModulesFingerprint.method val returnType = originalMethod.returnType - getModulesMatch.mutableClass.methods.add( + getModulesFingerprint.classDef.methods.add( ImmutableMethod( className, helperMethodName, @@ -54,7 +52,7 @@ val disableSubscriptionSuggestionsPatch = bytecodePatch( }, ) - val getModulesIndex = getModulesMatch.patternMatch!!.startIndex + val getModulesIndex = getModulesFingerprint.patternMatch!!.startIndex with(originalMethod) { removeInstruction(getModulesIndex) addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/swissid/integritycheck/RemoveGooglePlayIntegrityCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/swissid/integritycheck/RemoveGooglePlayIntegrityCheckPatch.kt index 82714c651..85ae4a2a8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/swissid/integritycheck/RemoveGooglePlayIntegrityCheckPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/swissid/integritycheck/RemoveGooglePlayIntegrityCheckPatch.kt @@ -3,8 +3,9 @@ package app.revanced.patches.swissid.integritycheck import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.bytecodePatch -private const val RESULT_METHOD_REFERENCE = " Lcom/swisssign/deviceintegrity/DeviceintegrityPlugin\$onMethodCall\$1;->" + - "\$result:Lio/flutter/plugin/common/MethodChannel\$Result;" +private const val RESULT_METHOD_REFERENCE = + " Lcom/swisssign/deviceintegrity/DeviceintegrityPlugin\$onMethodCall\$1;->" + + "\$result:Lio/flutter/plugin/common/MethodChannel\$Result;" private const val SUCCESS_METHOD_REFERENCE = "Lio/flutter/plugin/common/MethodChannel\$Result;->success(Ljava/lang/Object;)V" @@ -16,10 +17,8 @@ val removeGooglePlayIntegrityCheckPatch = bytecodePatch( ) { compatibleWith("com.swisssign.swissid.mobile") - val checkIntegrityMatch by checkIntegrityFingerprint() - execute { - checkIntegrityMatch.mutableMethod.addInstructions( + checkIntegrityFingerprint.method.addInstructions( 0, """ iget-object p1, p0, $RESULT_METHOD_REFERENCE diff --git a/patches/src/main/kotlin/app/revanced/patches/ticktick/misc/themeunlock/UnlockThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/ticktick/misc/themeunlock/UnlockThemePatch.kt index 5e2aa37d8..c9d777904 100644 --- a/patches/src/main/kotlin/app/revanced/patches/ticktick/misc/themeunlock/UnlockThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/ticktick/misc/themeunlock/UnlockThemePatch.kt @@ -11,11 +11,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("com.ticktick.task") - val checkLockedThemesMatch by checkLockedThemesFingerprint() - val setThemeMatch by setThemeFingerprint() - execute { - checkLockedThemesMatch.mutableMethod.addInstructions( + checkLockedThemesFingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 @@ -23,6 +20,6 @@ val unlockProPatch = bytecodePatch( """, ) - setThemeMatch.mutableMethod.removeInstructions(0, 10) + setThemeFingerprint.method.removeInstructions(0, 10) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/FeedFilterPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/FeedFilterPatch.kt index 7301c58ba..9ea783f95 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/FeedFilterPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/feedfilter/FeedFilterPatch.kt @@ -25,11 +25,8 @@ val feedFilterPatch = bytecodePatch( "com.zhiliaoapp.musically"("36.5.4"), ) - val feedApiServiceLIZMatch by feedApiServiceLIZFingerprint() - val settingsStatusLoadMatch by settingsStatusLoadFingerprint() - execute { - feedApiServiceLIZMatch.mutableMethod.apply { + feedApiServiceLIZFingerprint.method.apply { val returnFeedItemInstruction = instructions.first { it.opcode == Opcode.RETURN_OBJECT } val feedItemsRegister = (returnFeedItemInstruction as OneRegisterInstruction).registerA @@ -40,7 +37,7 @@ val feedFilterPatch = bytecodePatch( ) } - settingsStatusLoadMatch.mutableMethod.addInstruction( + settingsStatusLoadFingerprint.method.addInstruction( 0, "invoke-static {}, Lapp/revanced/extension/tiktok/settings/SettingsStatus;->enableFeedFilter()V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt index 73374b513..13c829e62 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/cleardisplay/RememberClearDisplayPatch.kt @@ -20,11 +20,8 @@ val rememberClearDisplayPatch = bytecodePatch( "com.zhiliaoapp.musically"("36.5.4"), ) - val onClearDisplayEventMatch by onClearDisplayEventFingerprint() - val onRenderFirstFrameMatch by onRenderFirstFrameFingerprint() - execute { - onClearDisplayEventMatch.mutableMethod.let { + onClearDisplayEventFingerprint.method.let { // region Hook the "Clear display" configuration save event to remember the state of clear display. val isEnabledIndex = it.indexOfFirstInstructionOrThrow(Opcode.IGET_BOOLEAN) + 1 @@ -41,30 +38,30 @@ val rememberClearDisplayPatch = bytecodePatch( // region Override the "Clear display" configuration load event to load the state of clear display. val clearDisplayEventClass = it.parameters[0].type - onRenderFirstFrameMatch.mutableMethod.addInstructionsWithLabels( + onRenderFirstFrameFingerprint.method.addInstructionsWithLabels( 0, """ - # Create a new clearDisplayEvent 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) - # Clear display type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. - const/4 v1, 0x0 + # Clear display type such as 0 = LONG_PRESS, 1 = SCREEN_RECORD etc. + const/4 v1, 0x0 - # Enter method (Such as "pinch", "swipe_exit", or an empty string (unknown, what it means)). - const-string v2, "" + # Enter method (Such as "pinch", "swipe_exit", or an empty string (unknown, what it means)). + const-string v2, "" - # Name of the clear display type which is equivalent to the clear display type. - const-string v3, "long_press" - - # The state of clear display. - invoke-static { }, Lapp/revanced/extension/tiktok/cleardisplay/RememberClearDisplayPatch;->getClearDisplayState()Z - move-result v4 - if-eqz v4, :clear_display_disabled + # Name of the clear display type which is equivalent to the clear display type. + const-string v3, "long_press" + + # The state of clear display. + invoke-static { }, Lapp/revanced/extension/tiktok/cleardisplay/RememberClearDisplayPatch;->getClearDisplayState()Z + move-result v4 + if-eqz v4, :clear_display_disabled - new-instance v0, $clearDisplayEventClass - invoke-direct { v0, v1, v2, v3, v4 }, $clearDisplayEventClass->(ILjava/lang/String;Ljava/lang/String;Z)V - invoke-virtual { v0 }, $clearDisplayEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; + new-instance v0, $clearDisplayEventClass + invoke-direct { v0, v1, v2, v3, v4 }, $clearDisplayEventClass->(ILjava/lang/String;Ljava/lang/String;Z)V + invoke-virtual { v0 }, $clearDisplayEventClass->post()Lcom/ss/android/ugc/governance/eventbus/IEvent; """, - ExternalLabel("clear_display_disabled", onRenderFirstFrameMatch.mutableMethod.getInstruction(0)), + ExternalLabel("clear_display_disabled", onRenderFirstFrameFingerprint.method.getInstruction(0)), ) // endregion diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt index 94afc211f..b80ceaed0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/downloads/DownloadsPatch.kt @@ -27,14 +27,8 @@ val downloadsPatch = bytecodePatch( "com.zhiliaoapp.musically"("36.5.4"), ) - val aclCommonShareMatch by aclCommonShareFingerprint() - val aclCommonShare2Match by aclCommonShare2Fingerprint() - val aclCommonShare3Match by aclCommonShare3Fingerprint() - val downloadUriMatch by downloadUriFingerprint() - val settingsStatusLoadMatch by settingsStatusLoadFingerprint() - - execute { context -> - aclCommonShareMatch.mutableMethod.replaceInstructions( + execute { + aclCommonShareFingerprint.method.replaceInstructions( 0, """ const/4 v0, 0x0 @@ -42,7 +36,7 @@ val downloadsPatch = bytecodePatch( """, ) - aclCommonShare2Match.mutableMethod.replaceInstructions( + aclCommonShare2Fingerprint.method.replaceInstructions( 0, """ const/4 v0, 0x2 @@ -51,7 +45,7 @@ val downloadsPatch = bytecodePatch( ) // Download videos without watermark. - aclCommonShare3Match.mutableMethod.addInstructionsWithLabels( + aclCommonShare3Fingerprint.method.addInstructionsWithLabels( 0, """ invoke-static {}, Lapp/revanced/extension/tiktok/download/DownloadsPatch;->shouldRemoveWatermark()Z @@ -65,7 +59,7 @@ val downloadsPatch = bytecodePatch( ) // Change the download path patch. - downloadUriMatch.mutableMethod.apply { + downloadUriFingerprint.method.apply { val firstIndex = indexOfFirstInstructionOrThrow { getReference()?.name == "" } @@ -90,7 +84,7 @@ val downloadsPatch = bytecodePatch( ) } - settingsStatusLoadMatch.mutableMethod.addInstruction( + settingsStatusLoadFingerprint.method.addInstruction( 0, "invoke-static {}, Lapp/revanced/extension/tiktok/settings/SettingsStatus;->enableDownload()V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/seekbar/ShowSeekbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/seekbar/ShowSeekbarPatch.kt index 5cb6db64c..417095b33 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/seekbar/ShowSeekbarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/seekbar/ShowSeekbarPatch.kt @@ -13,18 +13,15 @@ val showSeekbarPatch = bytecodePatch( "com.zhiliaoapp.musically", ) - val shouldShowSeekBarMatch by shouldShowSeekBarFingerprint() - val setSeekBarShowTypeMatch by setSeekBarShowTypeFingerprint() - execute { - shouldShowSeekBarMatch.mutableMethod.addInstructions( + shouldShowSeekBarFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 return v0 """, ) - setSeekBarShowTypeMatch.mutableMethod.apply { + setSeekBarShowTypeFingerprint.method.apply { val typeRegister = implementation!!.registerCount - 1 addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt index 81153a1dc..d59626ee7 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/interaction/speed/PlaybackSpeedPatch.kt @@ -22,15 +22,11 @@ val playbackSpeedPatch = bytecodePatch( "com.zhiliaoapp.musically"("36.5.4"), ) - val getSpeedMatch by getSpeedFingerprint() - val onRenderFirstFrameMatch by onRenderFirstFrameFingerprint() - val setSpeedMatch by setSpeedFingerprint() - val getEnterFromMatch by getEnterFromFingerprint() - execute { - setSpeedMatch.let { onVideoSwiped -> - getSpeedMatch.mutableMethod.apply { - val injectIndex = indexOfFirstInstructionOrThrow { getReference()?.returnType == "F" } + 2 + setSpeedFingerprint.let { onVideoSwiped -> + getSpeedFingerprint.method.apply { + val injectIndex = + indexOfFirstInstructionOrThrow { getReference()?.returnType == "F" } + 2 val register = getInstruction(injectIndex - 1).registerA addInstruction( @@ -42,32 +38,32 @@ val playbackSpeedPatch = bytecodePatch( // By default, the playback speed will reset to 1.0 at the start of each video. // Instead, override it with the desired playback speed. - onRenderFirstFrameMatch.mutableMethod.addInstructions( + onRenderFirstFrameFingerprint.method.addInstructions( 0, """ - # Video playback location (e.g. home page, following page or search result page) retrieved using getEnterFrom method. - const/4 v0, 0x1 - invoke-virtual { p0, v0 }, ${getEnterFromMatch.method} - move-result-object v0 - - # Model of current video retrieved using getCurrentAweme method. - invoke-virtual { p0 }, Lcom/ss/android/ugc/aweme/feed/panel/BaseListFragmentPanel;->getCurrentAweme()Lcom/ss/android/ugc/aweme/feed/model/Aweme; - move-result-object v1 - - # Desired playback speed retrieved using getPlaybackSpeed method. - invoke-static { }, Lapp/revanced/extension/tiktok/speed/PlaybackSpeedPatch;->getPlaybackSpeed()F - move-result v2 - invoke-static { v0, v1, v2 }, ${onVideoSwiped.method} - """, + # Video playback location (e.g. home page, following page or search result page) retrieved using getEnterFrom method. + const/4 v0, 0x1 + invoke-virtual { p0, v0 }, ${getEnterFromFingerprint.originalMethod} + move-result-object v0 + + # Model of current video retrieved using getCurrentAweme method. + invoke-virtual { p0 }, Lcom/ss/android/ugc/aweme/feed/panel/BaseListFragmentPanel;->getCurrentAweme()Lcom/ss/android/ugc/aweme/feed/model/Aweme; + move-result-object v1 + + # Desired playback speed retrieved using getPlaybackSpeed method. + invoke-static { }, Lapp/revanced/extension/tiktok/speed/PlaybackSpeedPatch;->getPlaybackSpeed()F + move-result v2 + invoke-static { v0, v1, v2 }, ${onVideoSwiped.originalMethod} + """, ) // Force enable the playback speed option for all videos. - onVideoSwiped.mutableClass.methods.find { method -> method.returnType == "Z" }?.addInstructions( + onVideoSwiped.classDef.methods.find { method -> method.returnType == "Z" }?.addInstructions( 0, """ - const/4 v0, 0x1 - return v0 - """, + const/4 v0, 0x1 + return v0 + """, ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/disablerequirement/DisableLoginRequirementPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/disablerequirement/DisableLoginRequirementPatch.kt index 1b2f0a0b0..2976abe5e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/disablerequirement/DisableLoginRequirementPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/disablerequirement/DisableLoginRequirementPatch.kt @@ -12,15 +12,12 @@ val disableLoginRequirementPatch = bytecodePatch( "com.zhiliaoapp.musically", ) - val mandatoryLoginServiceMatch by mandatoryLoginServiceFingerprint() - val mandatoryLoginService2Match by mandatoryLoginService2Fingerprint() - execute { listOf( - mandatoryLoginServiceMatch.mutableMethod, - mandatoryLoginService2Match.mutableMethod, - ).forEach { method -> - method.addInstructions( + mandatoryLoginServiceFingerprint, + mandatoryLoginService2Fingerprint, + ).forEach { fingerprint -> + fingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/fixgoogle/FixGoogleLoginPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/fixgoogle/FixGoogleLoginPatch.kt index 214868d04..7ab636c09 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/fixgoogle/FixGoogleLoginPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/login/fixgoogle/FixGoogleLoginPatch.kt @@ -13,13 +13,10 @@ val fixGoogleLoginPatch = bytecodePatch( "com.zhiliaoapp.musically", ) - val googleOneTapAuthAvailableMatch by googleOneTapAuthAvailableFingerprint() - val googleAuthAvailableMatch by googleAuthAvailableFingerprint() - execute { listOf( - googleOneTapAuthAvailableMatch.mutableMethod, - googleAuthAvailableMatch.mutableMethod, + googleOneTapAuthAvailableFingerprint.method, + googleAuthAvailableFingerprint.method, ).forEach { method -> method.addInstructions( 0, diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/SettingsPatch.kt index 7250ef7a7..a48305177 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/SettingsPatch.kt @@ -25,31 +25,26 @@ val settingsPatch = bytecodePatch( "com.zhiliaoapp.musically"("36.5.4"), ) - val adPersonalizationActivityOnCreateMatch by adPersonalizationActivityOnCreateFingerprint() - val addSettingsEntryMatch by addSettingsEntryFingerprint() - val settingsEntryMatch by settingsEntryFingerprint() - val settingsEntryInfoMatch by settingsEntryInfoFingerprint() - execute { val initializeSettingsMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->initialize(" + - "Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;" + - ")Z" + "Lcom/bytedance/ies/ugc/aweme/commercialize/compliance/personalization/AdPersonalizationActivity;" + + ")Z" val createSettingsEntryMethodDescriptor = "$EXTENSION_CLASS_DESCRIPTOR->createSettingsEntry(" + - "Ljava/lang/String;" + - "Ljava/lang/String;" + - ")Ljava/lang/Object;" + "Ljava/lang/String;" + + "Ljava/lang/String;" + + ")Ljava/lang/Object;" fun String.toClassName(): String = substring(1, this.length - 1).replace("/", ".") // Find the class name of classes which construct a settings entry - val settingsButtonClass = settingsEntryMatch.classDef.type.toClassName() - val settingsButtonInfoClass = settingsEntryInfoMatch.classDef.type.toClassName() + val settingsButtonClass = settingsEntryFingerprint.originalClassDef.type.toClassName() + val settingsButtonInfoClass = settingsEntryInfoFingerprint.originalClassDef.type.toClassName() // Create a settings entry for 'revanced settings' and add it to settings fragment - addSettingsEntryMatch.mutableMethod.apply { + addSettingsEntryFingerprint.method.apply { val markIndex = implementation!!.instructions.indexOfFirst { it.opcode == Opcode.IGET_OBJECT && ((it as Instruction22c).reference as FieldReference).name == "headerUnit" } @@ -72,13 +67,13 @@ val settingsPatch = bytecodePatch( const-string v1, "$settingsButtonInfoClass" invoke-static {v0, v1}, $createSettingsEntryMethodDescriptor move-result-object v0 - check-cast v0, ${settingsEntryMatch.classDef.type} + check-cast v0, ${settingsEntryFingerprint.originalClassDef.type} """, ) } // Initialize the settings menu once the replaced setting entry is clicked. - adPersonalizationActivityOnCreateMatch.mutableMethod.apply { + adPersonalizationActivityOnCreateFingerprint.method.apply { val initializeSettingsIndex = implementation!!.instructions.indexOfFirst { it.opcode == Opcode.INVOKE_SUPER } + 1 @@ -98,4 +93,4 @@ val settingsPatch = bytecodePatch( ) } } -} \ No newline at end of file +} diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/SpoofSimPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/SpoofSimPatch.kt index 408958179..593241d15 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/SpoofSimPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/spoof/sim/SpoofSimPatch.kt @@ -29,9 +29,7 @@ val spoofSimPatch = bytecodePatch( "com.zhiliaoapp.musically", ) - val settingsStatusLoadMatch by settingsStatusLoadFingerprint() - - execute { context -> + execute { val replacements = hashMapOf( "getSimCountryIso" to "getCountryIso", "getNetworkCountryIso" to "getCountryIso", @@ -43,7 +41,7 @@ val spoofSimPatch = bytecodePatch( // Find all api call to check sim information. buildMap { - context.classes.forEach { classDef -> + classes.forEach { classDef -> classDef.methods.let { methods -> buildMap methodList@{ methods.forEach methods@{ method -> @@ -71,7 +69,7 @@ val spoofSimPatch = bytecodePatch( } } }.forEach { (classDef, methods) -> - with(context.proxy(classDef).mutableClass) { + with(proxy(classDef).mutableClass) { methods.forEach { (method, patches) -> with(findMutableMethodOf(method)) { while (!patches.isEmpty()) { @@ -94,7 +92,7 @@ val spoofSimPatch = bytecodePatch( } // Enable patch in settings. - settingsStatusLoadMatch.mutableMethod.addInstruction( + settingsStatusLoadFingerprint.method.addInstruction( 0, "invoke-static {}, Lapp/revanced/extension/tiktok/settings/SettingsStatus;->enableSimSpoof()V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/trakt/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/trakt/UnlockProPatch.kt index 4b3138d67..bf10b9f40 100644 --- a/patches/src/main/kotlin/app/revanced/patches/trakt/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/trakt/UnlockProPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.trakt import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.exception @Suppress("unused") val unlockProPatch = bytecodePatch( @@ -10,27 +9,21 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("tv.trakt.trakt"("1.1.1")) - val remoteUserMatch by remoteUserFingerprint() - - execute { context -> - remoteUserMatch.classDef.let { remoteUserClass -> - arrayOf(isVIPFingerprint, isVIPEPFingerprint).onEach { fingerprint -> - // Resolve both fingerprints on the same class. - if (!fingerprint.match(context, remoteUserClass)) { - throw fingerprint.exception - } - }.forEach { fingerprint -> - // Return true for both VIP check methods. - fingerprint.match?.mutableMethod?.addInstructions( - 0, - """ - const/4 v0, 0x1 - invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean; - move-result-object v1 - return-object v1 - """, - ) ?: throw fingerprint.exception - } + execute { + arrayOf(isVIPFingerprint, isVIPEPFingerprint).onEach { fingerprint -> + // Resolve both fingerprints on the same class. + fingerprint.match(remoteUserFingerprint.originalClassDef) + }.forEach { fingerprint -> + // Return true for both VIP check methods. + fingerprint.method.addInstructions( + 0, + """ + const/4 v0, 0x1 + invoke-static {v0}, Ljava/lang/Boolean;->valueOf(Z)Ljava/lang/Boolean; + move-result-object v1 + return-object v1 + """, + ) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/ShowOnLockscreenPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/ShowOnLockscreenPatch.kt index c8121f705..2d3325190 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/ShowOnLockscreenPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/ShowOnLockscreenPatch.kt @@ -24,10 +24,8 @@ val showOnLockscreenPatch = bytecodePatch( compatibleWith("de.tudortmund.app") - val brightnessMatch by brightnessFingerprint() - execute { - brightnessMatch.mutableMethod.apply { + brightnessFingerprint.method.apply { // Find the instruction where the brightness value is loaded into a register val brightnessInstruction = instructions.firstNotNullOf { instruction -> if (instruction.opcode != Opcode.IGET_OBJECT) return@firstNotNullOf null diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/notifications/DisableBlogNotificationReminderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/notifications/DisableBlogNotificationReminderPatch.kt index fbd7cf712..fc3d1fc8e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/notifications/DisableBlogNotificationReminderPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/notifications/DisableBlogNotificationReminderPatch.kt @@ -10,10 +10,8 @@ val disableBlogNotificationReminderPatch = bytecodePatch( ) { compatibleWith("com.tumblr") - val isBlogNotifyEnabledMatch by isBlogNotifyEnabledFingerprint() - execute { - isBlogNotifyEnabledMatch.mutableMethod.addInstructions( + isBlogNotifyEnabledFingerprint.method.addInstructions( 0, """ # Return false for BlogNotifyCtaDialog.isEnabled() method. diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt index 7f1bc208f..09faa1734 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/annoyances/popups/DisableGiftMessagePopupPatch.kt @@ -10,9 +10,7 @@ val disableGiftMessagePopupPatch = bytecodePatch( ) { compatibleWith("com.tumblr") - val showGiftMessagePopupMatch by showGiftMessagePopupFingerprint() - execute { - showGiftMessagePopupMatch.mutableMethod.addInstructions(0, "return-void") + showGiftMessagePopupFingerprint.method.addInstructions(0, "return-void") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/featureflags/OverrideFeatureFlagsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/featureflags/OverrideFeatureFlagsPatch.kt index 01ed435e5..c2da658aa 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/featureflags/OverrideFeatureFlagsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/featureflags/OverrideFeatureFlagsPatch.kt @@ -22,18 +22,17 @@ internal lateinit var addFeatureFlagOverride: (name: String, value: String) -> U val overrideFeatureFlagsPatch = bytecodePatch( description = "Forcibly set the value of A/B testing features of your choice.", ) { - val getFeatureValueMatch by getFeatureValueFingerprint() execute { - val configurationClass = getFeatureValueMatch.method.definingClass - val featureClass = getFeatureValueMatch.method.parameterTypes[0].toString() + val configurationClass = getFeatureValueFingerprint.originalMethod.definingClass + val featureClass = getFeatureValueFingerprint.originalMethod.parameterTypes[0].toString() // The method we want to inject into does not have enough registers, so we inject a helper method // and inject more instructions into it later, see addOverride. // This is not in an extension since the unused variable would get compiled away and the method would // get compiled to only have one register, which is not enough for our later injected instructions. val helperMethod = ImmutableMethod( - getFeatureValueMatch.method.definingClass, + getFeatureValueFingerprint.originalMethod.definingClass, "getValueOverride", listOf(ImmutableMethodParameter(featureClass, null, "feature")), "Ljava/lang/String;", @@ -63,15 +62,15 @@ val overrideFeatureFlagsPatch = bytecodePatch( """, ) }.also { helperMethod -> - getFeatureValueMatch.mutableClass.methods.add(helperMethod) + getFeatureValueFingerprint.classDef.methods.add(helperMethod) } // Here we actually insert the hook to call our helper method and return its value if it returns not null // This is equivalent to // String forcedValue = getValueOverride(feature) // if (forcedValue != null) return forcedValue - val getFeatureIndex = getFeatureValueMatch.patternMatch!!.startIndex - getFeatureValueMatch.mutableMethod.addInstructionsWithLabels( + val getFeatureIndex = getFeatureValueFingerprint.patternMatch!!.startIndex + getFeatureValueFingerprint.method.addInstructionsWithLabels( getFeatureIndex, """ # Call the Helper Method with the Feature diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt index d51aead2b..dbe75d5f8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/fixes/FixOldVersionsPatch.kt @@ -12,9 +12,6 @@ val fixOldVersionsPatch = bytecodePatch( ) { compatibleWith("com.tumblr") - val httpPathParserMatch by httpPathParserFingerprint() - val addQueryParamMatch by addQueryParamFingerprint() - execute { val liveQueryParameters = listOf( ",?live_now", @@ -23,8 +20,8 @@ val fixOldVersionsPatch = bytecodePatch( // Remove the live query parameters from the path when it's specified via a @METHOD annotation. for (liveQueryParameter in liveQueryParameters) { - httpPathParserMatch.mutableMethod.addInstructions( - httpPathParserMatch.patternMatch!!.endIndex + 1, + httpPathParserFingerprint.method.addInstructions( + httpPathParserFingerprint.patternMatch!!.endIndex + 1, """ # urlPath = urlPath.replace(liveQueryParameter, "") const-string p1, "$liveQueryParameter" @@ -42,7 +39,7 @@ val fixOldVersionsPatch = bytecodePatch( // which would result in the path "api/me/inf0?fields[blog]=${value}" // Here we make sure that this value doesn't contain the broken query parameters. for (liveQueryParameter in liveQueryParameters) { - addQueryParamMatch.mutableMethod.addInstructions( + addQueryParamFingerprint.method.addInstructions( 0, """ # queryParameterValue = queryParameterValue.replace(liveQueryParameter, "") diff --git a/patches/src/main/kotlin/app/revanced/patches/tumblr/timelinefilter/FilterTimelineObjectsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/tumblr/timelinefilter/FilterTimelineObjectsPatch.kt index d094fb762..c4ab799e8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tumblr/timelinefilter/FilterTimelineObjectsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tumblr/timelinefilter/FilterTimelineObjectsPatch.kt @@ -23,14 +23,10 @@ val filterTimelineObjectsPatch = bytecodePatch( ) { dependsOn(sharedExtensionPatch) - val timelineConstructorMatch by timelineConstructorFingerprint() - val timelineFilterExtensionMatch by timelineFilterExtensionFingerprint() - val postsResponseConstructorMatch by postsResponseConstructorFingerprint() - execute { - val filterInsertIndex = timelineFilterExtensionMatch.patternMatch!!.startIndex + val filterInsertIndex = timelineFilterExtensionFingerprint.patternMatch!!.startIndex - timelineFilterExtensionMatch.mutableMethod.apply { + timelineFilterExtensionFingerprint.method.apply { val addInstruction = getInstruction(filterInsertIndex + 1) val filterListRegister = addInstruction.registerC @@ -52,10 +48,10 @@ val filterTimelineObjectsPatch = bytecodePatch( } mapOf( - timelineConstructorMatch to 1, - postsResponseConstructorMatch to 2, - ).forEach { (match, timelineObjectsRegister) -> - match.mutableMethod.addInstructions( + timelineConstructorFingerprint to 1, + postsResponseConstructorFingerprint to 2, + ).forEach { (fingerprint, timelineObjectsRegister) -> + fingerprint.method.addInstructions( 0, "invoke-static {p$timelineObjectsRegister}, " + "Lapp/revanced/extension/tumblr/patches/TimelineFilterPatch;->" + diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/audio/AudioAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/audio/AudioAdsPatch.kt index 6827a99e3..4b57bddbd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/audio/AudioAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/audio/AudioAdsPatch.kt @@ -24,8 +24,6 @@ val audioAdsPatch = bytecodePatch( compatibleWith("tv.twitch.android.app"("15.4.1", "16.1.0", "16.9.1")) - val audioAdsPresenterPlayMatch by audioAdsPresenterPlayFingerprint() - execute { addResources("twitch", "ad.audio.audioAdsPatch") @@ -34,7 +32,7 @@ val audioAdsPatch = bytecodePatch( ) // Block playAds call - audioAdsPresenterPlayMatch.mutableMethod.addInstructionsWithLabels( + audioAdsPresenterPlayFingerprint.method.addInstructionsWithLabels( 0, """ invoke-static { }, Lapp/revanced/extension/twitch/patches/AudioAdsPatch;->shouldBlockAudioAds()Z @@ -42,7 +40,7 @@ val audioAdsPatch = bytecodePatch( if-eqz v0, :show_audio_ads return-void """, - ExternalLabel("show_audio_ads", audioAdsPresenterPlayMatch.mutableMethod.getInstruction(0)), + ExternalLabel("show_audio_ads", audioAdsPresenterPlayFingerprint.method.getInstruction(0)), ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt index 4d36bc22d..973ccefe0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/embedded/EmbeddedAdsPatch.kt @@ -22,8 +22,6 @@ val embeddedAdsPatch = bytecodePatch( compatibleWith("tv.twitch.android.app"("15.4.1", "16.1.0", "16.9.1")) - val createUsherClientMatch by createsUsherClientFingerprint() - execute { addResources("twitch", "ad.embedded.embeddedAdsPatch") @@ -32,7 +30,7 @@ val embeddedAdsPatch = bytecodePatch( ) // Inject OkHttp3 application interceptor - createUsherClientMatch.mutableMethod.addInstructions( + createsUsherClientFingerprint.method.addInstructions( 3, """ invoke-static {}, Lapp/revanced/extension/twitch/patches/EmbeddedAdsPatch;->createRequestInterceptor()Lapp/revanced/extension/twitch/api/RequestInterceptor; diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/video/VideoAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/video/VideoAdsPatch.kt index 5c0eed6eb..49b715fce 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/ad/video/VideoAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/ad/video/VideoAdsPatch.kt @@ -26,11 +26,8 @@ val videoAdsPatch = bytecodePatch( settingsPatch, addResourcesPatch, adPatch(conditionCall, skipLabelName) { createConditionInstructions, blockMethods -> - val checkAdEligibilityLambdaMatch by checkAdEligibilityLambdaFingerprint() - val getReadyToShowAdMatch by getReadyToShowAdFingerprint() - val contentConfigShowAdsMatch by contentConfigShowAdsFingerprint() - execute { context -> + execute { addResources("twitch", "ad.video.videoAdsPatch") PreferenceScreen.ADS.CLIENT_SIDE.addPreferences( @@ -38,14 +35,14 @@ val videoAdsPatch = bytecodePatch( ) /* Amazon ads SDK */ - context.blockMethods( + blockMethods( "Lcom/amazon/ads/video/player/AdsManagerImpl;", setOf("playAds"), ReturnMethod.default, ) /* Twitch ads manager */ - context.blockMethods( + blockMethods( "Ltv/twitch/android/shared/ads/VideoAdManager;", setOf( "checkAdEligibilityAndRequestAd", @@ -56,7 +53,7 @@ val videoAdsPatch = bytecodePatch( ) /* Various ad presenters */ - context.blockMethods( + blockMethods( "Ltv/twitch/android/shared/ads/AdsPlayerPresenter;", setOf( "requestAd", @@ -68,7 +65,7 @@ val videoAdsPatch = bytecodePatch( ReturnMethod.default, ) - context.blockMethods( + blockMethods( "Ltv/twitch/android/shared/ads/AdsVodPlayerPresenter;", setOf( "requestAd", @@ -77,7 +74,7 @@ val videoAdsPatch = bytecodePatch( ReturnMethod.default, ) - context.blockMethods( + blockMethods( "Ltv/twitch/android/feature/theatre/ads/AdEdgeAllocationPresenter;", setOf( "parseAdAndCheckEligibility", @@ -89,13 +86,13 @@ val videoAdsPatch = bytecodePatch( ) /* A/B ad testing experiments */ - context.blockMethods( + blockMethods( "Ltv/twitch/android/provider/experiments/helpers/DisplayAdsExperimentHelper;", setOf("areDisplayAdsEnabled"), ReturnMethod('Z', "0"), ) - context.blockMethods( + blockMethods( "Ltv/twitch/android/shared/ads/tracking/MultiFormatAdsTrackingExperiment;", setOf( "shouldUseMultiAdFormatTracker", @@ -104,7 +101,7 @@ val videoAdsPatch = bytecodePatch( ReturnMethod('Z', "0"), ) - context.blockMethods( + blockMethods( "Ltv/twitch/android/shared/ads/MultiformatAdsExperiment;", setOf( "shouldDisableClientSideLivePreroll", @@ -114,7 +111,7 @@ val videoAdsPatch = bytecodePatch( ) // Pretend our player is ineligible for all ads. - checkAdEligibilityLambdaMatch.mutableMethod.addInstructionsWithLabels( + checkAdEligibilityLambdaFingerprint.method.addInstructionsWithLabels( 0, """ ${createConditionInstructions("v0")} @@ -125,13 +122,13 @@ val videoAdsPatch = bytecodePatch( """, ExternalLabel( skipLabelName, - checkAdEligibilityLambdaMatch.mutableMethod.getInstruction(0), + checkAdEligibilityLambdaFingerprint.method.getInstruction(0), ), ) val adFormatDeclined = "Ltv/twitch/android/shared/display/ads/theatre/StreamDisplayAdsPresenter\$Action\$AdFormatDeclined;" - getReadyToShowAdMatch.mutableMethod.addInstructionsWithLabels( + getReadyToShowAdFingerprint.method.addInstructionsWithLabels( 0, """ ${createConditionInstructions("v0")} @@ -140,11 +137,11 @@ val videoAdsPatch = bytecodePatch( move-result-object p1 return-object p1 """, - ExternalLabel(skipLabelName, getReadyToShowAdMatch.mutableMethod.getInstruction(0)), + ExternalLabel(skipLabelName, getReadyToShowAdFingerprint.method.getInstruction(0)), ) // Spoof showAds JSON field. - contentConfigShowAdsMatch.mutableMethod.addInstructions( + contentConfigShowAdsFingerprint.method.addInstructions( 0, """ ${createConditionInstructions("v0")} diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/antidelete/ShowDeletedMessagesPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/antidelete/ShowDeletedMessagesPatch.kt index 93996e77a..f607d1b05 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/antidelete/ShowDeletedMessagesPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/antidelete/ShowDeletedMessagesPatch.kt @@ -31,10 +31,6 @@ val showDeletedMessagesPatch = bytecodePatch( if-eqz $register, :no_spoiler """ - val setHasModAccessMatch by setHasModAccessFingerprint() - val deletedMessageClickableSpanCtorMatch by deletedMessageClickableSpanCtorFingerprint() - val chatUtilCreateDeletedSpanMatch by chatUtilCreateDeletedSpanFingerprint() - execute { addResources("twitch", "chat.antidelete.showDeletedMessagesPatch") @@ -46,7 +42,7 @@ val showDeletedMessagesPatch = bytecodePatch( ) // Spoiler mode: Force set hasModAccess member to true in constructor - deletedMessageClickableSpanCtorMatch.mutableMethod.apply { + deletedMessageClickableSpanCtorFingerprint.method.apply { addInstructionsWithLabels( implementation!!.instructions.lastIndex, /* place in front of return-void */ """ @@ -59,10 +55,10 @@ val showDeletedMessagesPatch = bytecodePatch( } // Spoiler mode: Disable setHasModAccess setter - setHasModAccessMatch.mutableMethod.addInstruction(0, "return-void") + setHasModAccessFingerprint.method.addInstruction(0, "return-void") // Cross-out mode: Reformat span of deleted message - chatUtilCreateDeletedSpanMatch.mutableMethod.apply { + chatUtilCreateDeletedSpanFingerprint.method.apply { addInstructionsWithLabels( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt index 15a03f7c3..fd5b81011 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/chat/autoclaim/AutoClaimChannelPointsPatch.kt @@ -2,6 +2,7 @@ package app.revanced.patches.twitch.chat.autoclaim import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction +import app.revanced.patcher.extensions.InstructionExtensions.instructions import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.util.smali.ExternalLabel import app.revanced.patches.all.misc.resources.addResources @@ -22,8 +23,6 @@ val autoClaimChannelPointsPatch = bytecodePatch( compatibleWith("tv.twitch.android.app"("15.4.1", "16.1.0", "16.9.1")) - val communityPointsButtonViewDelegateMatch by communityPointsButtonViewDelegateFingerprint() - execute { addResources("twitch", "chat.autoclaim.autoClaimChannelPointsPatch") @@ -31,8 +30,8 @@ val autoClaimChannelPointsPatch = bytecodePatch( SwitchPreference("revanced_auto_claim_channel_points"), ) - communityPointsButtonViewDelegateMatch.mutableMethod.apply { - val lastIndex = implementation!!.instructions.lastIndex + communityPointsButtonViewDelegateFingerprint.method.apply { + val lastIndex = instructions.lastIndex addInstructionsWithLabels( lastIndex, // place in front of return-void """ diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt index 25cd5acc1..d5cbd81aa 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/debug/DebugModePatch.kt @@ -23,10 +23,6 @@ val debugModePatch = bytecodePatch( compatibleWith("tv.twitch.android.app") - val isDebugConfigEnabledMatch by isDebugConfigEnabledFingerprint() - val isOmVerificationEnabledMatch by isOmVerificationEnabledFingerprint() - val shouldShowDebugOptionsMatch by shouldShowDebugOptionsFingerprint() - execute { addResources("twitch", "debug.debugModePatch") @@ -35,11 +31,11 @@ val debugModePatch = bytecodePatch( ) listOf( - isDebugConfigEnabledMatch, - isOmVerificationEnabledMatch, - shouldShowDebugOptionsMatch, - ).forEach { - it.mutableMethod.addInstructions( + isDebugConfigEnabledFingerprint, + isOmVerificationEnabledFingerprint, + shouldShowDebugOptionsFingerprint, + ).forEach { fingerprint -> + fingerprint.method.addInstructions( 0, """ invoke-static {}, Lapp/revanced/extension/twitch/patches/DebugModePatch;->isDebugModeEnabled()Z diff --git a/patches/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt index cca02a2e4..71bc5f54a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitch/misc/settings/SettingsPatch.kt @@ -1,6 +1,6 @@ package app.revanced.patches.twitch.misc.settings -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -55,11 +55,6 @@ val settingsPatch = bytecodePatch( ), ) - val settingsActivityOnCreateMatch by settingsActivityOnCreateFingerprint() - val settingsMenuItemEnumMatch by settingsMenuItemEnumFingerprint() - val menuGroupsUpdatedMatch by menuGroupsUpdatedFingerprint() - val menuGroupsOnClickMatch by menuGroupsOnClickFingerprint() - execute { addResources("twitch", "misc.settings.settingsPatch") @@ -78,8 +73,8 @@ val settingsPatch = bytecodePatch( ) // Hook onCreate to handle fragment creation. - val insertIndex = settingsActivityOnCreateMatch.mutableMethod.implementation!!.instructions.size - 2 - settingsActivityOnCreateMatch.mutableMethod.addInstructionsWithLabels( + val insertIndex = settingsActivityOnCreateFingerprint.method.implementation!!.instructions.size - 2 + settingsActivityOnCreateFingerprint.method.addInstructionsWithLabels( insertIndex, """ invoke-static { p0 }, $ACTIVITY_HOOKS_CLASS_DESCRIPTOR->handleSettingsCreation(Landroidx/appcompat/app/AppCompatActivity;)Z @@ -89,21 +84,21 @@ val settingsPatch = bytecodePatch( """, ExternalLabel( "no_rv_settings_init", - settingsActivityOnCreateMatch.mutableMethod.getInstruction(insertIndex), + settingsActivityOnCreateFingerprint.method.getInstruction(insertIndex), ), ) // Create new menu item for settings menu. - fun Match.injectMenuItem( + fun Fingerprint.injectMenuItem( name: String, value: Int, titleResourceName: String, iconResourceName: String, ) { // Add new static enum member field - mutableClass.staticFields.add( + classDef.staticFields.add( ImmutableField( - mutableMethod.definingClass, + method.definingClass, name, MENU_ITEM_ENUM_CLASS_DESCRIPTOR, AccessFlags.PUBLIC.value or @@ -117,8 +112,8 @@ val settingsPatch = bytecodePatch( ) // Add initializer for the new enum member - mutableMethod.addInstructions( - mutableMethod.implementation!!.instructions.size - 4, + method.addInstructions( + method.implementation!!.instructions.size - 4, """ new-instance v0, $MENU_ITEM_ENUM_CLASS_DESCRIPTOR const-string v1, "$titleResourceName" @@ -135,7 +130,7 @@ val settingsPatch = bytecodePatch( ) } - settingsMenuItemEnumMatch.injectMenuItem( + settingsMenuItemEnumFingerprint.injectMenuItem( REVANCED_SETTINGS_MENU_ITEM_NAME, REVANCED_SETTINGS_MENU_ITEM_ID, REVANCED_SETTINGS_MENU_ITEM_TITLE_RES, @@ -143,7 +138,7 @@ val settingsPatch = bytecodePatch( ) // Intercept settings menu creation and add new menu item. - menuGroupsUpdatedMatch.mutableMethod.addInstructions( + menuGroupsUpdatedFingerprint.method.addInstructions( 0, """ sget-object v0, $MENU_ITEM_ENUM_CLASS_DESCRIPTOR->$REVANCED_SETTINGS_MENU_ITEM_NAME:$MENU_ITEM_ENUM_CLASS_DESCRIPTOR @@ -153,8 +148,7 @@ val settingsPatch = bytecodePatch( ) // Intercept onclick events for the settings menu - - menuGroupsOnClickMatch.mutableMethod.addInstructionsWithLabels( + menuGroupsOnClickFingerprint.method.addInstructionsWithLabels( 0, """ invoke-static {p1}, $ACTIVITY_HOOKS_CLASS_DESCRIPTOR->handleSettingMenuOnClick(Ljava/lang/Enum;)Z @@ -166,7 +160,7 @@ val settingsPatch = bytecodePatch( """, ExternalLabel( "no_rv_settings_onclick", - menuGroupsOnClickMatch.mutableMethod.getInstruction(0), + menuGroupsOnClickFingerprint.method.getInstruction(0), ), ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/interaction/downloads/UnlockDownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/interaction/downloads/UnlockDownloadsPatch.kt index 0f9157d6b..6f2b9c12c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/interaction/downloads/UnlockDownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/interaction/downloads/UnlockDownloadsPatch.kt @@ -1,6 +1,6 @@ package app.revanced.patches.twitter.interaction.downloads -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -19,35 +19,31 @@ val unlockDownloadsPatch = bytecodePatch( ) { compatibleWith("com.twitter.android") - val constructMediaOptionsSheetMatch by constructMediaOptionsSheetFingerprint() - val showDownloadVideoUpsellBottomSheetMatch by showDownloadVideoUpsellBottomSheetFingerprint() - val buildMediaOptionsSheetMatch by buildMediaOptionsSheetFingerprint() - - fun Match.patch(getRegisterAndIndex: Match.() -> Pair) { - val (index, register) = getRegisterAndIndex() - mutableMethod.addInstruction(index, "const/4 v$register, 0x1") - } - execute { + fun Fingerprint.patch(getRegisterAndIndex: Fingerprint.() -> Pair) { + val (index, register) = getRegisterAndIndex() + method.addInstruction(index, "const/4 v$register, 0x1") + } + // Allow downloads for non-premium users. - showDownloadVideoUpsellBottomSheetMatch.patch { + showDownloadVideoUpsellBottomSheetFingerprint.patch { val checkIndex = patternMatch!!.startIndex - val register = mutableMethod.getInstruction(checkIndex).registerA + val register = method.getInstruction(checkIndex).registerA checkIndex to register } // Force show the download menu item. - constructMediaOptionsSheetMatch.patch { - val showDownloadButtonIndex = mutableMethod.instructions.lastIndex - 1 - val register = mutableMethod.getInstruction(showDownloadButtonIndex).registerA + constructMediaOptionsSheetFingerprint.patch { + val showDownloadButtonIndex = method.instructions.lastIndex - 1 + val register = method.getInstruction(showDownloadButtonIndex).registerA showDownloadButtonIndex to register } // Make GIFs downloadable. - val patternMatch = buildMediaOptionsSheetMatch.patternMatch!! - buildMediaOptionsSheetMatch.mutableMethod.apply { + val patternMatch = buildMediaOptionsSheetFingerprint.patternMatch!! + buildMediaOptionsSheetFingerprint.method.apply { val checkMediaTypeIndex = patternMatch.startIndex val checkMediaTypeInstruction = getInstruction(checkMediaTypeIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt index 83b65581e..deee9749f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/layout/viewcount/HideViewCountPatch.kt @@ -11,10 +11,8 @@ val hideViewCountPatch = bytecodePatch( ) { compatibleWith("com.twitter.android") - val viewCountsEnabledMatch by viewCountsEnabledFingerprint() - execute { - viewCountsEnabledMatch.mutableMethod.addInstructions( + viewCountsEnabledFingerprint.method.addInstructions( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt index b7c3d3e7a..286f51afc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/dynamiccolor/DynamicColorPatch.kt @@ -12,8 +12,8 @@ val dynamicColorPatch = resourcePatch( ) { compatibleWith("com.twitter.android") - execute { context -> - val resDirectory = context["res"] + execute { + val resDirectory = get("res") if (!resDirectory.isDirectory) throw PatchException("The res folder can not be found.") val valuesV31Directory = resDirectory.resolve("values-v31") @@ -32,7 +32,7 @@ val dynamicColorPatch = resourcePatch( } } - context.document["res/values-v31/colors.xml"].use { document -> + document("res/values-v31/colors.xml").use { document -> mapOf( "ps__twitter_blue" to "@color/twitter_blue", @@ -53,7 +53,7 @@ val dynamicColorPatch = resourcePatch( } } - context.document["res/values-night-v31/colors.xml"].use { document -> + document("res/values-night-v31/colors.xml").use { document -> mapOf( "twitter_blue" to "@android:color/system_accent1_200", "twitter_blue_fill_pressed" to "@android:color/system_accent1_300", diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/HookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/HookPatch.kt index ca757dcdd..66d1a3f16 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/HookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/HookPatch.kt @@ -2,8 +2,8 @@ package app.revanced.patches.twitter.misc.hook import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.twitter.misc.hook.json.JsonHook +import app.revanced.patches.twitter.misc.hook.json.addJsonHook import app.revanced.patches.twitter.misc.hook.json.jsonHookPatch -import app.revanced.patches.twitter.misc.hook.json.jsonHooks fun hookPatch( name: String, @@ -14,6 +14,6 @@ fun hookPatch( compatibleWith("com.twitter.android") execute { - jsonHooks.addHook(JsonHook(it, hookClassDescriptor)) + addJsonHook(JsonHook(hookClassDescriptor)) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/json/JsonHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/json/JsonHookPatch.kt index 6cde25b50..093305379 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/json/JsonHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/hook/json/JsonHookPatch.kt @@ -1,22 +1,40 @@ package app.revanced.patches.twitter.misc.hook.json -import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.removeInstructions import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.patch.PatchException import app.revanced.patcher.patch.bytecodePatch import app.revanced.patches.reddit.misc.extension.sharedExtensionPatch -import java.io.Closeable import java.io.InvalidClassException /** - * The [JsonHookPatchHook] of the [jsonHookPatch]. + * Add a hook to the [jsonHookPatch]. + * Will not add the hook if it's already added. * - * @see JsonHookPatchHook + * @param jsonHook The [JsonHook] to add. */ -internal lateinit var jsonHooks: JsonHookPatchHook - private set +context(BytecodePatchContext) +fun addJsonHook( + jsonHook: JsonHook, +) { + if (jsonHook.added) return + + jsonHookPatchFingerprint.method.apply { + // Insert hooks right before calling buildList. + val insertIndex = jsonHookPatchFingerprint.patternMatch!!.endIndex + + addInstructions( + insertIndex, + """ + sget-object v1, ${jsonHook.descriptor}->INSTANCE:${jsonHook.descriptor} + invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z + """, + ) + } + + jsonHook.added = true +} private const val JSON_HOOK_CLASS_NAMESPACE = "app/revanced/extension/twitter/patches/hook/json" private const val JSON_HOOK_PATCH_CLASS_DESCRIPTOR = "L$JSON_HOOK_CLASS_NAMESPACE/JsonHookPatch;" @@ -28,45 +46,37 @@ val jsonHookPatch = bytecodePatch( ) { dependsOn(sharedExtensionPatch) - val loganSquareMatch by loganSquareFingerprint() - - execute { context -> - jsonHookPatchFingerprint.apply { + execute { + val jsonFactoryClassDef = jsonHookPatchFingerprint.apply { // Make sure the extension is present. - val jsonHookPatch = context.classBy { classDef -> classDef.type == JSON_HOOK_PATCH_CLASS_DESCRIPTOR } + val jsonHookPatch = classBy { classDef -> classDef.type == JSON_HOOK_PATCH_CLASS_DESCRIPTOR } ?: throw PatchException("Could not find the extension.") - if (!match(context, jsonHookPatch.immutableClass)) { - throw PatchException("Unexpected extension.") - } - }.let { jsonHooks = JsonHookPatchHook(it) } - - // Conveniently find the type to hook a method in, via a named field. - val jsonFactory = loganSquareMatch - .classDef + matchOrNull(jsonHookPatch.immutableClass) + ?: throw PatchException("Unexpected extension.") + }.originalClassDef // Conveniently find the type to hook a method in, via a named field. .fields .firstOrNull { it.name == "JSON_FACTORY" } ?.type - .let { type -> - context.classBy { it.type == type }?.mutableClass - } ?: throw PatchException("Could not find required class.") + .let { type -> classes.find { it.type == type } } ?: throw PatchException("Could not find required class.") // Hook the methods first parameter. - jsonInputStreamFingerprint - .apply { match(context, jsonFactory) } - .match - ?.mutableMethod - ?.addInstructions( - 0, - """ - invoke-static { p1 }, $JSON_HOOK_PATCH_CLASS_DESCRIPTOR->parseJsonHook(Ljava/io/InputStream;)Ljava/io/InputStream; - move-result-object p1 - """, - ) ?: throw PatchException("Could not find method to hook.") + jsonInputStreamFingerprint.match(jsonFactoryClassDef).method.addInstructions( + 0, + """ + invoke-static { p1 }, $JSON_HOOK_PATCH_CLASS_DESCRIPTOR->parseJsonHook(Ljava/io/InputStream;)Ljava/io/InputStream; + move-result-object p1 + """, + ) } finalize { - jsonHooks.close() + // Remove hooks.add(dummyHook). + jsonHookPatchFingerprint.method.apply { + val addDummyHookIndex = jsonHookPatchFingerprint.patternMatch!!.endIndex - 2 + + removeInstructions(addDummyHookIndex, 2) + } } } @@ -75,15 +85,17 @@ val jsonHookPatch = bytecodePatch( * The class has to extend on **JsonHook**. * The class has to be a Kotlin object class, or at least have an INSTANCE field of itself. * - * @param context The [BytecodePatchContext] of the current patch. * @param descriptor The class descriptor of the hook. * @throws ClassNotFoundException If the class could not be found. */ -class JsonHook(context: BytecodePatchContext, internal val descriptor: String) { +context(BytecodePatchContext) +class JsonHook( + internal val descriptor: String, +) { internal var added = false init { - context.classBy { it.type == descriptor }?.let { + classBy { it.type == descriptor }?.let { it.mutableClass.also { classDef -> if ( classDef.superclass != JSON_HOOK_CLASS_DESCRIPTOR || @@ -95,47 +107,3 @@ class JsonHook(context: BytecodePatchContext, internal val descriptor: String) { } ?: throw ClassNotFoundException("Failed to find hook class $descriptor") } } - -/** - * A hook for the [jsonHookPatch]. - * - * @param jsonHookPatchFingerprint The [jsonHookPatchFingerprint] to hook. - */ -class JsonHookPatchHook(jsonHookPatchFingerprint: Fingerprint) : Closeable { - private val jsonHookPatchMatch = jsonHookPatchFingerprint.match!! - private val jsonHookPatchIndex = jsonHookPatchMatch.patternMatch!!.endIndex - - /** - * Add a hook to the [jsonHookPatch]. - * Will not add the hook if it's already added. - * - * @param jsonHook The [JsonHook] to add. - */ - fun addHook(jsonHook: JsonHook) { - if (jsonHook.added) return - - jsonHookPatchMatch.mutableMethod.apply { - // Insert hooks right before calling buildList. - val insertIndex = jsonHookPatchIndex - - addInstructions( - insertIndex, - """ - sget-object v1, ${jsonHook.descriptor}->INSTANCE:${jsonHook.descriptor} - invoke-interface {v0, v1}, Ljava/util/List;->add(Ljava/lang/Object;)Z - """, - ) - } - - jsonHook.added = true - } - - override fun close() { - // Remove hooks.add(dummyHook). - jsonHookPatchMatch.mutableMethod.apply { - val addDummyHookIndex = jsonHookPatchIndex - 2 - - removeInstructions(addDummyHookIndex, 2) - } - } -} diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt index f42000ac5..35131aa03 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/ChangeLinkSharingDomainPatch.kt @@ -51,23 +51,20 @@ val changeLinkSharingDomainPatch = bytecodePatch( required = true, ) - val linkSharingDomainMatch by linkSharingDomainFingerprint() - val linkBuilderMatch by linkBuilderFingerprint() - val linkResourceGetterMatch by linkResourceGetterFingerprint() - execute { - val replacementIndex = - linkSharingDomainMatch.stringMatches!!.first().index - val domainRegister = - linkSharingDomainMatch.mutableMethod.getInstruction(replacementIndex).registerA - linkSharingDomainMatch.mutableMethod.replaceInstruction( + val replacementIndex = + linkSharingDomainFingerprint.stringMatches!!.first().index + val domainRegister = + linkSharingDomainFingerprint.method.getInstruction(replacementIndex).registerA + + linkSharingDomainFingerprint.method.replaceInstruction( replacementIndex, "const-string v$domainRegister, \"https://$domainName\"", ) // Replace the domain name when copying a link with "Copy link" button. - linkBuilderMatch.mutableMethod.apply { + linkBuilderFingerprint.method.apply { addInstructions( 0, """ @@ -79,7 +76,7 @@ val changeLinkSharingDomainPatch = bytecodePatch( } // Used in the Share via... dialog. - linkResourceGetterMatch.mutableMethod.apply { + linkResourceGetterFingerprint.method.apply { val templateIdConstIndex = indexOfFirstLiteralInstructionOrThrow(tweetShareLinkTemplateId) // Format the link with the new domain name register (1 instruction below the const). diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt index c9cea00c7..03033e7d5 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/OpenLinksWithAppChooserPatch.kt @@ -12,14 +12,12 @@ val openLinksWithAppChooserPatch = bytecodePatch( ) { compatibleWith("com.twitter.android"("10.48.0-release.0")) - val openLinkMatch by openLinkFingerprint() - execute { val methodReference = "Lapp/revanced/extension/twitter/patches/links/OpenLinksWithAppChooserPatch;->" + "openWithChooser(Landroid/content/Context;Landroid/content/Intent;)V" - openLinkMatch.mutableMethod.addInstructions( + openLinkFingerprint.method.addInstructions( 0, """ invoke-static { p0, p1 }, $methodReference diff --git a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/SanitizeSharingLinksPatch.kt b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/SanitizeSharingLinksPatch.kt index 62e7a4f00..1cde6fc82 100644 --- a/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/SanitizeSharingLinksPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/twitter/misc/links/SanitizeSharingLinksPatch.kt @@ -10,10 +10,8 @@ val sanitizeSharingLinksPatch = bytecodePatch( ) { compatibleWith("com.twitter.android") - val sanitizeSharingLinksMatch by sanitizeSharingLinksFingerprint() - execute { - sanitizeSharingLinksMatch.mutableMethod.addInstructions( + sanitizeSharingLinksFingerprint.method.addInstructions( 0, """ # Method takes in a link (string, param 0) and then appends the tracking query params, diff --git a/patches/src/main/kotlin/app/revanced/patches/vsco/misc/pro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/vsco/misc/pro/UnlockProPatch.kt index dae609164..2135b1ec4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/vsco/misc/pro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/vsco/misc/pro/UnlockProPatch.kt @@ -10,10 +10,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("com.vsco.cam"("345")) - val revCatSubscriptionMatch by revCatSubscriptionFingerprint() - execute { // Set isSubscribed to true. - revCatSubscriptionMatch.mutableMethod.addInstruction(0, "const p1, 0x1") + revCatSubscriptionFingerprint.method.addInstruction(0, "const p1, 0x1") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/Fingerprints.kt index 41627aaaa..6eb7bd176 100644 --- a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/Fingerprints.kt @@ -11,7 +11,7 @@ internal val getMessagingCertFingerprint = fingerprint { ) } -internal val getReqistrationCertFingerprint = fingerprint { +internal val getRegistrationCertFingerprint = fingerprint { returns("Ljava/lang/String;") strings( "FirebaseRemoteConfig", diff --git a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/FirebaseGetCertPatch.kt b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/FirebaseGetCertPatch.kt index f3485c8b5..82a9008a4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/FirebaseGetCertPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/firebasegetcert/FirebaseGetCertPatch.kt @@ -8,12 +8,9 @@ val firebaseGetCertPatch = bytecodePatch( ) { compatibleWith("de.dwd.warnapp") - val getRegistrationCertMatch by getReqistrationCertFingerprint() - val getMessagingCertMatch by getMessagingCertFingerprint() - execute { - listOf(getRegistrationCertMatch, getMessagingCertMatch).forEach { match -> - match.mutableMethod.addInstructions( + listOf(getRegistrationCertFingerprint, getMessagingCertFingerprint).forEach { match -> + match.method.addInstructions( 0, """ const-string v0, "0799DDF0414D3B3475E88743C91C0676793ED450" diff --git a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/promocode/PromoCodeUnlockPatch.kt b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/promocode/PromoCodeUnlockPatch.kt index 67b930ae8..8acb8a650 100644 --- a/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/promocode/PromoCodeUnlockPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/warnwetter/misc/promocode/PromoCodeUnlockPatch.kt @@ -13,10 +13,8 @@ val promoCodeUnlockPatch = bytecodePatch( compatibleWith("de.dwd.warnapp"("4.2.2")) - val promoCodeUnlockMatch by promoCodeUnlockFingerprint() - execute { - promoCodeUnlockMatch.mutableMethod.addInstructions( + promoCodeUnlockFingerprint.method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/willhaben/ads/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/willhaben/ads/HideAdsPatch.kt index 6c0d99cca..b3dd1a3fc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/willhaben/ads/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/willhaben/ads/HideAdsPatch.kt @@ -10,11 +10,8 @@ internal val hideAdsPatch = bytecodePatch( ) { compatibleWith("at.willhaben") - adResolverFingerprint() - whAdViewInjectorFingerprint() - execute { - adResolverFingerprint.returnEarly() - whAdViewInjectorFingerprint.returnEarly() + adResolverFingerprint.method.returnEarly() + whAdViewInjectorFingerprint.method.returnEarly() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/windyapp/misc/unlockpro/UnlockProPatch.kt b/patches/src/main/kotlin/app/revanced/patches/windyapp/misc/unlockpro/UnlockProPatch.kt index 3f4cac757..2478b235d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/windyapp/misc/unlockpro/UnlockProPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/windyapp/misc/unlockpro/UnlockProPatch.kt @@ -10,10 +10,8 @@ val unlockProPatch = bytecodePatch( ) { compatibleWith("co.windyapp.android") - val checkProMatch by checkProFingerprint() - execute { - checkProMatch.mutableMethod.addInstructions( + checkProFingerprint.method.addInstructions( 0, """ const/16 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/HideAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/HideAdsPatch.kt index 3d5384ac4..3bd82fb26 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/HideAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/HideAdsPatch.kt @@ -78,8 +78,8 @@ val hideAdsPatch = bytecodePatch( ), ) - execute { context -> - context.classes.forEach { classDef -> + execute { + classes.forEach { classDef -> classDef.methods.forEach { method -> with(method.implementation) { this?.instructions?.forEachIndexed { index, instruction -> @@ -101,7 +101,7 @@ val hideAdsPatch = bytecodePatch( // Hide the view val viewRegister = (this as Instruction35c).registerC - context.proxy(classDef) + proxy(classDef) .mutableClass .findMutableMethodOf(method) .injectHideViewCall( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/getpremium/HideGetPremiumPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/getpremium/HideGetPremiumPatch.kt index 67817d410..b4f044228 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/getpremium/HideGetPremiumPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/getpremium/HideGetPremiumPatch.kt @@ -34,8 +34,6 @@ val hideGetPremiumPatch = bytecodePatch( ), ) - val getPremiumViewMatch by getPremiumViewFingerprint() - execute { addResources("youtube", "ad.getpremium.hideGetPremiumPatch") @@ -43,8 +41,8 @@ val hideGetPremiumPatch = bytecodePatch( SwitchPreference("revanced_hide_get_premium"), ) - getPremiumViewMatch.mutableMethod.apply { - val startIndex = getPremiumViewMatch.patternMatch!!.startIndex + getPremiumViewFingerprint.method.apply { + val startIndex = getPremiumViewFingerprint.patternMatch!!.startIndex val measuredWidthRegister = getInstruction(startIndex).registerA val measuredHeightInstruction = getInstruction(startIndex + 1) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/VideoAdsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/VideoAdsPatch.kt index 1f9ce8aa9..b073814bf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/VideoAdsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/VideoAdsPatch.kt @@ -33,8 +33,6 @@ val videoAdsPatch = bytecodePatch( ), ) - val loadVideoAdsMatch by loadVideoAdsFingerprint() - execute { addResources("youtube", "ad.video.videoAdsPatch") @@ -42,7 +40,7 @@ val videoAdsPatch = bytecodePatch( SwitchPreference("revanced_hide_video_ads"), ) - loadVideoAdsMatch.mutableMethod.addInstructionsWithLabels( + loadVideoAdsFingerprint.method.addInstructionsWithLabels( 0, """ invoke-static { }, Lapp/revanced/extension/youtube/patches/VideoAdsPatch;->shouldShowAds()Z @@ -50,7 +48,7 @@ val videoAdsPatch = bytecodePatch( if-nez v0, :show_video_ads return-void """, - ExternalLabel("show_video_ads", loadVideoAdsMatch.mutableMethod.getInstruction(0)), + ExternalLabel("show_video_ads", loadVideoAdsFingerprint.method.getInstruction(0)), ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlPatch.kt index ecfb1edda..f18264e93 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/copyvideourl/CopyVideoUrlPatch.kt @@ -19,7 +19,7 @@ private val copyVideoUrlResourcePatch = resourcePatch { addResourcesPatch, ) - execute { context -> + execute { addResources("youtube", "interaction.copyvideourl.copyVideoUrlResourcePatch") PreferenceScreen.PLAYER.addPreferences( @@ -27,7 +27,7 @@ private val copyVideoUrlResourcePatch = resourcePatch { SwitchPreference("revanced_copy_video_url_timestamp"), ) - context.copyResources( + copyResources( "copyvideourl", ResourceGroup( resourceDirectoryName = "drawable", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch.kt index b930c977e..cf000474f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/dialog/RemoveViewerDiscretionDialogPatch.kt @@ -34,8 +34,6 @@ val removeViewerDiscretionDialogPatch = bytecodePatch( ), ) - val createDialogMatch by createDialogFingerprint() - val extensionMethodDescriptor = "Lapp/revanced/extension/youtube/patches/RemoveViewerDiscretionDialogPatch;->" + "confirmDialog(Landroid/app/AlertDialog;)V" @@ -47,7 +45,7 @@ val removeViewerDiscretionDialogPatch = bytecodePatch( SwitchPreference("revanced_remove_viewer_discretion_dialog"), ) - createDialogMatch.mutableMethod.apply { + createDialogFingerprint.method.apply { val showDialogIndex = implementation!!.instructions.lastIndex - 2 val dialogRegister = getInstruction(showDialogIndex).registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/DownloadsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/DownloadsPatch.kt index 2bdda2fe5..702270683 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/DownloadsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/DownloadsPatch.kt @@ -26,7 +26,7 @@ private val downloadsResourcePatch = resourcePatch { addResourcesPatch, ) - execute { context -> + execute { addResources("youtube", "interaction.downloads.downloadsResourcePatch") PreferenceScreen.PLAYER.addPreferences( @@ -41,7 +41,7 @@ private val downloadsResourcePatch = resourcePatch { ), ) - context.copyResources( + copyResources( "downloads", ResourceGroup("drawable", "revanced_yt_download_button.xml"), ) @@ -77,22 +77,19 @@ val downloadsPatch = bytecodePatch( ), ) - val offlineVideoEndpointMatch by offlineVideoEndpointFingerprint() - val mainActivityMatch by mainActivityFingerprint() - execute { initializeBottomControl(BUTTON_DESCRIPTOR) injectVisibilityCheckCall(BUTTON_DESCRIPTOR) // Main activity is used to launch downloader intent. - mainActivityMatch.mutableMethod.apply { + mainActivityFingerprint.method.apply { addInstruction( implementation!!.instructions.lastIndex, "invoke-static { p0 }, $EXTENSION_CLASS_DESCRIPTOR->activityCreated(Landroid/app/Activity;)V", ) } - offlineVideoEndpointMatch.mutableMethod.apply { + offlineVideoEndpointFingerprint.method.apply { addInstructionsWithLabels( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt index 121616c9b..a8ec77ebf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/DisablePreciseSeekingGesturePatch.kt @@ -10,7 +10,6 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch -import app.revanced.util.applyMatch @Suppress("unused") val disablePreciseSeekingGesturePatch = bytecodePatch( @@ -34,9 +33,7 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( ), ) - val swipingUpGestureParentMatch by swipingUpGestureParentFingerprint() - - execute { context -> + execute { addResources("youtube", "interaction.seekbar.disablePreciseSeekingGesturePatch") PreferenceScreen.SEEKBAR.addPreferences( @@ -45,10 +42,9 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( val extensionMethodDescriptor = "Lapp/revanced/extension/youtube/patches/DisablePreciseSeekingGesturePatch;" - allowSwipingUpGestureFingerprint.applyMatch( - context, - swipingUpGestureParentMatch, - ).mutableMethod.apply { + allowSwipingUpGestureFingerprint.match( + swipingUpGestureParentFingerprint.originalClassDef, + ).method.apply { addInstructionsWithLabels( 0, """ @@ -61,10 +57,9 @@ val disablePreciseSeekingGesturePatch = bytecodePatch( ) } - showSwipingUpGuideFingerprint.applyMatch( - context, - swipingUpGestureParentMatch, - ).mutableMethod.apply { + showSwipingUpGuideFingerprint.match( + swipingUpGestureParentFingerprint.originalClassDef, + ).method.apply { addInstructionsWithLabels( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt index f88753e92..afc2eddae 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSeekbarTappingPatch.kt @@ -36,9 +36,6 @@ val enableSeekbarTappingPatch = bytecodePatch( ), ) - val onTouchEventHandlerMatch by onTouchEventHandlerFingerprint() - val seekbarTappingMatch by seekbarTappingFingerprint() - execute { addResources("youtube", "interaction.seekbar.enableSeekbarTappingPatch") @@ -47,9 +44,9 @@ val enableSeekbarTappingPatch = bytecodePatch( ) // Find the required methods to tap the seekbar. - val patternMatch = onTouchEventHandlerMatch.patternMatch!! + val patternMatch = onTouchEventHandlerFingerprint.patternMatch!! - fun getReference(index: Int) = onTouchEventHandlerMatch.mutableMethod.getInstruction(index) + fun getReference(index: Int) = onTouchEventHandlerFingerprint.method.getInstruction(index) .reference as MethodReference val seekbarTappingMethods = buildMap { @@ -57,9 +54,9 @@ val enableSeekbarTappingPatch = bytecodePatch( put("O", getReference(patternMatch.endIndex)) } - val insertIndex = seekbarTappingMatch.patternMatch!!.endIndex - 1 + val insertIndex = seekbarTappingFingerprint.patternMatch!!.endIndex - 1 - seekbarTappingMatch.mutableMethod.apply { + seekbarTappingFingerprint.method.apply { val thisInstanceRegister = getInstruction(insertIndex - 1).registerC val freeRegister = 0 diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt index f61947609..12d7451d6 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/EnableSlideToSeekPatch.kt @@ -17,6 +17,7 @@ import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction internal const val EXTENSION_METHOD_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/SlideToSeekPatch;->isSlideToSeekDisabled(Z)Z" @@ -46,11 +47,6 @@ val enableSlideToSeekPatch = bytecodePatch( ), ) - val slideToSeekMatch by slideToSeekFingerprint() - val disableFastForwardLegacyMatch by disableFastForwardLegacyFingerprint() - val disableFastForwardGestureMatch by disableFastForwardGestureFingerprint() - val disableFastForwardNoticeMatch by disableFastForwardNoticeFingerprint() - execute { addResources("youtube", "interaction.seekbar.enableSlideToSeekPatch") @@ -61,12 +57,13 @@ val enableSlideToSeekPatch = bytecodePatch( var modifiedMethods = false // Restore the behaviour to slide to seek. - val checkIndex = slideToSeekMatch.patternMatch!!.startIndex - val checkReference = slideToSeekMatch.mutableMethod.getInstruction(checkIndex) + + val checkIndex = slideToSeekFingerprint.patternMatch!!.startIndex + val checkReference = slideToSeekFingerprint.method.getInstruction(checkIndex) .getReference()!! // A/B check method was only called on this class. - slideToSeekMatch.mutableClass.methods.forEach { method -> + slideToSeekFingerprint.classDef.methods.forEach { method -> method.findInstructionIndicesReversed { opcode == Opcode.INVOKE_VIRTUAL && getReference() == checkReference }.forEach { index -> @@ -78,7 +75,7 @@ val enableSlideToSeekPatch = bytecodePatch( """ invoke-static { v$register }, $EXTENSION_METHOD_DESCRIPTOR move-result v$register - """ + """, ) } @@ -91,11 +88,11 @@ val enableSlideToSeekPatch = bytecodePatch( // Disable the double speed seek gesture. if (is_19_17_or_greater) { arrayOf( - disableFastForwardGestureMatch, - disableFastForwardNoticeMatch, - ).forEach { - it.mutableMethod.apply { - val targetIndex = it.patternMatch!!.endIndex + disableFastForwardGestureFingerprint, + disableFastForwardNoticeFingerprint, + ).forEach { fingerprint -> + fingerprint.method.apply { + val targetIndex = fingerprint.patternMatch!!.endIndex val targetRegister = getInstruction(targetIndex).registerA addInstructions( @@ -108,19 +105,17 @@ val enableSlideToSeekPatch = bytecodePatch( } } } else { - disableFastForwardLegacyMatch.let { - it.mutableMethod.apply { - val insertIndex = it.patternMatch!!.endIndex + 1 - val targetRegister = getInstruction(insertIndex).registerA + disableFastForwardLegacyFingerprint.method.apply { + val insertIndex = disableFastForwardLegacyFingerprint.patternMatch!!.endIndex + 1 + val targetRegister = getInstruction(insertIndex).registerA - addInstructions( - insertIndex, - """ - invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR - move-result v$targetRegister - """ - ) - } + addInstructions( + insertIndex, + """ + invoke-static { v$targetRegister }, $EXTENSION_METHOD_DESCRIPTOR + move-result v$targetRegister + """, + ) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt index 1116f56be..a9ad7563b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/SeekbarThumbnailsPatch.kt @@ -39,10 +39,6 @@ val seekbarThumbnailsPatch = bytecodePatch( ) ) - val fullscreenSeekbarThumbnailsQualityMatch by fullscreenSeekbarThumbnailsQualityFingerprint() - - val fullscreenSeekbarThumbnailsMatch by fullscreenSeekbarThumbnailsFingerprint() - execute { addResources("youtube", "layout.seekbar.seekbarThumbnailsPatch") @@ -60,7 +56,7 @@ val seekbarThumbnailsPatch = bytecodePatch( ) ) - fullscreenSeekbarThumbnailsMatch.mutableMethod.apply { + fullscreenSeekbarThumbnailsFingerprint.method.apply { val moveResultIndex = instructions.lastIndex - 1 addInstruction( @@ -70,7 +66,7 @@ val seekbarThumbnailsPatch = bytecodePatch( } } - fullscreenSeekbarThumbnailsQualityMatch.mutableMethod.addInstructions( + fullscreenSeekbarThumbnailsQualityFingerprint.method.addInstructions( 0, """ invoke-static { }, $EXTENSION_CLASS_DESCRIPTOR->useHighQualityFullscreenThumbnails()Z diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt index 8ffbb2770..6b6668420 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/swipecontrols/SwipeControlsPatch.kt @@ -13,10 +13,7 @@ import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.mainActivityFingerprint -import app.revanced.util.ResourceGroup -import app.revanced.util.copyResources -import app.revanced.util.transformMethods -import app.revanced.util.traverseClassHierarchy +import app.revanced.util.* import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.immutable.ImmutableMethod @@ -26,7 +23,7 @@ private val swipeControlsResourcePatch = resourcePatch { addResourcesPatch, ) - execute { context -> + execute { addResources("youtube", "interaction.swipecontrols.swipeControlsResourcePatch") PreferenceScreen.SWIPE_CONTROLS.addPreferences( @@ -42,7 +39,7 @@ private val swipeControlsResourcePatch = resourcePatch { TextPreference("revanced_swipe_threshold", inputType = InputType.NUMBER), ) - context.copyResources( + copyResources( "swipecontrols", ResourceGroup( "drawable", @@ -77,19 +74,16 @@ val swipeControlsPatch = bytecodePatch( ), ) - val mainActivityMatch by mainActivityFingerprint() - val swipeControlsHostActivityMatch by swipeControlsHostActivityFingerprint() - - execute { context -> - val wrapperClass = swipeControlsHostActivityMatch.mutableClass - val targetClass = mainActivityMatch.mutableClass + execute { + val wrapperClass = swipeControlsHostActivityFingerprint.classDef + val targetClass = mainActivityFingerprint.classDef // Inject the wrapper class from the extension into the class hierarchy of MainActivity. wrapperClass.setSuperClass(targetClass.superclass) targetClass.setSuperClass(wrapperClass.type) // Ensure all classes and methods in the hierarchy are non-final, so we can override them in the extension. - context.traverseClassHierarchy(targetClass) { + traverseClassHierarchy(targetClass) { accessFlags = accessFlags and AccessFlags.FINAL.value.inv() transformMethods { ImmutableMethod( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt index 0e9853355..4dfa092f0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/AutoCaptionsPatch.kt @@ -32,10 +32,6 @@ val autoCaptionsPatch = bytecodePatch( ), ) - val startVideoInformerMatch by startVideoInformerFingerprint() - val subtitleButtonControllerMatch by subtitleButtonControllerFingerprint() - val subtitleTrackMatch by subtitleTrackFingerprint() - execute { addResources("youtube", "layout.autocaptions.autoCaptionsPatch") @@ -44,10 +40,10 @@ val autoCaptionsPatch = bytecodePatch( ) mapOf( - startVideoInformerMatch to 0, - subtitleButtonControllerMatch to 1, - ).forEach { (match, enabled) -> - match.mutableMethod.addInstructions( + startVideoInformerFingerprint to 0, + subtitleButtonControllerFingerprint to 1, + ).forEach { (fingerprint, enabled) -> + fingerprint.method.addInstructions( 0, """ const/4 v0, 0x$enabled @@ -56,7 +52,7 @@ val autoCaptionsPatch = bytecodePatch( ) } - subtitleTrackMatch.mutableMethod.addInstructions( + subtitleTrackFingerprint.method.addInstructions( 0, """ invoke-static {}, Lapp/revanced/extension/youtube/patches/DisableAutoCaptionsPatch;->autoCaptionsEnabled()Z diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt index d1670aeda..aee051ea1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/CustomBrandingPatch.kt @@ -65,7 +65,7 @@ val customBrandingPatch = resourcePatch( """.trimIndentMultiline(), ) - execute { context -> + execute { icon?.let { icon -> // Change the app icon. mipmapDirectories.map { directory -> @@ -76,7 +76,7 @@ val customBrandingPatch = resourcePatch( }.let { resourceGroups -> if (icon != REVANCED_ICON) { val path = File(icon) - val resourceDirectory = context["res"] + val resourceDirectory = get("res") resourceGroups.forEach { group -> val fromDirectory = path.resolve(group.resourceDirectoryName) @@ -90,14 +90,14 @@ val customBrandingPatch = resourcePatch( } } } else { - resourceGroups.forEach { context.copyResources("custom-branding", it) } + resourceGroups.forEach { copyResources("custom-branding", it) } } } } appName?.let { name -> // Change the app name. - val manifest = context["AndroidManifest.xml"] + val manifest = get("AndroidManifest.xml") manifest.writeText( manifest.readText() .replace( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt index c4c9c0699..e45680789 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/branding/header/ChangeHeaderPatch.kt @@ -63,10 +63,10 @@ val changeHeaderPatch = resourcePatch( required = true, ) - execute { context -> + execute { // The directories to copy the header to. val targetResourceDirectories = targetResourceDirectoryNames.keys.mapNotNull { - context["res"].resolve(it).takeIf(File::exists) + get("res").resolve(it).takeIf(File::exists) } // The files to replace in the target directories. val targetResourceFiles = targetResourceDirectoryNames.keys.map { directoryName -> @@ -95,14 +95,14 @@ val changeHeaderPatch = resourcePatch( val toHeader = { overwriteFromTo(HEADER_FILE_NAME, PREMIUM_HEADER_FILE_NAME) } val toReVanced = { // Copy the ReVanced header to the resource directories. - targetResourceFiles.forEach { context.copyResources("change-header/revanced", it) } + targetResourceFiles.forEach { copyResources("change-header/revanced", it) } // Overwrite the premium with the custom header as well. toHeader() } val toReVancedBorderless = { // Copy the ReVanced borderless header to the resource directories. - targetResourceFiles.forEach { context.copyResources("change-header/revanced-borderless", it) } + targetResourceFiles.forEach { copyResources("change-header/revanced-borderless", it) } // Overwrite the premium with the custom header as well. toHeader() @@ -115,7 +115,7 @@ val changeHeaderPatch = resourcePatch( // For each source folder, copy the files to the target resource directories. sourceFolders.forEach { dpiSourceFolder -> - val targetDpiFolder = context["res"].resolve(dpiSourceFolder.name) + val targetDpiFolder = get("res").resolve(dpiSourceFolder.name) if (!targetDpiFolder.exists()) return@forEach val imgSourceFiles = dpiSourceFolder.listFiles { file -> file.isFile }!! diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt index f793410d3..e25eb0f55 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/NavigationButtonsPatch.kt @@ -19,6 +19,7 @@ import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction internal const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/NavigationButtonsPatch;" @@ -45,9 +46,6 @@ val navigationButtonsPatch = bytecodePatch( ), ) - val addCreateButtonViewMatch by addCreateButtonViewFingerprint() - val createPivotBarMatch by createPivotBarFingerprint() - execute { addResources("youtube", "layout.buttons.navigation.navigationButtonsPatch") @@ -67,8 +65,8 @@ val navigationButtonsPatch = bytecodePatch( ) // Switch create with notifications button. - addCreateButtonViewMatch.mutableMethod.apply { - val stringIndex = addCreateButtonViewMatch.stringMatches!!.find { match -> + addCreateButtonViewFingerprint.method.apply { + val stringIndex = addCreateButtonViewFingerprint.stringMatches!!.find { match -> match.string == ANDROID_AUTOMOTIVE_STRING }!!.index @@ -86,7 +84,7 @@ val navigationButtonsPatch = bytecodePatch( } // Hide navigation button labels. - createPivotBarMatch.mutableMethod.apply { + createPivotBarFingerprint.method.apply { val setTextIndex = indexOfFirstInstructionOrThrow { getReference()?.name == "setText" } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt index d0a2e1f6d..63c4af749 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/overlay/HidePlayerOverlayButtonsPatch.kt @@ -18,10 +18,7 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.layoutConstructorFingerprint import app.revanced.patches.youtube.shared.subtitleButtonControllerFingerprint -import app.revanced.util.getReference -import app.revanced.util.indexOfFirstInstructionOrThrow -import app.revanced.util.indexOfFirstLiteralInstructionOrThrow -import app.revanced.util.indexOfFirstResourceIdOrThrow +import app.revanced.util.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction @@ -66,11 +63,6 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( ), ) - val playerControlsPreviousNextOverlayTouchMatch by playerControlsPreviousNextOverlayTouchFingerprint() - val mediaRouteButtonMatch by mediaRouteButtonFingerprint() - val subtitleButtonControllerMatch by subtitleButtonControllerFingerprint() - val layoutConstructorMatch by layoutConstructorFingerprint() - execute { addResources("youtube", "layout.buttons.overlay.hidePlayerOverlayButtonsPatch") @@ -83,7 +75,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( // region Hide player next/previous button. - playerControlsPreviousNextOverlayTouchMatch.mutableMethod.apply { + playerControlsPreviousNextOverlayTouchFingerprint.method.apply { val resourceIndex = indexOfFirstLiteralInstructionOrThrow(playerControlPreviousButtonTouchArea) val insertIndex = indexOfFirstInstructionOrThrow(resourceIndex) { @@ -104,7 +96,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( // region Hide cast button. - mediaRouteButtonMatch.mutableMethod.addInstructions( + mediaRouteButtonFingerprint.method.addInstructions( 0, """ invoke-static { p1 }, $EXTENSION_CLASS_DESCRIPTOR->getCastButtonOverrideV2(I)I @@ -116,7 +108,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( // region Hide captions button. - subtitleButtonControllerMatch.mutableMethod.apply { + subtitleButtonControllerFingerprint.method.apply { // Due to previously applied patches, scanResult index cannot be used in this context val insertIndex = indexOfFirstInstructionOrThrow(Opcode.IGET_BOOLEAN) + 1 @@ -130,7 +122,7 @@ val hidePlayerOverlayButtonsPatch = bytecodePatch( // region Hide autoplay button. - layoutConstructorMatch.mutableMethod.apply { + layoutConstructorFingerprint.method.apply { val constIndex = indexOfFirstResourceIdOrThrow("autonav_toggle") val constRegister = getInstruction(constIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/endscreencards/HideEndscreenCardsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/endscreencards/HideEndscreenCardsPatch.kt index 7b5eb1ff4..56a97f241 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/endscreencards/HideEndscreenCardsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/endscreencards/HideEndscreenCardsPatch.kt @@ -13,7 +13,7 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch -import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction21c +import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction internal var layoutCircle = -1L private set @@ -65,19 +65,15 @@ val hideEndscreenCardsPatch = bytecodePatch( ), ) - val layoutCircleMatch by layoutCircleFingerprint() - val layoutIconMatch by layoutIconFingerprint() - val layoutVideoMatch by layoutVideoFingerprint() - execute { listOf( - layoutCircleMatch, - layoutIconMatch, - layoutVideoMatch, - ).forEach { - it.mutableMethod.apply { - val insertIndex = it.patternMatch!!.endIndex + 1 - val viewRegister = getInstruction(insertIndex - 1).registerA + layoutCircleFingerprint, + layoutIconFingerprint, + layoutVideoFingerprint, + ).forEach { fingerprint -> + fingerprint.method.apply { + val insertIndex = fingerprint.patternMatch!!.endIndex + 1 + val viewRegister = getInstruction(insertIndex - 1).registerA addInstruction( insertIndex, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt index 90d622540..7c7de97a2 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/DisableFullscreenAmbientModePatch.kt @@ -39,8 +39,6 @@ val disableFullscreenAmbientModePatch = bytecodePatch( ), ) - val setFullScreenBackgroundColorMatch by setFullScreenBackgroundColorFingerprint() - execute { addResources("youtube", "layout.hide.fullscreenambientmode.disableFullscreenAmbientModePatch") @@ -48,7 +46,7 @@ val disableFullscreenAmbientModePatch = bytecodePatch( SwitchPreference("revanced_disable_fullscreen_ambient_mode"), ) - setFullScreenBackgroundColorMatch.mutableMethod.apply { + setFullScreenBackgroundColorFingerprint.method.apply { val insertIndex = indexOfFirstInstructionReversedOrThrow { getReference()?.name == "setBackgroundColor" } @@ -59,7 +57,7 @@ val disableFullscreenAmbientModePatch = bytecodePatch( """ invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->getFullScreenBackgroundColor(I)I move-result v$register - """ + """, ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt index 60c973c32..39cbc4808 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/HideLayoutComponentsPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.hide.general +import app.revanced.patcher.Fingerprint import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions @@ -21,7 +22,6 @@ import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch import app.revanced.patches.youtube.misc.navigation.navigationBarHookPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch -import app.revanced.util.applyMatch import app.revanced.util.findInstructionIndicesReversedOrThrow import app.revanced.util.getReference import com.android.tools.smali.dexlib2.Opcode @@ -132,18 +132,7 @@ val hideLayoutComponentsPatch = bytecodePatch( ), ) - val parseElementFromBufferMatch by parseElementFromBufferFingerprint() - val playerOverlayMatch by playerOverlayFingerprint() - val hideShowMoreButtonMatch by hideShowMoreButtonFingerprint() - val albumCardsMatch by albumCardsFingerprint() - val crowdfundingBoxMatch by crowdfundingBoxFingerprint() - val yoodlesImageViewMatch by yoodlesImageViewFingerprint() - val relatedChipCloudMatch by relatedChipCloudFingerprint() - val searchResultsChipBarMatch by searchResultsChipBarFingerprint() - val showFloatingMicrophoneButtonMatch by showFloatingMicrophoneButtonFingerprint() - val filterBarHeightMatch by filterBarHeightFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.hide.general.hideLayoutComponentsPatch") PreferenceScreen.PLAYER.addPreferences( @@ -253,9 +242,9 @@ val hideLayoutComponentsPatch = bytecodePatch( // region Mix playlists - val startIndex = parseElementFromBufferMatch.patternMatch!!.startIndex + val startIndex = parseElementFromBufferFingerprint.patternMatch!!.startIndex - parseElementFromBufferMatch.mutableMethod.apply { + parseElementFromBufferFingerprint.method.apply { val freeRegister = "v0" val byteArrayParameter = "p3" val conversionContextRegister = getInstruction(startIndex).registerA @@ -277,10 +266,9 @@ val hideLayoutComponentsPatch = bytecodePatch( // region Watermark (legacy code for old versions of YouTube) - showWatermarkFingerprint.applyMatch( - context, - playerOverlayMatch, - ).mutableMethod.apply { + showWatermarkFingerprint.match( + playerOverlayFingerprint.originalClassDef, + ).method.apply { val index = implementation!!.instructions.size - 5 removeInstruction(index) @@ -297,8 +285,8 @@ val hideLayoutComponentsPatch = bytecodePatch( // region Show more button - hideShowMoreButtonMatch.mutableMethod.apply { - val moveRegisterIndex = hideShowMoreButtonMatch.patternMatch!!.endIndex + hideShowMoreButtonFingerprint.method.apply { + val moveRegisterIndex = hideShowMoreButtonFingerprint.patternMatch!!.endIndex val viewRegister = getInstruction(moveRegisterIndex).registerA val insertIndex = moveRegisterIndex + 1 @@ -312,8 +300,8 @@ val hideLayoutComponentsPatch = bytecodePatch( // endregion // region crowdfunding box - crowdfundingBoxMatch.let { - it.mutableMethod.apply { + crowdfundingBoxFingerprint.let { + it.method.apply { val insertIndex = it.patternMatch!!.endIndex val objectRegister = getInstruction(insertIndex).registerA @@ -329,8 +317,8 @@ val hideLayoutComponentsPatch = bytecodePatch( // region hide album cards - albumCardsMatch.let { - it.mutableMethod.apply { + albumCardsFingerprint.let { + it.method.apply { val checkCastAnchorIndex = it.patternMatch!!.endIndex val insertIndex = checkCastAnchorIndex + 1 val register = getInstruction(checkCastAnchorIndex).registerA @@ -347,8 +335,8 @@ val hideLayoutComponentsPatch = bytecodePatch( // region hide floating microphone - showFloatingMicrophoneButtonMatch.let { - it.mutableMethod.apply { + showFloatingMicrophoneButtonFingerprint.let { + it.method.apply { val startIndex = it.patternMatch!!.startIndex val register = getInstruction(startIndex).registerA @@ -366,7 +354,7 @@ val hideLayoutComponentsPatch = bytecodePatch( // region 'Yoodles' - yoodlesImageViewMatch.mutableMethod.apply { + yoodlesImageViewFingerprint.method.apply { findInstructionIndicesReversedOrThrow { getReference()?.name == "setImageDrawable" }.forEach { insertIndex -> @@ -396,11 +384,11 @@ val hideLayoutComponentsPatch = bytecodePatch( * @param hookRegisterOffset The offset to add to the register of the hook. * @param instructions The instructions to add with the register as a parameter. */ - fun Match.patch( + fun Fingerprint.patch( insertIndexOffset: Int = 0, hookRegisterOffset: Int = 0, instructions: (Int) -> String, - ) = mutableMethod.apply { + ) = method.apply { val endIndex = patternMatch!!.endIndex val insertIndex = endIndex + insertIndexOffset @@ -410,21 +398,21 @@ val hideLayoutComponentsPatch = bytecodePatch( addInstructions(insertIndex, instructions(register)) } - filterBarHeightMatch.patch { register -> + filterBarHeightFingerprint.patch { register -> """ invoke-static { v$register }, $LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR->hideInFeed(I)I move-result v$register """ } - searchResultsChipBarMatch.patch(-1, -2) { register -> + searchResultsChipBarFingerprint.patch(-1, -2) { register -> """ invoke-static { v$register }, $LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR->hideInSearch(I)I move-result v$register """ } - relatedChipCloudMatch.patch(1) { register -> + relatedChipCloudFingerprint.patch(1) { register -> "invoke-static { v$register }, " + "$LAYOUT_COMPONENTS_FILTER_CLASS_DESCRIPTOR->hideInRelatedVideos(Landroid/view/View;)V" } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/infocards/HideInfoCardsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/infocards/HideInfoCardsPatch.kt index e59119974..29eb8de6b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/infocards/HideInfoCardsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/infocards/HideInfoCardsPatch.kt @@ -17,7 +17,6 @@ import app.revanced.patches.youtube.misc.litho.filter.addLithoFilter import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch -import app.revanced.util.applyMatch import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction @@ -67,11 +66,8 @@ val hideInfoCardsPatch = bytecodePatch( ), ) - val infocardsIncognitoParentMatch by infocardsIncognitoParentFingerprint() - val infocardsMethodCallMatch by infocardsMethodCallFingerprint() - - execute { context -> - infocardsIncognitoFingerprint.applyMatch(context, infocardsIncognitoParentMatch).mutableMethod.apply { + execute { + infocardsIncognitoFingerprint.match(infocardsIncognitoParentFingerprint.originalClassDef).method.apply { val invokeInstructionIndex = implementation!!.instructions.indexOfFirst { it.opcode.ordinal == Opcode.INVOKE_VIRTUAL.ordinal && ((it as ReferenceInstruction).reference.toString() == "Landroid/view/View;->setVisibility(I)V") @@ -84,10 +80,10 @@ val hideInfoCardsPatch = bytecodePatch( ) } - val hideInfoCardsCallMethod = infocardsMethodCallMatch.mutableMethod + val hideInfoCardsCallMethod = infocardsMethodCallFingerprint.method - val invokeInterfaceIndex = infocardsMethodCallMatch.patternMatch!!.endIndex - val toggleRegister = infocardsMethodCallMatch.mutableMethod.implementation!!.registerCount - 1 + val invokeInterfaceIndex = infocardsMethodCallFingerprint.patternMatch!!.endIndex + val toggleRegister = infocardsMethodCallFingerprint.method.implementation!!.registerCount - 1 hideInfoCardsCallMethod.addInstructionsWithLabels( invokeInterfaceIndex, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/rollingnumber/DisableRollingNumberAnimationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/rollingnumber/DisableRollingNumberAnimationPatch.kt index dbd1c8549..bf1aba4fd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/rollingnumber/DisableRollingNumberAnimationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/rollingnumber/DisableRollingNumberAnimationPatch.kt @@ -39,8 +39,6 @@ val disableRollingNumberAnimationPatch = bytecodePatch( ), ) - val rollingNumberTextViewAnimationUpdateMatch by rollingNumberTextViewAnimationUpdateFingerprint() - execute { addResources("youtube", "layout.hide.rollingnumber.disableRollingNumberAnimationPatch") @@ -50,10 +48,11 @@ val disableRollingNumberAnimationPatch = bytecodePatch( // Animations are disabled by preventing an Image from being applied to the text span, // which prevents the animations from appearing. - val patternMatch = rollingNumberTextViewAnimationUpdateMatch.patternMatch!! + + val patternMatch = rollingNumberTextViewAnimationUpdateFingerprint.patternMatch!! val blockStartIndex = patternMatch.startIndex val blockEndIndex = patternMatch.endIndex + 1 - rollingNumberTextViewAnimationUpdateMatch.mutableMethod.apply { + rollingNumberTextViewAnimationUpdateFingerprint.method.apply { val freeRegister = getInstruction(blockStartIndex).registerA // ReturnYouTubeDislike also makes changes to this same method, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt index 565c80439..34c231020 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/seekbar/HideSeekbarPatch.kt @@ -11,7 +11,6 @@ import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.seekbarFingerprint import app.revanced.patches.youtube.shared.seekbarOnDrawFingerprint -import app.revanced.util.applyMatch @Suppress("unused") val hideSeekbarPatch = bytecodePatch( @@ -36,9 +35,7 @@ val hideSeekbarPatch = bytecodePatch( ), ) - val seekbarMatch by seekbarFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.hide.seekbar.hideSeekbarPatch") PreferenceScreen.SEEKBAR.addPreferences( @@ -46,7 +43,7 @@ val hideSeekbarPatch = bytecodePatch( SwitchPreference("revanced_hide_seekbar_thumbnail"), ) - seekbarOnDrawFingerprint.applyMatch(context, seekbarMatch).mutableMethod.addInstructionsWithLabels( + seekbarOnDrawFingerprint.match(seekbarFingerprint.originalClassDef).method.addInstructionsWithLabels( 0, """ const/4 v0, 0x0 diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt index 689c70f43..816e65d3b 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/HideShortsComponentsPatch.kt @@ -29,6 +29,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction internal var reelMultipleItemShelfId = -1L private set @@ -61,7 +62,7 @@ private val hideShortsComponentsResourcePatch = resourcePatch { versionCheckPatch, ) - execute { context -> + execute { val hideShortsAppShortcut by hideShortsAppShortcutOption val hideShortsWidget by hideShortsWidgetOption @@ -118,7 +119,7 @@ private val hideShortsComponentsResourcePatch = resourcePatch { ) // Verify the file has the expected node, even if the patch option is off. - context.document["res/xml/main_shortcuts.xml"].use { document -> + document("res/xml/main_shortcuts.xml").use { document -> val shortsItem = document.childNodes.findElementByAttributeValueOrThrow( "android:shortcutId", "shorts-shortcut", @@ -129,7 +130,7 @@ private val hideShortsComponentsResourcePatch = resourcePatch { } } - context.document["res/layout/appwidget_two_rows.xml"].use { document -> + document("res/layout/appwidget_two_rows.xml").use { document -> val shortsItem = document.childNodes.findElementByAttributeValueOrThrow( "android:id", "@id/button_shorts_container", @@ -191,33 +192,21 @@ val hideShortsComponentsPatch = bytecodePatch( ), ) - hideShortsAppShortcutOption() - hideShortsWidgetOption() - - val createShortsButtonsMatch by createShortsButtonsFingerprint() - val shortsBottomBarContainerMatch by shortsBottomBarContainerFingerprint() - val legacyRenderBottomNavigationBarParentMatch by legacyRenderBottomNavigationBarParentFingerprint() - val renderBottomNavigationBarParentMatch by renderBottomNavigationBarParentFingerprint() - val setPivotBarVisibilityParentMatch by setPivotBarVisibilityParentFingerprint() - reelConstructorFingerprint() - - execute { context -> + execute { // region Hide the Shorts shelf. // This patch point is not present in 19.03.x and greater. - if (!is_19_03_or_greater) { - reelConstructorFingerprint.match?.let { - it.mutableMethod.apply { - val insertIndex = it.patternMatch!!.startIndex + 2 - val viewRegister = getInstruction(insertIndex).registerA + if (!is_19_03_or_greater && reelConstructorFingerprint.methodOrNull != null) { + reelConstructorFingerprint.method.apply { + val insertIndex = reelConstructorFingerprint.patternMatch!!.startIndex + 2 + val viewRegister = getInstruction(insertIndex).registerA - injectHideViewCall( - insertIndex, - viewRegister, - FILTER_CLASS_DESCRIPTOR, - "hideShortsShelf", - ) - } + injectHideViewCall( + insertIndex, + viewRegister, + FILTER_CLASS_DESCRIPTOR, + "hideShortsShelf", + ) } } @@ -226,7 +215,7 @@ val hideShortsComponentsPatch = bytecodePatch( // region Hide the Shorts buttons in older versions of YouTube. // Some Shorts buttons are views, hide them by setting their visibility to GONE. - ShortsButtons.entries.forEach { button -> button.injectHideCall(createShortsButtonsMatch.mutableMethod) } + ShortsButtons.entries.forEach { button -> button.injectHideCall(createShortsButtonsFingerprint.method) } // endregion @@ -234,7 +223,7 @@ val hideShortsComponentsPatch = bytecodePatch( addLithoFilter(FILTER_CLASS_DESCRIPTOR) - context.forEachLiteralValueInstruction( + forEachLiteralValueInstruction( reelPlayerRightPivotV2Size, ) { literalInstructionIndex -> val targetIndex = indexOfFirstInstructionOrThrow(literalInstructionIndex) { @@ -257,11 +246,10 @@ val hideShortsComponentsPatch = bytecodePatch( // region Hide the navigation bar. // Hook to get the pivotBar view. - setPivotBarVisibilityFingerprint.applyMatch( - context, - setPivotBarVisibilityParentMatch, + setPivotBarVisibilityFingerprint.match( + setPivotBarVisibilityParentFingerprint.originalClassDef, ).let { result -> - result.mutableMethod.apply { + result.method.apply { val insertIndex = result.patternMatch!!.endIndex val viewRegister = getInstruction(insertIndex - 1).registerA addInstruction( @@ -273,20 +261,19 @@ val hideShortsComponentsPatch = bytecodePatch( } // Hook to hide the shared navigation bar when the Shorts player is opened. - renderBottomNavigationBarFingerprint.applyMatch( - context, + renderBottomNavigationBarFingerprint.match( if (is_19_41_or_greater) { - renderBottomNavigationBarParentMatch + renderBottomNavigationBarParentFingerprint } else { - legacyRenderBottomNavigationBarParentMatch - }, - ).mutableMethod.addInstruction( + legacyRenderBottomNavigationBarParentFingerprint + }.originalClassDef, + ).method.addInstruction( 0, "invoke-static { p1 }, $FILTER_CLASS_DESCRIPTOR->hideNavigationBar(Ljava/lang/String;)V", ) // Hide the bottom bar container of the Shorts player. - shortsBottomBarContainerMatch.mutableMethod.apply { + shortsBottomBarContainerFingerprint.method.apply { val resourceIndex = indexOfFirstLiteralInstruction(bottomBarContainer) val targetIndex = indexOfFirstInstructionOrThrow(resourceIndex) { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/suggestedvideoendscreen/DisableSuggestedVideoEndScreenPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/suggestedvideoendscreen/DisableSuggestedVideoEndScreenPatch.kt index cf10a805f..17a83f98a 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/suggestedvideoendscreen/DisableSuggestedVideoEndScreenPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/suggestedvideoendscreen/DisableSuggestedVideoEndScreenPatch.kt @@ -63,11 +63,9 @@ val disableSuggestedVideoEndScreenPatch = bytecodePatch( ), ) - val createEndScreenViewMatch by createEndScreenViewFingerprint() - execute { - createEndScreenViewMatch.mutableMethod.apply { - val addOnClickEventListenerIndex = createEndScreenViewMatch.patternMatch!!.endIndex - 1 + createEndScreenViewFingerprint.method.apply { + val addOnClickEventListenerIndex = createEndScreenViewFingerprint.patternMatch!!.endIndex - 1 val viewRegister = getInstruction(addOnClickEventListenerIndex).registerC addInstruction( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/HideTimestampPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/HideTimestampPatch.kt index 313d39e47..acb5f9f19 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/HideTimestampPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/HideTimestampPatch.kt @@ -31,8 +31,6 @@ val hideTimestampPatch = bytecodePatch( ), ) - val timeCounterMatch by timeCounterFingerprint() - execute { addResources("youtube", "layout.hide.time.hideTimestampPatch") @@ -40,7 +38,7 @@ val hideTimestampPatch = bytecodePatch( SwitchPreference("revanced_hide_timestamp"), ) - timeCounterMatch.mutableMethod.addInstructionsWithLabels( + timeCounterFingerprint.method.addInstructionsWithLabels( 0, """ invoke-static { }, Lapp/revanced/extension/youtube/patches/HideTimestampPatch;->hideTimestamp()Z diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt index e7b03d8f2..cc2b9de91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/MiniplayerPatch.kt @@ -2,7 +2,7 @@ package app.revanced.patches.youtube.layout.miniplayer -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -173,15 +173,7 @@ val miniplayerPatch = bytecodePatch( ), ) - val miniplayerDimensionsCalculatorParentMatch by miniplayerDimensionsCalculatorParentFingerprint() - val miniplayerResponseModelSizeCheckMatch by miniplayerResponseModelSizeCheckFingerprint() - val miniplayerOverrideMatch by miniplayerOverrideFingerprint() - val miniplayerModernConstructorMatch by miniplayerModernConstructorFingerprint() - val miniplayerModernViewParentMatch by miniplayerModernViewParentFingerprint() - val miniplayerMinimumSizeMatch by miniplayerMinimumSizeFingerprint() - val playerOverlaysLayoutMatch by playerOverlaysLayoutFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.miniplayer.miniplayerPatch") val preferences = mutableSetOf() @@ -273,11 +265,11 @@ val miniplayerPatch = bytecodePatch( insertBooleanOverride(index, "getModernMiniplayerOverride") } - fun Match.insertLiteralValueBooleanOverride( + fun Fingerprint.insertLiteralValueBooleanOverride( literal: Long, extensionMethod: String, ) { - mutableMethod.apply { + method.apply { val literalIndex = indexOfFirstLiteralInstructionOrThrow(literal) val targetIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT) @@ -285,11 +277,11 @@ val miniplayerPatch = bytecodePatch( } } - fun Match.insertLiteralValueFloatOverride( + fun Fingerprint.insertLiteralValueFloatOverride( literal: Long, extensionMethod: String, ) { - mutableMethod.apply { + method.apply { val literalIndex = indexOfFirstLiteralInstructionOrThrow(literal) val targetIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.DOUBLE_TO_FLOAT) val register = getInstruction(targetIndex).registerA @@ -339,24 +331,22 @@ val miniplayerPatch = bytecodePatch( // region Enable tablet miniplayer. - miniplayerOverrideNoContextFingerprint.applyMatch( - context, - miniplayerDimensionsCalculatorParentMatch, - ).mutableMethod.apply { + miniplayerOverrideNoContextFingerprint.match( + miniplayerDimensionsCalculatorParentFingerprint.originalClassDef, + ).method.apply { findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) } } // endregion // region Legacy tablet miniplayer hooks. - - val appNameStringIndex = miniplayerOverrideMatch.stringMatches!!.first().index + 2 - context.navigate(miniplayerOverrideMatch.mutableMethod).at(appNameStringIndex).mutable().apply { + val appNameStringIndex = miniplayerOverrideFingerprint.stringMatches!!.first().index + 2 + navigate(miniplayerOverrideFingerprint.originalMethod).to(appNameStringIndex).stop().apply { findReturnIndicesReversed().forEach { index -> insertLegacyTabletMiniplayerOverride(index) } } - miniplayerResponseModelSizeCheckMatch.let { - it.mutableMethod.insertLegacyTabletMiniplayerOverride(it.patternMatch!!.endIndex) + miniplayerResponseModelSizeCheckFingerprint.let { + it.method.insertLegacyTabletMiniplayerOverride(it.patternMatch!!.endIndex) } if (!is_19_16_or_greater) { @@ -368,7 +358,7 @@ val miniplayerPatch = bytecodePatch( // region Enable modern miniplayer. - miniplayerModernConstructorMatch.mutableClass.methods.forEach { + miniplayerModernConstructorFingerprint.classDef.methods.forEach { it.apply { if (AccessFlags.CONSTRUCTOR.isSet(accessFlags)) { val iPutIndex = indexOfFirstInstructionOrThrow { @@ -383,38 +373,38 @@ val miniplayerPatch = bytecodePatch( } if (is_19_23_or_greater) { - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_DRAG_DROP_FEATURE_KEY, "enableMiniplayerDragAndDrop", ) } if (is_19_43_or_greater) { - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_HORIZONTAL_DRAG_FEATURE_KEY, "setHorizontalDrag", ) } if (is_19_25_or_greater) { - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_MODERN_FEATURE_LEGACY_KEY, "getModernMiniplayerOverride", ) - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_MODERN_FEATURE_KEY, "getModernFeatureFlagsActiveOverride", ) - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_DOUBLE_TAP_FEATURE_KEY, "enableMiniplayerDoubleTapAction", ) } if (is_19_26_or_greater) { - miniplayerModernConstructorMatch.mutableMethod.apply { + miniplayerModernConstructorFingerprint.method.apply { val literalIndex = indexOfFirstLiteralInstructionOrThrow( MINIPLAYER_INITIAL_SIZE_FEATURE_KEY, ) @@ -432,7 +422,7 @@ val miniplayerPatch = bytecodePatch( } // Override a minimum size constant. - miniplayerMinimumSizeMatch.mutableMethod.apply { + miniplayerMinimumSizeFingerprint.method.apply { val index = indexOfFirstInstructionOrThrow { opcode == Opcode.CONST_16 && (this as NarrowLiteralInstruction).narrowLiteral == 192 } @@ -446,7 +436,7 @@ val miniplayerPatch = bytecodePatch( } if (is_19_36_or_greater) { - miniplayerModernConstructorMatch.insertLiteralValueBooleanOverride( + miniplayerModernConstructorFingerprint.insertLiteralValueBooleanOverride( MINIPLAYER_ROUNDED_CORNERS_FEATURE_KEY, "setRoundedCorners", ) @@ -458,10 +448,9 @@ val miniplayerPatch = bytecodePatch( // YT fixed this mistake in 19.17. // Fix this, by swapping the drawable resource values with each other. if (ytOutlinePictureInPictureWhite24 >= 0) { - miniplayerModernExpandCloseDrawablesFingerprint.applyMatch( - context, - miniplayerModernViewParentMatch, - ).mutableMethod.apply { + miniplayerModernExpandCloseDrawablesFingerprint.match( + miniplayerModernViewParentFingerprint.originalClassDef, + ).method.apply { listOf( ytOutlinePictureInPictureWhite24 to ytOutlineXWhite24, ytOutlineXWhite24 to ytOutlinePictureInPictureWhite24, @@ -505,20 +494,18 @@ val miniplayerPatch = bytecodePatch( "adjustMiniplayerOpacity", ), ).forEach { (fingerprint, literalValue, methodName) -> - fingerprint.applyMatch( - context, - miniplayerModernViewParentMatch, - ).mutableMethod.hookInflatedView( + fingerprint.match( + miniplayerModernViewParentFingerprint.classDef, + ).method.hookInflatedView( literalValue, "Landroid/widget/ImageView;", "$EXTENSION_CLASS_DESCRIPTOR->$methodName(Landroid/widget/ImageView;)V", ) } - miniplayerModernAddViewListenerFingerprint.applyMatch( - context, - miniplayerModernViewParentMatch, - ).mutableMethod.addInstruction( + miniplayerModernAddViewListenerFingerprint.match( + miniplayerModernViewParentFingerprint.classDef, + ).method.addInstruction( 0, "invoke-static { p1 }, $EXTENSION_CLASS_DESCRIPTOR->" + "hideMiniplayerSubTexts(Landroid/view/View;)V", @@ -531,7 +518,7 @@ val miniplayerPatch = bytecodePatch( // // NOTE: Modern 2 uses the same video UI as the regular player except resized to smaller. // This patch code could be used to hide other player overlays that do not use Litho. - playerOverlaysLayoutMatch.mutableClass.methods.add( + playerOverlaysLayoutFingerprint.classDef.methods.add( ImmutableMethod( YOUTUBE_PLAYER_OVERLAYS_LAYOUT_CLASS_NAME, "addView", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/panels/popup/PlayerPopupPanelsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/panels/popup/PlayerPopupPanelsPatch.kt index f9ff7e378..a245dc8a9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/panels/popup/PlayerPopupPanelsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/panels/popup/PlayerPopupPanelsPatch.kt @@ -31,8 +31,6 @@ val playerPopupPanelsPatch = bytecodePatch( ), ) - val engagementPanelControllerMatch by engagementPanelControllerFingerprint() - execute { addResources("youtube", "layout.panels.popup.playerPopupPanelsPatch") @@ -40,7 +38,7 @@ val playerPopupPanelsPatch = bytecodePatch( SwitchPreference("revanced_hide_player_popup_panels"), ) - engagementPanelControllerMatch.mutableMethod.addInstructionsWithLabels( + engagementPanelControllerFingerprint.method.addInstructionsWithLabels( 0, """ invoke-static { }, Lapp/revanced/extension/youtube/patches/DisablePlayerPopupPanelsPatch;->disablePlayerPopupPanels()Z diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/background/PlayerControlsBackgroundPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/background/PlayerControlsBackgroundPatch.kt index 15188223a..d039837f0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/background/PlayerControlsBackgroundPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/background/PlayerControlsBackgroundPatch.kt @@ -21,8 +21,8 @@ val playerControlsBackgroundPatch = resourcePatch( ), ) - execute { context -> - context.document["res/drawable/player_button_circle_background.xml"].use { document -> + execute { + document("res/drawable/player_button_circle_background.xml").use { document -> document.doRecursively node@{ node -> if (node !is Element) return@node diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/CustomPlayerOverlayOpacityPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/CustomPlayerOverlayOpacityPatch.kt index 0354f05cd..91d39cd1f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/CustomPlayerOverlayOpacityPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/CustomPlayerOverlayOpacityPatch.kt @@ -40,7 +40,8 @@ private val customPlayerOverlayOpacityResourcePatch = resourcePatch { } } -private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/CustomPlayerOverlayOpacityPatch;" +private const val EXTENSION_CLASS_DESCRIPTOR = + "Lapp/revanced/extension/youtube/patches/CustomPlayerOverlayOpacityPatch;" @Suppress("unused") val customPlayerOverlayOpacityPatch = bytecodePatch( @@ -57,13 +58,11 @@ val customPlayerOverlayOpacityPatch = bytecodePatch( "19.25.37", "19.34.42", "19.43.41", - ) + ), ) - val createPlayerOverviewMatch by createPlayerOverviewFingerprint() - execute { - createPlayerOverviewMatch.mutableMethod.apply { + createPlayerOverviewFingerprint.method.apply { val viewRegisterIndex = indexOfFirstLiteralInstructionOrThrow(scrimOverlayId) + 3 val viewRegister = diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt index e755afb51..51c8ccc24 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/returnyoutubedislike/ReturnYouTubeDislikePatch.kt @@ -1,6 +1,5 @@ package app.revanced.patches.youtube.layout.returnyoutubedislike -import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -32,6 +31,7 @@ import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference import com.android.tools.smali.dexlib2.iface.reference.MethodReference import com.android.tools.smali.dexlib2.iface.reference.TypeReference +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/ReturnYouTubeDislikePatch;" @@ -64,20 +64,7 @@ val returnYouTubeDislikePatch = bytecodePatch( ), ) - val conversionContextMatch by conversionContextFingerprint() - val textComponentConstructorMatch by textComponentConstructorFingerprint() - val textComponentDataMatch by textComponentDataFingerprint() - val shortsTextViewMatch by shortsTextViewFingerprint() - val likeMatch by likeFingerprint() - val dislikeMatch by dislikeFingerprint() - val removeLikeMatch by removeLikeFingerprint() - val rollingNumberSetterMatch by rollingNumberSetterFingerprint() - val rollingNumberMeasureStaticLabelParentMatch by rollingNumberMeasureStaticLabelParentFingerprint() - val rollingNumberMeasureAnimatedTextMatch by rollingNumberMeasureAnimatedTextFingerprint() - val rollingNumberTextViewMatch by rollingNumberTextViewFingerprint() - val rollingNumberTextViewAnimationUpdateMatch by rollingNumberTextViewAnimationUpdateFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.returnyoutubedislike.returnYouTubeDislikePatch") addSettingPreference( @@ -100,14 +87,12 @@ val returnYouTubeDislikePatch = bytecodePatch( // region Hook like/dislike/remove like button clicks to send votes to the API. - data class VotePatch(val fingerprint: Match, val voteKind: Vote) - - listOf( - VotePatch(likeMatch, Vote.LIKE), - VotePatch(dislikeMatch, Vote.DISLIKE), - VotePatch(removeLikeMatch, Vote.REMOVE_LIKE), - ).forEach { (match, vote) -> - match.mutableMethod.addInstructions( + mapOf( + likeFingerprint to Vote.LIKE, + dislikeFingerprint to Vote.DISLIKE, + removeLikeFingerprint to Vote.REMOVE_LIKE, + ).forEach { (fingerprint, vote) -> + fingerprint.method.addInstructions( 0, """ const/4 v0, ${vote.value} @@ -125,14 +110,14 @@ val returnYouTubeDislikePatch = bytecodePatch( // And it works in all situations excepxt did not change. // This hook handles all situations, as it's where the created Spans are stored and later reused. // Find the field name of the conversion context. - val conversionContextField = textComponentConstructorMatch.classDef.fields.find { - it.type == conversionContextMatch.classDef.type + val conversionContextField = textComponentConstructorFingerprint.originalClassDef.fields.find { + it.type == conversionContextFingerprint.originalClassDef.type } ?: throw PatchException("Could not find conversion context field") - textComponentLookupFingerprint.applyMatch(context, textComponentConstructorMatch) - textComponentLookupFingerprint.matchOrThrow.mutableMethod.apply { + textComponentLookupFingerprint.match(textComponentConstructorFingerprint.originalClassDef) + textComponentLookupFingerprint.method.apply { // Find the instruction for creating the text data object. - val textDataClassType = textComponentDataMatch.classDef.type + val textDataClassType = textComponentDataFingerprint.originalClassDef.type val insertIndex: Int val tempRegister: Int @@ -185,9 +170,8 @@ val returnYouTubeDislikePatch = bytecodePatch( // endregion // region Hook for non-litho Short videos. - - shortsTextViewMatch.mutableMethod.apply { - val insertIndex = shortsTextViewMatch.patternMatch!!.endIndex + 1 + shortsTextViewFingerprint.method.apply { + val insertIndex = shortsTextViewFingerprint.patternMatch!!.endIndex + 1 // If the field is true, the TextView is for a dislike button. val isDisLikesBooleanInstruction = instructions.first { instruction -> @@ -244,10 +228,9 @@ val returnYouTubeDislikePatch = bytecodePatch( // Do this last to allow patching old unsupported versions (if the user really wants), // On older unsupported version this will fail to match and throw an exception, // but everything will still work correctly anyway. + val dislikesIndex = rollingNumberSetterFingerprint.patternMatch!!.endIndex - val dislikesIndex = rollingNumberSetterMatch.patternMatch!!.endIndex - - rollingNumberSetterMatch.mutableMethod.apply { + rollingNumberSetterFingerprint.method.apply { val insertIndex = 1 val charSequenceInstanceRegister = @@ -274,11 +257,11 @@ val returnYouTubeDislikePatch = bytecodePatch( // Rolling Number text views use the measured width of the raw string for layout. // Modify the measure text calculation to include the left drawable separator if needed. - val patternMatch = rollingNumberMeasureAnimatedTextMatch.patternMatch!! + val patternMatch = rollingNumberMeasureAnimatedTextFingerprint.patternMatch!! // Additional check to verify the opcodes are at the start of the method if (patternMatch.startIndex != 0) throw PatchException("Unexpected opcode location") val endIndex = patternMatch.endIndex - rollingNumberMeasureAnimatedTextMatch.mutableMethod.apply { + rollingNumberMeasureAnimatedTextFingerprint.method.apply { val measuredTextWidthRegister = getInstruction(endIndex).registerA addInstructions( @@ -292,12 +275,11 @@ val returnYouTubeDislikePatch = bytecodePatch( // Additional text measurement method. Used if YouTube decides not to animate the likes count // and sometimes used for initial video load. - rollingNumberMeasureStaticLabelFingerprint.applyMatch( - context, - rollingNumberMeasureStaticLabelParentMatch, + rollingNumberMeasureStaticLabelFingerprint.match( + rollingNumberMeasureStaticLabelParentFingerprint.originalClassDef, ).let { val measureTextIndex = it.patternMatch!!.startIndex + 1 - it.mutableMethod.apply { + it.method.apply { val freeRegister = getInstruction(0).registerA addInstructions( @@ -312,13 +294,13 @@ val returnYouTubeDislikePatch = bytecodePatch( // The rolling number Span is missing styling since it's initially set as a String. // Modify the UI text view and use the styled like/dislike Span. // Initial TextView is set in this method. - val initiallyCreatedTextViewMethod = rollingNumberTextViewMatch.mutableMethod + val initiallyCreatedTextViewMethod = rollingNumberTextViewFingerprint.method // Videos less than 24 hours after uploaded, like counts will be updated in real time. // Whenever like counts are updated, TextView is set in this method. arrayOf( initiallyCreatedTextViewMethod, - rollingNumberTextViewAnimationUpdateMatch.mutableMethod, + rollingNumberTextViewAnimationUpdateFingerprint.method, ).forEach { insertMethod -> insertMethod.apply { val setTextIndex = indexOfFirstInstructionOrThrow { diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/WideSearchbarPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/WideSearchbarPatch.kt index 07dcd64d5..233d611cf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/WideSearchbarPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/WideSearchbarPatch.kt @@ -1,6 +1,6 @@ package app.revanced.patches.youtube.layout.searchbar -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.patch.BytecodePatchContext @@ -39,10 +39,7 @@ val wideSearchbarPatch = bytecodePatch( ), ) - val setWordmarkHeaderMatch by setWordmarkHeaderFingerprint() - val createSearchSuggestionsMatch by createSearchSuggestionsFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.searchbar.wideSearchbarPatch") PreferenceScreen.FEED.addPreferences( @@ -53,11 +50,11 @@ val wideSearchbarPatch = bytecodePatch( * Navigate a fingerprints method at a given index mutably. * * @param index The index to navigate to. - * @param fromMatch The fingerprint match to navigate the method on. + * @param from The fingerprint to navigate the method on. * @return The [MutableMethod] which was navigated on. */ - fun BytecodePatchContext.walkMutable(index: Int, fromMatch: Match) = - navigate(fromMatch.method).at(index).mutable() + fun BytecodePatchContext.walkMutable(index: Int, from: Fingerprint) = + navigate(from.originalMethod).to(index).stop() /** * Injects instructions required for certain methods. @@ -76,10 +73,10 @@ val wideSearchbarPatch = bytecodePatch( } mapOf( - setWordmarkHeaderMatch to 1, - createSearchSuggestionsMatch to createSearchSuggestionsMatch.patternMatch!!.startIndex, + setWordmarkHeaderFingerprint to 1, + createSearchSuggestionsFingerprint to createSearchSuggestionsFingerprint.patternMatch!!.startIndex, ).forEach { (fingerprint, callIndex) -> - context.walkMutable(callIndex, fingerprint).injectSearchBarHook() + walkMutable(callIndex, fingerprint).injectSearchBarHook() } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/music/premium/backgroundplay/BackgroundPlayPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt similarity index 100% rename from patches/src/main/kotlin/app/revanced/patches/music/premium/backgroundplay/BackgroundPlayPatch.kt rename to patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/RestoreOldSeekbarThumbnailsPatch.kt diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt index 7dff7e79e..49a5444ab 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/SeekbarColorPatch.kt @@ -37,7 +37,7 @@ private val seekbarColorResourcePatch = resourcePatch { versionCheckPatch, ) - execute { context -> + execute { reelTimeBarPlayedColorId = resourceMappings[ "color", "reel_time_bar_played_color", @@ -52,7 +52,7 @@ private val seekbarColorResourcePatch = resourcePatch { ] // Edit the resume playback drawable and replace the progress bar with a custom drawable - context.document["res/drawable/resume_playback_progressbar_drawable.xml"].use { document -> + document("res/drawable/resume_playback_progressbar_drawable.xml").use { document -> val layerList = document.getElementsByTagName("layer-list").item(0) as Element val progressNode = layerList.getElementsByTagName("item").item(1) as Element @@ -80,13 +80,7 @@ val seekbarColorPatch = bytecodePatch( seekbarColorResourcePatch, ) - val playerSeekbarColorMatch by playerSeekbarColorFingerprint() - val shortsSeekbarColorMatch by shortsSeekbarColorFingerprint() - val setSeekbarClickedColorMatch by setSeekbarClickedColorFingerprint() - val playerSeekbarGradientConfigMatch by playerSeekbarGradientConfigFingerprint() - val lithoLinearGradientMatch by lithoLinearGradientFingerprint() - - execute { context -> + execute { fun MutableMethod.addColorChangeInstructions(resourceId: Long) { val registerIndex = indexOfFirstLiteralInstructionOrThrow(resourceId) + 2 val colorRegister = getInstruction(registerIndex).registerA @@ -99,20 +93,19 @@ val seekbarColorPatch = bytecodePatch( ) } - playerSeekbarColorMatch.mutableMethod.apply { + playerSeekbarColorFingerprint.method.apply { addColorChangeInstructions(inlineTimeBarColorizedBarPlayedColorDarkId) addColorChangeInstructions(inlineTimeBarPlayedNotHighlightedColorId) } - shortsSeekbarColorMatch.mutableMethod.apply { + shortsSeekbarColorFingerprint.method.apply { addColorChangeInstructions(reelTimeBarPlayedColorId) } - setSeekbarClickedColorMatch.mutableMethod.let { - val setColorMethodIndex = setSeekbarClickedColorMatch.patternMatch!!.startIndex + 1 - val method = context.navigate(it).at(setColorMethodIndex).mutable() + setSeekbarClickedColorFingerprint.originalMethod.let { + val setColorMethodIndex = setSeekbarClickedColorFingerprint.patternMatch!!.startIndex + 1 - method.apply { + navigate(it).to(setColorMethodIndex).stop().apply { val colorRegister = getInstruction(0).registerA addInstructions( 0, @@ -125,7 +118,7 @@ val seekbarColorPatch = bytecodePatch( } if (is_19_23_or_greater) { - playerSeekbarGradientConfigMatch.mutableMethod.apply { + playerSeekbarGradientConfigFingerprint.method.apply { val literalIndex = indexOfFirstLiteralInstructionOrThrow(PLAYER_SEEKBAR_GRADIENT_FEATURE_FLAG) val resultIndex = indexOfFirstInstructionOrThrow(literalIndex, Opcode.MOVE_RESULT) val register = getInstruction(resultIndex).registerA @@ -139,7 +132,7 @@ val seekbarColorPatch = bytecodePatch( ) } - lithoLinearGradientMatch.mutableMethod.addInstruction( + lithoLinearGradientFingerprint.method.addInstruction( 0, "invoke-static/range { p4 .. p5 }, $EXTENSION_CLASS_DESCRIPTOR->setLinearGradient([I[F)V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt index ed2556013..04088be7e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/ShortsAutoplayPatch.kt @@ -41,10 +41,6 @@ val shortsAutoplayPatch = bytecodePatch( ), ) - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - val reelEnumConstructorMatch by reelEnumConstructorFingerprint() - val reelPlaybackRepeatMatch by reelPlaybackRepeatFingerprint() - execute { addResources("youtube", "layout.shortsautoplay.shortsAutoplayPatch") @@ -59,16 +55,16 @@ val shortsAutoplayPatch = bytecodePatch( } // Main activity is used to check if app is in pip mode. - mainActivityOnCreateMatch.mutableMethod.addInstructions( + mainActivityOnCreateFingerprint.method.addInstructions( 0, "invoke-static/range { p0 .. p0 }, $EXTENSION_CLASS_DESCRIPTOR->" + "setMainActivity(Landroid/app/Activity;)V", ) - val reelEnumClass = reelEnumConstructorMatch.classDef.type + val reelEnumClass = reelEnumConstructorFingerprint.originalClassDef.type - reelEnumConstructorMatch.mutableMethod.apply { - val insertIndex = reelEnumConstructorMatch.patternMatch!!.startIndex + reelEnumConstructorFingerprint.method.apply { + val insertIndex = reelEnumConstructorFingerprint.patternMatch!!.startIndex addInstructions( insertIndex, @@ -81,7 +77,7 @@ val shortsAutoplayPatch = bytecodePatch( ) } - reelPlaybackRepeatMatch.mutableMethod.apply { + reelPlaybackRepeatFingerprint.method.apply { // The behavior enums are looked up from an ordinal value to an enum type. findInstructionIndicesReversedOrThrow { val reference = getReference() diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt index e2da6c960..18c440d4e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/SponsorBlockPatch.kt @@ -15,7 +15,6 @@ import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.shared.misc.settings.preference.IntentPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playercontrols.* -import app.revanced.patches.youtube.misc.playercontrols.addTopControl import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch import app.revanced.patches.youtube.misc.settings.addSettingPreference import app.revanced.patches.youtube.misc.settings.newIntent @@ -41,7 +40,7 @@ private val sponsorBlockResourcePatch = resourcePatch { playerControlsPatch, ) - execute { context -> + execute { addResources("youtube", "layout.sponsorblock.sponsorBlockResourcePatch") addSettingPreference( @@ -78,7 +77,7 @@ private val sponsorBlockResourcePatch = resourcePatch { "quantum_ic_skip_next_white_24.png", ), ).forEach { resourceGroup -> - context.copyResources("sponsorblock", resourceGroup) + copyResources("sponsorblock", resourceGroup) } addTopControl("sponsorblock") @@ -121,12 +120,7 @@ val sponsorBlockPatch = bytecodePatch( ), ) - val seekbarMatch by seekbarFingerprint() - val appendTimeMatch by appendTimeFingerprint() - val layoutConstructorMatch by layoutConstructorFingerprint() - val autoRepeatParentMatch by autoRepeatParentFingerprint() - - execute { context -> + execute { // Hook the video time methods. videoTimeHook( EXTENSION_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR, @@ -139,7 +133,7 @@ val sponsorBlockPatch = bytecodePatch( ) // Seekbar drawing - seekbarOnDrawFingerprint.applyMatch(context, seekbarMatch).mutableMethod.apply { + seekbarOnDrawFingerprint.match(seekbarFingerprint.originalClassDef).method.apply { // Get left and right of seekbar rectangle. val moveRectangleToRegisterIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_OBJECT_FROM16) @@ -184,8 +178,8 @@ val sponsorBlockPatch = bytecodePatch( injectVisibilityCheckCall(EXTENSION_VOTING_BUTTON_CONTROLLER_CLASS_DESCRIPTOR) // Append the new time to the player layout. - val appendTimePatternScanStartIndex = appendTimeMatch.patternMatch!!.startIndex - appendTimeMatch.mutableMethod.apply { + val appendTimePatternScanStartIndex = appendTimeFingerprint.patternMatch!!.startIndex + appendTimeFingerprint.method.apply { val register = getInstruction(appendTimePatternScanStartIndex + 1).registerA addInstructions( @@ -201,9 +195,9 @@ val sponsorBlockPatch = bytecodePatch( onCreateHook(EXTENSION_SEGMENT_PLAYBACK_CONTROLLER_CLASS_DESCRIPTOR, "initialize") // Initialize the SponsorBlock view. - controlsOverlayFingerprint.applyMatch(context, layoutConstructorMatch).let { + controlsOverlayFingerprint.match(layoutConstructorFingerprint.originalClassDef).let { val startIndex = it.patternMatch!!.startIndex - it.mutableMethod.apply { + it.method.apply { val frameLayoutRegister = (getInstruction(startIndex + 2) as OneRegisterInstruction).registerA addInstruction( startIndex + 3, @@ -213,13 +207,12 @@ val sponsorBlockPatch = bytecodePatch( } // Set seekbar draw rectangle. - rectangleFieldInvalidatorFingerprint.applyMatch(context, seekbarOnDrawFingerprint.match!!).mutableMethod.apply { + rectangleFieldInvalidatorFingerprint.match(seekbarOnDrawFingerprint.originalClassDef).method.apply { val fieldIndex = instructions.count() - 3 val fieldReference = getInstruction(fieldIndex).reference as FieldReference // replace the "replaceMeWith*" strings - context - .proxy(context.classes.first { it.type.endsWith("SegmentPlaybackController;") }) + proxy(classes.first { it.type.endsWith("SegmentPlaybackController;") }) .mutableClass .methods .find { it.name == "setSponsorBarRect" } @@ -248,7 +241,7 @@ val sponsorBlockPatch = bytecodePatch( // The vote and create segment buttons automatically change their visibility when appropriate, // but if buttons are showing when the end of the video is reached then they will not automatically hide. // Add a hook to forcefully hide when the end of the video is reached. - autoRepeatFingerprint.applyMatch(context, autoRepeatParentMatch).mutableMethod.addInstruction( + autoRepeatFingerprint.match(autoRepeatParentFingerprint.originalClassDef).method.addInstruction( 0, "invoke-static {}, $EXTENSION_SPONSORBLOCK_VIEW_CONTROLLER_CLASS_DESCRIPTOR->endOfVideoReached()V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/SpoofAppVersionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/SpoofAppVersionPatch.kt index 4560905f6..60f84dd72 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/SpoofAppVersionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/SpoofAppVersionPatch.kt @@ -38,8 +38,6 @@ val spoofAppVersionPatch = bytecodePatch( ), ) - val spoofAppVersionMatch by spoofAppVersionFingerprint() - execute { addResources("youtube", "layout.spoofappversion.spoofAppVersionPatch") @@ -51,11 +49,11 @@ val spoofAppVersionPatch = bytecodePatch( ), ) - val insertIndex = spoofAppVersionMatch.patternMatch!!.startIndex + 1 + val insertIndex = spoofAppVersionFingerprint.patternMatch!!.startIndex + 1 val buildOverrideNameRegister = - spoofAppVersionMatch.mutableMethod.getInstruction(insertIndex - 1).registerA + spoofAppVersionFingerprint.method.getInstruction(insertIndex - 1).registerA - spoofAppVersionMatch.mutableMethod.addInstructions( + spoofAppVersionFingerprint.method.addInstructions( insertIndex, """ invoke-static {v$buildOverrideNameRegister}, $EXTENSION_CLASS_DESCRIPTOR->getYouTubeVersionOverride(Ljava/lang/String;)Ljava/lang/String; diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt index 3e4c2e0f7..26c2633ae 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startpage/ChangeStartPagePatch.kt @@ -39,10 +39,7 @@ val changeStartPagePatch = bytecodePatch( ), ) - val browseIdMatch by browseIdFingerprint() - val intentActionMatch by intentActionFingerprint() - - execute { _ -> + execute { addResources("youtube", "layout.startpage.changeStartPagePatch") PreferenceScreen.GENERAL_LAYOUT.addPreferences( @@ -53,7 +50,7 @@ val changeStartPagePatch = bytecodePatch( ) // Hook browseId. - browseIdMatch.mutableMethod.apply { + browseIdFingerprint.method.apply { val browseIdIndex = indexOfFirstInstructionOrThrow { getReference()?.string == "FEwhat_to_watch" } @@ -70,7 +67,7 @@ val changeStartPagePatch = bytecodePatch( // There is no browserId assigned to Shorts and Search. // Just hook the Intent action. - intentActionMatch.mutableMethod.addInstruction( + intentActionFingerprint.method.addInstruction( 0, "invoke-static { p1 }, $EXTENSION_CLASS_DESCRIPTOR->overrideIntentAction(Landroid/content/Intent;)V", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt index 2bdfaff20..2f48ee67e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/DisableResumingShortsOnStartupPatch.kt @@ -41,28 +41,25 @@ val disableResumingShortsOnStartupPatch = bytecodePatch( ), ) - val userWasInShortsConfigMatch by userWasInShortsConfigFingerprint() - val userWasInShortsMatch by userWasInShortsFingerprint() - - execute { context -> + execute { addResources("youtube", "layout.startupshortsreset.disableResumingShortsOnStartupPatch") PreferenceScreen.SHORTS.addPreferences( SwitchPreference("revanced_disable_resuming_shorts_player"), ) - userWasInShortsConfigMatch.mutableMethod.apply { + userWasInShortsConfigFingerprint.originalMethod.apply { val startIndex = indexOfOptionalInstruction(this) val walkerIndex = indexOfFirstInstructionOrThrow(startIndex) { val reference = getReference() opcode == Opcode.INVOKE_VIRTUAL && reference?.returnType == "Z" && reference.definingClass != "Lj${'$'}/util/Optional;" && - reference.parameterTypes.isEmpty() + reference.parameterTypes.isEmpty() } // Presumably a method that processes the ProtoDataStore value (boolean) for the 'user_was_in_shorts' key. - context.navigate(this).at(walkerIndex).mutable().addInstructionsWithLabels( + navigate(this).to(walkerIndex).stop().addInstructionsWithLabels( 0, """ invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->disableResumingStartupShortsPlayer()Z @@ -76,7 +73,7 @@ val disableResumingShortsOnStartupPatch = bytecodePatch( ) } - userWasInShortsMatch.mutableMethod.apply { + userWasInShortsFingerprint.method.apply { val listenableInstructionIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_INTERFACE && getReference()?.definingClass == "Lcom/google/common/util/concurrent/ListenableFuture;" && diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/tablet/EnableTabletLayoutPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/tablet/EnableTabletLayoutPatch.kt index 5a96d78c5..181f5b920 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/tablet/EnableTabletLayoutPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/tablet/EnableTabletLayoutPatch.kt @@ -36,8 +36,6 @@ val enableTabletLayoutPatch = bytecodePatch( ), ) - val getFormFactorMatch by getFormFactorFingerprint() - execute { addResources("youtube", "layout.tablet.enableTabletLayoutPatch") @@ -45,7 +43,7 @@ val enableTabletLayoutPatch = bytecodePatch( SwitchPreference("revanced_tablet_layout"), ) - getFormFactorMatch.mutableMethod.apply { + getFormFactorFingerprint.method.apply { val returnIsLargeFormFactorIndex = instructions.lastIndex - 4 val returnIsLargeFormFactorLabel = getInstruction(returnIsLargeFormFactorIndex) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/LithoColorHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/LithoColorHookPatch.kt index 5fa87d900..fdab6c4b8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/LithoColorHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/LithoColorHookPatch.kt @@ -9,13 +9,13 @@ lateinit var lithoColorOverrideHook: (targetMethodClass: String, targetMethodNam val lithoColorHookPatch = bytecodePatch( description = "Adds a hook to set color of Litho components.", ) { - val lithoThemeMatch by lithoThemeFingerprint() execute { - var insertionIndex = lithoThemeMatch.patternMatch!!.endIndex - 1 + + var insertionIndex = lithoThemeFingerprint.patternMatch!!.endIndex - 1 lithoColorOverrideHook = { targetMethodClass, targetMethodName -> - lithoThemeMatch.mutableMethod.addInstructions( + lithoThemeFingerprint.method.addInstructions( insertionIndex, """ invoke-static { p1 }, $targetMethodClass->$targetMethodName(I)I diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt index 04fcfdcc5..7becb91d1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/theme/ThemePatch.kt @@ -81,7 +81,7 @@ val themePatch = bytecodePatch( addResourcesPatch, ) - execute { context -> + execute { addResources("youtube", "layout.theme.themeResourcePatch") PreferenceScreen.SEEKBAR.addPreferences( @@ -90,7 +90,7 @@ val themePatch = bytecodePatch( ) // Edit theme colors via resources. - context.document["res/values/colors.xml"].use { document -> + document("res/values/colors.xml").use { document -> val resourcesNode = document.getElementsByTagName("resources").item(0) as Element @@ -118,7 +118,7 @@ val themePatch = bytecodePatch( colorName: String, colorValue: String, ) { - context.document[resourceFile].use { document -> + document(resourceFile).use { document -> val resourcesNode = document.getElementsByTagName("resources").item(0) as Element @@ -153,7 +153,7 @@ val themePatch = bytecodePatch( ) splashScreenResourceFiles.forEach editSplashScreen@{ resourceFile -> - context.document[resourceFile].use { document -> + document(resourceFile).use { document -> document.getElementsByTagName("layer-list").item(0).forEachChildElement { node -> if (node.hasAttribute("android:drawable")) { node.setAttribute("android:drawable", "@color/$splashBackgroundColor") @@ -169,7 +169,7 @@ val themePatch = bytecodePatch( // In earlier versions of the app this is white and makes no sense for dark mode. // This is only required for 19.32 and greater, but is applied to all targets. // Only dark mode needs this fix as light mode correctly uses the custom color. - context.document["res/values-night/styles.xml"].use { document -> + document("res/values-night/styles.xml").use { document -> // Create a night mode specific override for the splash screen background. val style = document.createElement("style") style.setAttribute("name", "Theme.YouTube.Home") @@ -202,10 +202,6 @@ val themePatch = bytecodePatch( ), ) - val useGradientLoadingScreenMatch by useGradientLoadingScreenFingerprint() - val themeHelperLightColorMatch by themeHelperLightColorFingerprint() - val themeHelperDarkColorMatch by themeHelperDarkColorFingerprint() - execute { addResources("youtube", "layout.theme.themePatch") @@ -213,7 +209,7 @@ val themePatch = bytecodePatch( SwitchPreference("revanced_gradient_loading_screen"), ) - useGradientLoadingScreenMatch.mutableMethod.apply { + useGradientLoadingScreenFingerprint.method.apply { val isEnabledIndex = indexOfFirstLiteralInstructionOrThrow(GRADIENT_LOADING_SCREEN_AB_CONSTANT) + 3 val isEnabledRegister = getInstruction(isEnabledIndex - 1).registerA @@ -227,10 +223,10 @@ val themePatch = bytecodePatch( ) } mapOf( - themeHelperLightColorMatch to lightThemeBackgroundColor, - themeHelperDarkColorMatch to darkThemeBackgroundColor, - ).forEach { (match, color) -> - match.mutableMethod.apply { + themeHelperLightColorFingerprint to lightThemeBackgroundColor, + themeHelperDarkColorFingerprint to darkThemeBackgroundColor, + ).forEach { (fingerprint, color) -> + fingerprint.method.apply { addInstructions( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/announcements/AnnouncementsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/announcements/AnnouncementsPatch.kt index 1fc3d7726..5afa220b0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/announcements/AnnouncementsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/announcements/AnnouncementsPatch.kt @@ -30,11 +30,9 @@ val announcementsPatch = bytecodePatch( "19.25.37", "19.34.42", "19.43.41", - ) + ), ) - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - execute { addResources("youtube", "misc.announcements.announcementsPatch") @@ -42,7 +40,7 @@ val announcementsPatch = bytecodePatch( SwitchPreference("revanced_announcements"), ) - mainActivityOnCreateMatch.mutableMethod.addInstructions( + mainActivityOnCreateFingerprint.method.addInstructions( // Insert index must be greater than the insert index used by GmsCoreSupport, // as both patch the same method and GmsCore check should be first. 1, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch.kt index b7d359721..e2c24ed5c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/autorepeat/AutoRepeatPatch.kt @@ -11,7 +11,7 @@ import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.shared.autoRepeatFingerprint import app.revanced.patches.youtube.shared.autoRepeatParentFingerprint -import app.revanced.util.matchOrThrow +import org.stringtemplate.v4.compiler.Bytecode.instructions // TODO: Rename this patch to AlwaysRepeatPatch (as well as strings and references in the extension). @Suppress("unused") @@ -35,19 +35,15 @@ val autoRepeatPatch = bytecodePatch( ), ) - val autoRepeatParentMatch by autoRepeatParentFingerprint() - - execute { context -> + execute { addResources("youtube", "misc.autorepeat.autoRepeatPatch") PreferenceScreen.MISC.addPreferences( SwitchPreference("revanced_auto_repeat"), ) - autoRepeatFingerprint.apply { - match(context, autoRepeatParentMatch.classDef) - }.matchOrThrow.mutableMethod.apply { - val playMethod = autoRepeatParentMatch.mutableMethod + autoRepeatFingerprint.match(autoRepeatParentFingerprint.originalClassDef).method.apply { + val playMethod = autoRepeatParentFingerprint.method val index = instructions.lastIndex // Remove return-void. diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt index 78229a809..36f7cfddd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/backgroundplayback/BackgroundPlaybackPatch.kt @@ -15,10 +15,7 @@ import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.video.information.videoInformationPatch -import app.revanced.util.addInstructionsAtControlFlowLabel -import app.revanced.util.findInstructionIndicesReversedOrThrow -import app.revanced.util.getReference -import app.revanced.util.returnEarly +import app.revanced.util.* import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.MethodReference @@ -60,26 +57,18 @@ val backgroundPlaybackPatch = bytecodePatch( ), ) - val backgroundPlaybackManagerMatch by backgroundPlaybackManagerFingerprint() - val backgroundPlaybackSettingsMatch by backgroundPlaybackSettingsFingerprint() - - val shortsBackgroundPlaybackFeatureFlagMatch by shortsBackgroundPlaybackFeatureFlagFingerprint() - val backgroundPlaybackManagerShortsMatch by backgroundPlaybackManagerShortsFingerprint() - - val kidsBackgroundPlaybackPolicyControllerMatch by kidsBackgroundPlaybackPolicyControllerFingerprint() - - execute { context -> + execute { addResources("youtube", "misc.backgroundplayback.backgroundPlaybackPatch") PreferenceScreen.SHORTS.addPreferences( - SwitchPreference("revanced_shorts_disable_background_playback") + SwitchPreference("revanced_shorts_disable_background_playback"), ) arrayOf( - backgroundPlaybackManagerMatch to "isBackgroundPlaybackAllowed", - backgroundPlaybackManagerShortsMatch to "isBackgroundShortsPlaybackAllowed" - ).forEach { (match, integrationsMethod) -> - match.mutableMethod.apply { + backgroundPlaybackManagerFingerprint to "isBackgroundPlaybackAllowed", + backgroundPlaybackManagerShortsFingerprint to "isBackgroundShortsPlaybackAllowed", + ).forEach { (fingerprint, integrationsMethod) -> + fingerprint.method.apply { findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index -> val register = getInstruction(index).registerA @@ -88,28 +77,28 @@ val backgroundPlaybackPatch = bytecodePatch( """ invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->$integrationsMethod(Z)Z move-result v$register - """ + """, ) } } } // Enable background playback option in YouTube settings - backgroundPlaybackSettingsMatch.mutableMethod.apply { + backgroundPlaybackSettingsFingerprint.originalMethod.apply { val booleanCalls = instructions.withIndex().filter { it.value.getReference()?.returnType == "Z" } val settingsBooleanIndex = booleanCalls.elementAt(1).index - val settingsBooleanMethod = context.navigate(this).at(settingsBooleanIndex).mutable() + val settingsBooleanMethod by navigate(this).to(settingsBooleanIndex) settingsBooleanMethod.returnEarly(true) } // Force allowing background play for Shorts. - shortsBackgroundPlaybackFeatureFlagMatch.mutableMethod.returnEarly(true) + shortsBackgroundPlaybackFeatureFlagFingerprint.method.returnEarly(true) // Force allowing background play for videos labeled for kids. - kidsBackgroundPlaybackPolicyControllerMatch.mutableMethod.returnEarly() + kidsBackgroundPlaybackPolicyControllerFingerprint.method.returnEarly() } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatch.kt index 9d68a03a2..9696418eb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/debugging/EnableDebuggingPatch.kt @@ -10,7 +10,6 @@ import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.settings.PreferenceScreen import app.revanced.patches.youtube.misc.settings.settingsPatch -import app.revanced.util.applyMatch import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode @@ -36,12 +35,10 @@ val enableDebuggingPatch = bytecodePatch( "19.25.37", "19.34.42", "19.43.41", - ) + ), ) - val experimentalFeatureFlagParentMatch by experimentalFeatureFlagParentFingerprint() - - execute { context -> + execute { addResources("youtube", "misc.debugging.enableDebuggingPatch") PreferenceScreen.MISC.addPreferences( @@ -58,11 +55,9 @@ val enableDebuggingPatch = bytecodePatch( ) // Hook the methods that look up if a feature flag is active. - - experimentalBooleanFeatureFlagFingerprint.applyMatch( - context, - experimentalFeatureFlagParentMatch - ).mutableMethod.apply { + experimentalBooleanFeatureFlagFingerprint.match( + experimentalFeatureFlagParentFingerprint.originalClassDef + ).method.apply { val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT) // It appears that all usage of this method has a default of 'false', @@ -78,10 +73,9 @@ val enableDebuggingPatch = bytecodePatch( ) } - experimentalDoubleFeatureFlagFingerprint.applyMatch( - context, - experimentalFeatureFlagParentMatch - ).mutableMethod.apply { + experimentalDoubleFeatureFlagFingerprint.match( + experimentalFeatureFlagParentFingerprint.originalClassDef + ).method.apply { val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT_WIDE) addInstructions( @@ -95,10 +89,9 @@ val enableDebuggingPatch = bytecodePatch( ) } - experimentalLongFeatureFlagFingerprint.applyMatch( - context, - experimentalFeatureFlagParentMatch - ).mutableMethod.apply { + experimentalLongFeatureFlagFingerprint.match( + experimentalFeatureFlagParentFingerprint.originalClassDef + ).method.apply { val insertIndex = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT_WIDE) addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt index af018b643..66718480c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dimensions/spoof/SpoofDeviceDimensionsPatch.kt @@ -34,8 +34,6 @@ val spoofDeviceDimensionsPatch = bytecodePatch( ), ) - val deviceDimensionsModelToStringMatch by deviceDimensionsModelToStringFingerprint() - execute { addResources("youtube", "misc.dimensions.spoof.spoofDeviceDimensionsPatch") @@ -43,8 +41,8 @@ val spoofDeviceDimensionsPatch = bytecodePatch( SwitchPreference("revanced_spoof_device_dimensions"), ) - deviceDimensionsModelToStringMatch - .mutableClass.methods.first { method -> method.name == "" } + deviceDimensionsModelToStringFingerprint + .classDef.methods.first { method -> method.name == "" } // Override the parameters containing the dimensions. .addInstructions( 1, // Add after super call. diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dns/CheckWatchHistoryDomainNameResolutionPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dns/CheckWatchHistoryDomainNameResolutionPatch.kt index f98030344..b831d1fae 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dns/CheckWatchHistoryDomainNameResolutionPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/dns/CheckWatchHistoryDomainNameResolutionPatch.kt @@ -24,12 +24,10 @@ val checkWatchHistoryDomainNameResolutionPatch = bytecodePatch( ), ) - val mainActivityOnCreateMatch by mainActivityOnCreateFingerprint() - execute { addResources("youtube", "misc.dns.checkWatchHistoryDomainNameResolutionPatch") - mainActivityOnCreateMatch.mutableMethod.addInstructions( + mainActivityOnCreateFingerprint.method.addInstructions( // FIXME: Insert index must be greater than the insert index used by GmsCoreSupport, // as both patch the same method and GmsCoreSupport check should be first, // but the patch does not depend on GmsCoreSupport, so it should not be possible to enforce this diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt index 6179cebf0..0778e814f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/FixBackToExitGesturePatch.kt @@ -1,45 +1,39 @@ package app.revanced.patches.youtube.misc.fix.backtoexitgesture -import app.revanced.patcher.Match +import app.revanced.patcher.Fingerprint import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.matchOrThrow internal val fixBackToExitGesturePatch = bytecodePatch( description = "Fixes the swipe back to exit gesture.", ) { - val recyclerViewTopScrollingParentMatch by recyclerViewTopScrollingParentFingerprint() - val recyclerViewScrollingMatch by recyclerViewScrollingFingerprint() - val onBackPressedMatch by onBackPressedFingerprint() - - execute { context -> - recyclerViewTopScrollingFingerprint.apply { - match(context, recyclerViewTopScrollingParentMatch.classDef) - } + execute { /** * Inject a call to a method from the extension. * * @param targetMethod The target method to call. */ - fun Match.injectCall(targetMethod: ExtensionMethod) = mutableMethod.addInstruction( + fun Fingerprint.injectCall(targetMethod: ExtensionMethod) = method.addInstruction( patternMatch!!.endIndex, targetMethod.toString(), ) mapOf( - recyclerViewTopScrollingFingerprint.matchOrThrow to ExtensionMethod( + recyclerViewTopScrollingFingerprint.also { + it.match(recyclerViewTopScrollingParentFingerprint.originalClassDef) + } to ExtensionMethod( methodName = "onTopView", ), - recyclerViewScrollingMatch to ExtensionMethod( + recyclerViewScrollingFingerprint to ExtensionMethod( methodName = "onScrollingViews", ), - onBackPressedMatch to ExtensionMethod( + onBackPressedFingerprint to ExtensionMethod( "p0", "onBackPressed", "Landroid/app/Activity;", ), - ).forEach { (match, target) -> match.injectCall(target) } + ).forEach { (fingerprint, target) -> fingerprint.injectCall(target) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/cairo/DisableCairoSettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/cairo/DisableCairoSettingsPatch.kt index 723419008..d6fafe539 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/cairo/DisableCairoSettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/cairo/DisableCairoSettingsPatch.kt @@ -16,8 +16,6 @@ internal val disableCairoSettingsPatch = bytecodePatch( ) { dependsOn(versionCheckPatch) - val cairoFragmentConfigMatch by cairoFragmentConfigFingerprint() - execute { if (!is_19_04_or_greater) { return@execute @@ -35,7 +33,7 @@ internal val disableCairoSettingsPatch = bytecodePatch( * Screenshots of the Cairo Fragment: * uYouPlus#1468. */ - cairoFragmentConfigMatch.mutableMethod.apply { + cairoFragmentConfigFingerprint.method.apply { val literalIndex = indexOfFirstLiteralInstructionOrThrow( CAIRO_CONFIG_LITERAL_VALUE, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/SpoofVideoStreamsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/SpoofVideoStreamsPatch.kt index c654cf91a..25b35c447 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/SpoofVideoStreamsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/playback/SpoofVideoStreamsPatch.kt @@ -52,13 +52,6 @@ val spoofVideoStreamsPatch = bytecodePatch( userAgentClientSpoofPatch, ) - val buildInitPlaybackRequestMatch by buildInitPlaybackRequestFingerprint() - val buildPlayerRequestURIMatch by buildPlayerRequestURIFingerprint() - val createStreamingDataMatch by createStreamingDataFingerprint() - val buildMediaDataSourceMatch by buildMediaDataSourceFingerprint() - val buildRequestMatch by buildRequestFingerprint() - val protobufClassParseByteBufferMatch by protobufClassParseByteBufferFingerprint() - execute { addResources("youtube", "misc.fix.playback.spoofVideoStreamsPatch") @@ -84,9 +77,9 @@ val spoofVideoStreamsPatch = bytecodePatch( // region Block /initplayback requests to fall back to /get_watch requests. - val moveUriStringIndex = buildInitPlaybackRequestMatch.patternMatch!!.startIndex + val moveUriStringIndex = buildInitPlaybackRequestFingerprint.patternMatch!!.startIndex - buildInitPlaybackRequestMatch.mutableMethod.apply { + buildInitPlaybackRequestFingerprint.method.apply { val targetRegister = getInstruction(moveUriStringIndex).registerA addInstructions( @@ -102,9 +95,9 @@ val spoofVideoStreamsPatch = bytecodePatch( // region Block /get_watch requests to fall back to /player requests. - val invokeToStringIndex = buildPlayerRequestURIMatch.patternMatch!!.startIndex + val invokeToStringIndex = buildPlayerRequestURIFingerprint.patternMatch!!.startIndex - buildPlayerRequestURIMatch.mutableMethod.apply { + buildPlayerRequestURIFingerprint.method.apply { val uriRegister = getInstruction(invokeToStringIndex).registerC addInstructions( @@ -120,7 +113,7 @@ val spoofVideoStreamsPatch = bytecodePatch( // region Get replacement streams at player requests. - buildRequestMatch.mutableMethod.apply { + buildRequestFingerprint.method.apply { val newRequestBuilderIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_VIRTUAL && getReference()?.name == "newUrlRequestBuilder" @@ -141,10 +134,10 @@ val spoofVideoStreamsPatch = bytecodePatch( // region Replace the streaming data with the replacement streams. - createStreamingDataMatch.mutableMethod.apply { + createStreamingDataFingerprint.method.apply { val setStreamDataMethodName = "patch_setStreamingData" - val resultMethodType = createStreamingDataMatch.mutableClass.type - val videoDetailsIndex = createStreamingDataMatch.patternMatch!!.endIndex + val resultMethodType = createStreamingDataFingerprint.classDef.type + val videoDetailsIndex = createStreamingDataFingerprint.patternMatch!!.endIndex val videoDetailsRegister = getInstruction(videoDetailsIndex).registerA val videoDetailsClass = getInstruction(videoDetailsIndex).getReference()!!.type @@ -154,8 +147,8 @@ val spoofVideoStreamsPatch = bytecodePatch( "$resultMethodType->$setStreamDataMethodName($videoDetailsClass)V", ) - val protobufClass = protobufClassParseByteBufferMatch.mutableMethod.definingClass - val setStreamingDataIndex = createStreamingDataMatch.patternMatch!!.startIndex + val protobufClass = protobufClassParseByteBufferFingerprint.method.definingClass + val setStreamingDataIndex = createStreamingDataFingerprint.patternMatch!!.startIndex val playerProtoClass = getInstruction(setStreamingDataIndex + 1) .getReference()!!.definingClass @@ -169,7 +162,7 @@ val spoofVideoStreamsPatch = bytecodePatch( ).getReference() // Use a helper method to avoid the need of picking out multiple free registers from the hooked code. - createStreamingDataMatch.mutableClass.methods.add( + createStreamingDataFingerprint.classDef.methods.add( ImmutableMethod( resultMethodType, setStreamDataMethodName, @@ -222,7 +215,7 @@ val spoofVideoStreamsPatch = bytecodePatch( // Requesting streams intended for other platforms with a body tuned for Android could be the cause of 400 errors. // A proper fix may include modifying the request body to match the platforms expected body. - buildMediaDataSourceMatch.mutableMethod.apply { + buildMediaDataSourceFingerprint.method.apply { val targetIndex = instructions.lastIndex // Instructions are added just before the method returns, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt index 8e21147f6..b9292ef84 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/imageurlhook/CronetImageUrlHook.kt @@ -7,7 +7,6 @@ import app.revanced.patcher.patch.bytecodePatch import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod import app.revanced.patcher.util.proxy.mutableTypes.MutableMethod.Companion.toMutable import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch -import app.revanced.util.applyMatch import app.revanced.util.getReference import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -30,23 +29,19 @@ val cronetImageUrlHookPatch = bytecodePatch( ) { dependsOn(sharedExtensionPatch) - val messageDigestImageUrlParentMatch by messageDigestImageUrlParentFingerprint() - val onResponseStartedMatch by onResponseStartedFingerprint() - val requestMatch by requestFingerprint() - - execute { context -> + execute { loadImageUrlMethod = messageDigestImageUrlFingerprint - .applyMatch(context, messageDigestImageUrlParentMatch).mutableMethod + .match(messageDigestImageUrlParentFingerprint.originalClassDef).method loadImageSuccessCallbackMethod = onSucceededFingerprint - .applyMatch(context, onResponseStartedMatch).mutableMethod + .match(onResponseStartedFingerprint.originalClassDef).method loadImageErrorCallbackMethod = onFailureFingerprint - .applyMatch(context, onResponseStartedMatch).mutableMethod + .match(onResponseStartedFingerprint.originalClassDef).method // The URL is required for the failure callback hook, but the URL field is obfuscated. // Add a helper get method that returns the URL field. - val urlFieldInstruction = requestMatch.mutableMethod.instructions.first { + val urlFieldInstruction = requestFingerprint.method.instructions.first { val reference = it.getReference() it.opcode == Opcode.IPUT_OBJECT && reference?.type == "Ljava/lang/String;" } as ReferenceInstruction @@ -54,7 +49,7 @@ val cronetImageUrlHookPatch = bytecodePatch( val urlFieldName = (urlFieldInstruction.reference as FieldReference).name val definingClass = CRONET_URL_REQUEST_CLASS_DESCRIPTOR val addedMethodName = "getHookedUrl" - requestMatch.mutableClass.methods.add( + requestFingerprint.classDef.methods.add( ImmutableMethod( definingClass, addedMethodName, @@ -82,7 +77,7 @@ val cronetImageUrlHookPatch = bytecodePatch( fun addImageUrlHook(targetMethodClass: String, highPriority: Boolean = false) { loadImageUrlMethod.addInstructions( if (highPriority) 0 else loadImageUrlIndex, -""" + """ invoke-static { p1 }, $targetMethodClass->overrideImageURL(Ljava/lang/String;)Ljava/lang/String; move-result-object p1 """, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt index 7112d43e2..d2c06292c 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/links/BypassURLRedirectsPatch.kt @@ -40,11 +40,6 @@ val bypassURLRedirectsPatch = bytecodePatch( ), ) - val abUriParserMatch by abUriParserFingerprint() - val abUriParserLegacyMatch by abUriParserLegacyFingerprint() - val httpUriParserMatch by httpUriParserFingerprint() - val httpUriParserLegacyMatch by httpUriParserLegacyFingerprint() - execute { addResources("youtube", "misc.links.bypassURLRedirectsPatch") @@ -52,20 +47,20 @@ val bypassURLRedirectsPatch = bytecodePatch( SwitchPreference("revanced_bypass_url_redirects"), ) - val matches = if (is_19_33_or_greater) { + val fingerprints = if (is_19_33_or_greater) { arrayOf( - abUriParserMatch, - httpUriParserMatch, + abUriParserFingerprint, + httpUriParserFingerprint, ) } else { arrayOf( - abUriParserLegacyMatch, - httpUriParserLegacyMatch, + abUriParserLegacyFingerprint, + httpUriParserLegacyFingerprint, ) } - matches.forEach { - it.mutableMethod.apply { + fingerprints.forEach { + it.method.apply { val insertIndex = findUriParseIndex() val uriStringRegister = getInstruction(insertIndex).registerC diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/LithoFilterPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/LithoFilterPatch.kt index e0db2c821..16a834083 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/LithoFilterPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/litho/filter/LithoFilterPatch.kt @@ -37,14 +37,6 @@ val lithoFilterPatch = bytecodePatch( versionCheckPatch, ) - val componentContextParserMatch by componentContextParserFingerprint() - val lithoFilterMatch by lithoFilterFingerprint() - val protobufBufferReferenceMatch by protobufBufferReferenceFingerprint() - val readComponentIdentifierMatch by readComponentIdentifierFingerprint() - val emptyComponentMatch by emptyComponentFingerprint() - val lithoComponentNameUpbFeatureFlagMatch by lithoComponentNameUpbFeatureFlagFingerprint() - val lithoConverterBufferUpbFeatureFlagMatch by lithoConverterBufferUpbFeatureFlagFingerprint() - var filterCount = 0 /** @@ -98,10 +90,10 @@ val lithoFilterPatch = bytecodePatch( * } * } */ - execute { context -> + execute { // Remove dummy filter from extenion static field // and add the filters included during patching. - lithoFilterMatch.mutableMethod.apply { + lithoFilterFingerprint.method.apply { removeInstructions(2, 4) // Remove dummy filter. addLithoFilter = { classDescriptor -> @@ -119,7 +111,7 @@ val lithoFilterPatch = bytecodePatch( // region Pass the buffer into extension. - protobufBufferReferenceMatch.mutableMethod.addInstruction( + protobufBufferReferenceFingerprint.method.addInstruction( 0, " invoke-static { p2 }, $EXTENSION_CLASS_DESCRIPTOR->setProtoBuffer(Ljava/nio/ByteBuffer;)V", ) @@ -128,18 +120,18 @@ val lithoFilterPatch = bytecodePatch( // region Hook the method that parses bytes into a ComponentContext. - val readComponentMethod = readComponentIdentifierMatch.method + val readComponentMethod = readComponentIdentifierFingerprint.originalMethod // Get the only static method in the class. - val builderMethodDescriptor = emptyComponentMatch.classDef.methods.first { method -> + val builderMethodDescriptor = emptyComponentFingerprint.classDef.methods.first { method -> AccessFlags.STATIC.isSet(method.accessFlags) } // Only one field. - val emptyComponentField = context.classBy { classDef -> + val emptyComponentField = classBy { classDef -> builderMethodDescriptor.returnType == classDef.type }!!.immutableClass.fields.single() // Returns an empty component instead of the original component. - fun createReturnEmptyComponentInstructions(register : Int) : String = + fun createReturnEmptyComponentInstructions(register: Int): String = """ move-object/from16 v$register, p1 invoke-static { v$register }, $builderMethodDescriptor @@ -148,7 +140,7 @@ val lithoFilterPatch = bytecodePatch( return-object v$register """ - componentContextParserMatch.mutableMethod.apply { + componentContextParserFingerprint.method.apply { // 19.18 and later require patching 2 methods instead of one. // Otherwise the modifications done here are the same for all targets. if (is_19_18_or_greater) { @@ -183,7 +175,7 @@ val lithoFilterPatch = bytecodePatch( // region Read component then store the result. - readComponentIdentifierMatch.mutableMethod.apply { + readComponentIdentifierFingerprint.method.apply { val insertHookIndex = indexOfFirstInstructionOrThrow { opcode == Opcode.IPUT_OBJECT && getReference()?.type == "Ljava/lang/StringBuilder;" @@ -244,7 +236,7 @@ val lithoFilterPatch = bytecodePatch( // Turn off native code that handles litho component names. If this feature is on then nearly // all litho components have a null name and identifier/path filtering is completely broken. if (is_19_25_or_greater) { - lithoComponentNameUpbFeatureFlagMatch.mutableMethod.apply { + lithoComponentNameUpbFeatureFlagFingerprint.method.apply { // Don't use return early, so the debug patch logs if this was originally on. val insertIndex = indexOfFirstInstructionOrThrow(Opcode.RETURN) val register = getInstruction(insertIndex).registerA @@ -256,7 +248,7 @@ val lithoFilterPatch = bytecodePatch( // Turn off a feature flag that enables native code of protobuf parsing (Upb protobuf). // If this is enabled, then the litho protobuffer hook will always show an empty buffer // since it's no longer handled by the hooked Java code. - lithoConverterBufferUpbFeatureFlagMatch.mutableMethod.apply { + lithoConverterBufferUpbFeatureFlagFingerprint.method.apply { val index = indexOfFirstInstructionOrThrow(Opcode.MOVE_RESULT) val register = getInstruction(index).registerA @@ -267,6 +259,6 @@ val lithoFilterPatch = bytecodePatch( } finalize { - lithoFilterMatch.mutableMethod.replaceInstruction(0, "const/16 v0, $filterCount") + lithoFilterFingerprint.method.replaceInstruction(0, "const/16 v0, $filterCount") } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt index 9541eb43f..503eb91d4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/NavigationBarHookPatch.kt @@ -12,7 +12,9 @@ import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.shared.misc.mapping.resourceMappings import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch -import app.revanced.util.* +import app.revanced.util.getReference +import app.revanced.util.indexOfFirstInstructionOrThrow +import app.revanced.util.indexOfFirstLiteralInstructionOrThrow import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.Instruction @@ -48,16 +50,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig playerTypeHookPatch, // Required to detect the search bar in all situations. ) - val pivotBarConstructorMatch by pivotBarConstructorFingerprint() - val navigationEnumMatch by navigationEnumFingerprint() - val pivotBarButtonsCreateDrawableViewMatch by pivotBarButtonsCreateDrawableViewFingerprint() - val pivotBarButtonsCreateResourceViewMatch by pivotBarButtonsCreateResourceViewFingerprint() - val pivotBarButtonsViewSetSelectedMatch by pivotBarButtonsViewSetSelectedFingerprint() - val navigationBarHookCallbackMatch by navigationBarHookCallbackFingerprint() - val mainActivityOnBackPressedMatch by mainActivityOnBackPressedFingerprint() - val actionBarSearchResultsMatch by actionBarSearchResultsFingerprint() - - execute { context -> + execute { fun MutableMethod.addHook(hook: Hook, insertPredicate: Instruction.() -> Boolean) { val filtered = instructions.filter(insertPredicate) if (filtered.isEmpty()) throw PatchException("Could not find insert indexes") @@ -73,16 +66,16 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig } } - initializeButtonsFingerprint.applyMatch(context, pivotBarConstructorMatch).mutableMethod.apply { + initializeButtonsFingerprint.match(pivotBarConstructorFingerprint.originalClassDef).method.apply { // Hook the current navigation bar enum value. Note, the 'You' tab does not have an enum value. - val navigationEnumClassName = navigationEnumMatch.mutableClass.type + val navigationEnumClassName = navigationEnumFingerprint.classDef.type addHook(Hook.SET_LAST_APP_NAVIGATION_ENUM) { opcode == Opcode.INVOKE_STATIC && getReference()?.definingClass == navigationEnumClassName } // Hook the creation of navigation tab views. - val drawableTabMethod = pivotBarButtonsCreateDrawableViewMatch.mutableMethod + val drawableTabMethod = pivotBarButtonsCreateDrawableViewFingerprint.method addHook(Hook.NAVIGATION_TAB_LOADED) predicate@{ MethodUtil.methodSignaturesMatch( getReference() ?: return@predicate false, @@ -90,7 +83,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig ) } - val imageResourceTabMethod = pivotBarButtonsCreateResourceViewMatch.method + val imageResourceTabMethod = pivotBarButtonsCreateResourceViewFingerprint.originalMethod addHook(Hook.NAVIGATION_IMAGE_RESOURCE_TAB_LOADED) predicate@{ MethodUtil.methodSignaturesMatch( getReference() ?: return@predicate false, @@ -99,7 +92,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig } } - pivotBarButtonsViewSetSelectedMatch.mutableMethod.apply { + pivotBarButtonsViewSetSelectedFingerprint.method.apply { val index = indexOfSetViewSelectedInstruction(this) val instruction = getInstruction(index) val viewRegister = instruction.registerC @@ -114,7 +107,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig // Hook onto back button pressed. Needed to fix race problem with // Litho filtering based on navigation tab before the tab is updated. - mainActivityOnBackPressedMatch.mutableMethod.addInstruction( + mainActivityOnBackPressedFingerprint.method.addInstruction( 0, "invoke-static { p0 }, " + "$EXTENSION_CLASS_DESCRIPTOR->onBackPressed(Landroid/app/Activity;)V", @@ -125,7 +118,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig // Two different layouts are used at the hooked code. // Insert before the first ViewGroup method call after inflating, // so this works regardless which layout is used. - actionBarSearchResultsMatch.mutableMethod.apply { + actionBarSearchResultsFingerprint.method.apply { val searchBarResourceId = indexOfFirstLiteralInstructionOrThrow( actionBarSearchResultsViewMicId, ) @@ -144,7 +137,7 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig } hookNavigationButtonCreated = { extensionClassDescriptor -> - navigationBarHookCallbackMatch.mutableMethod.addInstruction( + navigationBarHookCallbackFingerprint.method.addInstruction( 0, "invoke-static { p0, p1 }, " + "$extensionClassDescriptor->navigationTabCreated" + @@ -157,5 +150,5 @@ val navigationBarHookPatch = bytecodePatch(description = "Hooks the active navig private enum class Hook(val methodName: String, val parameters: String) { SET_LAST_APP_NAVIGATION_ENUM("setLastAppNavigationEnum", "Ljava/lang/Enum;"), NAVIGATION_TAB_LOADED("navigationTabLoaded", "Landroid/view/View;"), - NAVIGATION_IMAGE_RESOURCE_TAB_LOADED("navigationImageResourceTabLoaded", "Landroid/view/View;") + NAVIGATION_IMAGE_RESOURCE_TAB_LOADED("navigationImageResourceTabLoaded", "Landroid/view/View;"), } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsPatch.kt index a198e75ea..d2a20deb0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/PlayerControlsPatch.kt @@ -59,7 +59,7 @@ val playerControlsResourcePatch = resourcePatch { lateinit var bottomTargetDocument: Document - execute { context -> + execute { val targetResourceName = "youtube_controls_bottom_ui_container.xml" bottomUiContainerResourceId = resourceMappings["id", "bottom_ui_container_stub"] @@ -67,7 +67,7 @@ val playerControlsResourcePatch = resourcePatch { heatseekerViewstub = resourceMappings["id", "heatseeker_viewstub"] fullscreenButton = resourceMappings["id", "fullscreen_button"] - bottomTargetDocument = context.document["res/layout/$targetResourceName"] + bottomTargetDocument = document("res/layout/$targetResourceName") val bottomTargetElement: Node = bottomTargetDocument.getElementsByTagName( "android.support.constraint.ConstraintLayout", @@ -85,13 +85,13 @@ val playerControlsResourcePatch = resourcePatch { val resourceFileName = "host/layout/youtube_controls_layout.xml" val hostingResourceStream = inputStreamFromBundledResource( resourceDirectoryName, - resourceFileName + resourceFileName, ) ?: throw PatchException("Could not find $resourceFileName") - val document = context.document["res/layout/youtube_controls_layout.xml"] + val document = document("res/layout/youtube_controls_layout.xml") "RelativeLayout".copyXmlNode( - context.document[hostingResourceStream], + document(hostingResourceStream), document, ).use { val element = document.childNodes.findElementByAttributeValueOrThrow( @@ -109,10 +109,10 @@ val playerControlsResourcePatch = resourcePatch { addBottomControl = { resourceDirectoryName -> val resourceFileName = "host/layout/youtube_controls_bottom_ui_container.xml" - val sourceDocument = context.document[ + val sourceDocument = document( inputStreamFromBundledResource(resourceDirectoryName, resourceFileName) - ?: throw PatchException("Could not find $resourceFileName") - ] + ?: throw PatchException("Could not find $resourceFileName"), + ) val sourceElements = sourceDocument.getElementsByTagName( "android.support.constraint.ConstraintLayout", @@ -214,13 +214,7 @@ val playerControlsPatch = bytecodePatch( ) { dependsOn(playerControlsResourcePatch) - val playerBottomControlsInflateMatch by playerBottomControlsInflateFingerprint() - val playerTopControlsInflateMatch by playerTopControlsInflateFingerprint() - val overlayViewInflateMatch by overlayViewInflateFingerprint() - val playerControlsExtensionHookMatch by playerControlsExtensionHookFingerprint() - val playerControlsExploderFeatureFlagMatch by playerControlsExploderFeatureFlagFingerprint() - - execute { context -> + execute { fun MutableMethod.indexOfFirstViewInflateOrThrow() = indexOfFirstInstructionOrThrow { val reference = getReference() @@ -228,7 +222,7 @@ val playerControlsPatch = bytecodePatch( reference.name == "inflate" } - playerBottomControlsInflateMatch.mutableMethod.apply { + playerBottomControlsInflateFingerprint.method.apply { inflateBottomControlMethod = this val inflateReturnObjectIndex = indexOfFirstViewInflateOrThrow() + 1 @@ -236,7 +230,7 @@ val playerControlsPatch = bytecodePatch( inflateBottomControlInsertIndex = inflateReturnObjectIndex + 1 } - playerTopControlsInflateMatch.mutableMethod.apply { + playerTopControlsInflateFingerprint.method.apply { inflateTopControlMethod = this val inflateReturnObjectIndex = indexOfFirstViewInflateOrThrow() + 1 @@ -244,16 +238,13 @@ val playerControlsPatch = bytecodePatch( inflateTopControlInsertIndex = inflateReturnObjectIndex + 1 } - controlsOverlayVisibilityFingerprint.applyMatch( - context, - playerTopControlsInflateMatch, - ).mutableMethod.apply { - visibilityMethod = this - } + visibilityMethod = controlsOverlayVisibilityFingerprint.match( + playerTopControlsInflateFingerprint.originalClassDef, + ).method // Hook the fullscreen close button. Used to fix visibility // when seeking and other situations. - overlayViewInflateMatch.mutableMethod.apply { + overlayViewInflateFingerprint.method.apply { val resourceIndex = indexOfFirstLiteralInstructionReversedOrThrow(fullscreenButton) val index = indexOfFirstInstructionOrThrow(resourceIndex) { @@ -270,14 +261,14 @@ val playerControlsPatch = bytecodePatch( ) } - visibilityImmediateMethod = playerControlsExtensionHookMatch.mutableMethod + visibilityImmediateMethod = playerControlsExtensionHookFingerprint.method // A/B test for a slightly different overlay controls, // that uses layout file youtube_video_exploder_controls_bottom_ui_container.xml // The change to support this is simple and only requires adding buttons to both layout files, // but for now force this different layout off since it's still an experimental test. if (is_19_35_or_greater) { - playerControlsExploderFeatureFlagMatch.mutableMethod.returnEarly() + playerControlsExploderFeatureFlagFingerprint.method.returnEarly() } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/PlayerTypeHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/PlayerTypeHookPatch.kt index 0b3a5a52c..e021928a8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/PlayerTypeHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/PlayerTypeHookPatch.kt @@ -14,17 +14,14 @@ val playerTypeHookPatch = bytecodePatch( ) { dependsOn(sharedExtensionPatch) - val playerTypeMatch by playerTypeFingerprint() - val videoStateMatch by videoStateFingerprint() - execute { - playerTypeMatch.mutableMethod.addInstruction( + playerTypeFingerprint.method.addInstruction( 0, "invoke-static {p1}, $EXTENSION_CLASS_DESCRIPTOR->setPlayerType(Ljava/lang/Enum;)V", ) - videoStateMatch.mutableMethod.apply { - val endIndex = videoStateMatch.patternMatch!!.endIndex + videoStateFingerprint.method.apply { + val endIndex = videoStateFingerprint.patternMatch!!.endIndex val videoStateFieldName = getInstruction(endIndex).reference addInstructions( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playservice/VersionCheckPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playservice/VersionCheckPatch.kt index 780ad310a..0598a77bd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playservice/VersionCheckPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playservice/VersionCheckPatch.kt @@ -41,10 +41,10 @@ var is_19_43_or_greater = false val versionCheckPatch = resourcePatch( description = "Uses the Play Store service version to find the major/minor version of the YouTube target app.", ) { - execute { context -> + execute { // The app version is missing from the decompiled manifest, // so instead use the Google Play services version and compare against specific releases. - val playStoreServicesVersion = context.document["res/values/integers.xml"].use { document -> + val playStoreServicesVersion = document("res/values/integers.xml").use { document -> document.documentElement.childNodes.findElementByAttributeValueOrThrow( "name", "google_play_services_version", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/privacy/RemoveTrackingQueryParameterPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/privacy/RemoveTrackingQueryParameterPatch.kt index ee397c8f0..7a6d519e4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/privacy/RemoveTrackingQueryParameterPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/privacy/RemoveTrackingQueryParameterPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.privacy +import app.revanced.patcher.Fingerprint import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction @@ -39,10 +40,6 @@ val removeTrackingQueryParameterPatch = bytecodePatch( ), ) - val youTubeShareSheetMatch by youtubeShareSheetFingerprint() - val systemShareSheetMatch by systemShareSheetFingerprint() - val copyTextMatch by copyTextFingerprint() - execute { addResources("youtube", "misc.privacy.removeTrackingQueryParameterPatch") @@ -50,14 +47,14 @@ val removeTrackingQueryParameterPatch = bytecodePatch( SwitchPreference("revanced_remove_tracking_query_parameter"), ) - fun Match.hook( + fun Fingerprint.hook( getInsertIndex: Match.PatternMatch.() -> Int, getUrlRegister: MutableMethod.(insertIndex: Int) -> Int, ) { val insertIndex = patternMatch!!.getInsertIndex() - val urlRegister = mutableMethod.getUrlRegister(insertIndex) + val urlRegister = method.getUrlRegister(insertIndex) - mutableMethod.addInstructions( + method.addInstructions( insertIndex, """ invoke-static {v$urlRegister}, $EXTENSION_CLASS_DESCRIPTOR->sanitize(Ljava/lang/String;)Ljava/lang/String; @@ -66,17 +63,17 @@ val removeTrackingQueryParameterPatch = bytecodePatch( ) } - // YouTube share sheet. - youTubeShareSheetMatch.hook(getInsertIndex = { startIndex + 1 }) { insertIndex -> + // YouTube share sheet.\ + youtubeShareSheetFingerprint.hook(getInsertIndex = { startIndex + 1 }) { insertIndex -> getInstruction(insertIndex - 1).registerA } // Native system share sheet. - systemShareSheetMatch.hook(getInsertIndex = { endIndex }) { insertIndex -> + systemShareSheetFingerprint.hook(getInsertIndex = { endIndex }) { insertIndex -> getInstruction(insertIndex - 1).registerA } - copyTextMatch.hook(getInsertIndex = { startIndex + 2 }) { insertIndex -> + copyTextFingerprint.hook(getInsertIndex = { startIndex + 2 }) { insertIndex -> getInstruction(insertIndex - 2).registerA } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/recyclerviewtree/hook/RecyclerViewTreeHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/recyclerviewtree/hook/RecyclerViewTreeHookPatch.kt index 16863b200..86588df09 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/recyclerviewtree/hook/RecyclerViewTreeHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/recyclerviewtree/hook/RecyclerViewTreeHookPatch.kt @@ -10,11 +10,10 @@ lateinit var addRecyclerViewTreeHook: (String) -> Unit val recyclerViewTreeHookPatch = bytecodePatch { dependsOn(sharedExtensionPatch) - val recyclerViewTreeObserverMatch by recyclerViewTreeObserverFingerprint() - execute { - recyclerViewTreeObserverMatch.mutableMethod.apply { - val insertIndex = recyclerViewTreeObserverMatch.patternMatch!!.startIndex + 1 + + recyclerViewTreeObserverFingerprint.method.apply { + val insertIndex = recyclerViewTreeObserverFingerprint.patternMatch!!.startIndex + 1 val recyclerViewParameter = 2 addRecyclerViewTreeHook = { classDescriptor -> diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt index 183950b03..627a70f91 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/SettingsPatch.kt @@ -19,7 +19,6 @@ import app.revanced.patches.youtube.misc.check.checkEnvironmentPatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.fix.cairo.disableCairoSettingsPatch import app.revanced.util.* -import app.revanced.util.inputStreamFromBundledResource import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.util.MethodUtil @@ -47,14 +46,14 @@ private val settingsResourcePatch = resourcePatch { ), ) - execute { context -> + execute { // Used for a fingerprint from SettingsPatch. appearanceStringId = resourceMappings["string", "app_theme_appearance_dark"] arrayOf( ResourceGroup("layout", "revanced_settings_with_toolbar.xml"), ).forEach { resourceGroup -> - context.copyResources("settings", resourceGroup) + copyResources("settings", resourceGroup) } // Copy style properties used to fix over-sized copy menu that appear in EditTextPreference. @@ -66,14 +65,14 @@ private val settingsResourcePatch = resourcePatch { targetResource, )!!.let { inputStream -> "resources".copyXmlNode( - context.document[inputStream], - context.document["res/$targetResource"], + document(inputStream), + document("res/$targetResource"), ).close() } // Remove horizontal divider from the settings Preferences // To better match the appearance of the stock YouTube settings. - context.document["res/values/styles.xml"].use { document -> + document("res/values/styles.xml").use { document -> arrayOf( "Theme.YouTube.Settings", @@ -93,7 +92,7 @@ private val settingsResourcePatch = resourcePatch { // Modify the manifest and add a data intent filter to the LicenseActivity. // Some devices freak out if undeclared data is passed to an intent, // and this change appears to fix the issue. - context.document["AndroidManifest.xml"].use { document -> + document("AndroidManifest.xml").use { document -> val licenseElement = document.childNodes.findElementByAttributeValueOrThrow( "android:name", @@ -124,9 +123,6 @@ val settingsPatch = bytecodePatch( checkEnvironmentPatch, ) - val setThemeMatch by setThemeFingerprint() - val licenseActivityOnCreateMatch by licenseActivityOnCreateFingerprint() - val extensionPackage = "app/revanced/extension/youtube" val activityHookClassDescriptor = "L$extensionPackage/settings/LicenseActivityHook;" @@ -154,7 +150,7 @@ val settingsPatch = bytecodePatch( ), ) - setThemeMatch.mutableMethod.let { setThemeMethod -> + setThemeFingerprint.method.let { setThemeMethod -> setThemeMethod.implementation!!.instructions.mapIndexedNotNull { i, instruction -> if (instruction.opcode == Opcode.RETURN_OBJECT) i else null }.asReversed().forEach { returnIndex -> @@ -178,7 +174,8 @@ val settingsPatch = bytecodePatch( // Modify the license activity and remove all existing layout code. // Must modify an existing activity and cannot add a new activity to the manifest, // as that fails for root installations. - licenseActivityOnCreateMatch.mutableMethod.addInstructions( + + licenseActivityOnCreateFingerprint.method.addInstructions( 1, """ invoke-static { p0 }, $activityHookClassDescriptor->initialize(Landroid/app/Activity;)V @@ -187,7 +184,7 @@ val settingsPatch = bytecodePatch( ) // Remove other methods as they will break as the onCreate method is modified above. - licenseActivityOnCreateMatch.mutableClass.apply { + licenseActivityOnCreateFingerprint.classDef.apply { methods.removeIf { it.name != "onCreate" && !MethodUtil.isConstructor(it) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/ZoomHapticsPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/ZoomHapticsPatch.kt index 38afeddd4..77ec07f13 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/ZoomHapticsPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/zoomhaptics/ZoomHapticsPatch.kt @@ -28,11 +28,9 @@ val zoomHapticsPatch = bytecodePatch( "19.25.37", "19.34.42", "19.43.41", - ) + ), ) - val zoomHapticsMatch by zoomHapticsFingerprint() - execute { addResources("youtube", "misc.zoomhaptics.zoomHapticsPatch") @@ -40,7 +38,7 @@ val zoomHapticsPatch = bytecodePatch( SwitchPreference("revanced_disable_zoom_haptics"), ) - zoomHapticsMatch.mutableMethod.apply { + zoomHapticsFingerprint.method.apply { addInstructionsWithLabels( 0, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt index 2f7ce505a..4b1755141 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/VideoInformationPatch.kt @@ -16,7 +16,6 @@ import app.revanced.patches.youtube.video.videoid.hookBackgroundPlayVideoId import app.revanced.patches.youtube.video.videoid.hookPlayerResponseVideoId import app.revanced.patches.youtube.video.videoid.hookVideoId import app.revanced.patches.youtube.video.videoid.videoIdPatch -import app.revanced.util.applyMatch import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionOrThrow import com.android.tools.smali.dexlib2.AccessFlags @@ -34,7 +33,8 @@ import com.android.tools.smali.dexlib2.immutable.ImmutableMethodParameter import com.android.tools.smali.dexlib2.util.MethodUtil private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/VideoInformation;" -private const val EXTENSION_PLAYER_INTERFACE = "Lapp/revanced/extension/youtube/patches/VideoInformation${'$'}PlaybackController;" +private const val EXTENSION_PLAYER_INTERFACE = + "Lapp/revanced/extension/youtube/patches/VideoInformation${'$'}PlaybackController;" private lateinit var playerInitMethod: MutableMethod private var playerInitInsertIndex = -1 @@ -74,15 +74,9 @@ val videoInformationPatch = bytecodePatch( playerResponseMethodHookPatch, ) - val playerInitMatch by playerInitFingerprint() - val mdxPlayerDirectorSetVideoStageMatch by mdxPlayerDirectorSetVideoStageFingerprint() - val createVideoPlayerSeekbarMatch by createVideoPlayerSeekbarFingerprint() - val playerControllerSetTimeReferenceMatch by playerControllerSetTimeReferenceFingerprint() - val onPlaybackSpeedItemClickMatch by onPlaybackSpeedItemClickFingerprint() - val newVideoQualityChangedMatch by newVideoQualityChangedFingerprint() + execute { - execute { context -> - playerInitMethod = playerInitMatch.mutableClass.methods.first { MethodUtil.isConstructor(it) } + playerInitMethod = playerInitFingerprint.classDef.methods.first { MethodUtil.isConstructor(it) } // Find the location of the first invoke-direct call and extract the register storing the 'this' object reference. val initThisIndex = playerInitMethod.indexOfFirstInstructionOrThrow { @@ -94,14 +88,19 @@ val videoInformationPatch = bytecodePatch( // Hook the player controller for use through the extension. onCreateHook(EXTENSION_CLASS_DESCRIPTOR, "initialize") - val seekFingerprintResultMethod = seekFingerprint.applyMatch(context, playerInitMatch).method - val seekRelativeFingerprintResultMethod = seekRelativeFingerprint.applyMatch(context, playerInitMatch).method + val seekFingerprintResultMethod = seekFingerprint.match(playerInitFingerprint.originalClassDef).method + val seekRelativeFingerprintResultMethod = + seekRelativeFingerprint.match(playerInitFingerprint.originalClassDef).method // Create extension interface methods. - addSeekInterfaceMethods(playerInitMatch.mutableClass, seekFingerprintResultMethod, seekRelativeFingerprintResultMethod) + addSeekInterfaceMethods( + playerInitFingerprint.classDef, + seekFingerprintResultMethod, + seekRelativeFingerprintResultMethod, + ) - with(mdxPlayerDirectorSetVideoStageMatch) { - mdxInitMethod = mutableClass.methods.first { MethodUtil.isConstructor(it) } + with(mdxPlayerDirectorSetVideoStageFingerprint) { + mdxInitMethod = classDef.methods.first { MethodUtil.isConstructor(it) } val initThisIndex = mdxInitMethod.indexOfFirstInstructionOrThrow { opcode == Opcode.INVOKE_DIRECT && getReference()?.name == "" @@ -112,18 +111,16 @@ val videoInformationPatch = bytecodePatch( // Hook the MDX director for use through the extension. onCreateHookMdx(EXTENSION_CLASS_DESCRIPTOR, "initializeMdx") - val mdxSeekFingerprintResultMethod = - mdxSeekFingerprint.applyMatch(context, mdxPlayerDirectorSetVideoStageMatch).method - val mdxSeekRelativeFingerprintResultMethod = - mdxSeekRelativeFingerprint.applyMatch(context, mdxPlayerDirectorSetVideoStageMatch).method + val mdxSeekFingerprintResultMethod = mdxSeekFingerprint.match(classDef).method + val mdxSeekRelativeFingerprintResultMethod = mdxSeekRelativeFingerprint.match(classDef).method - addSeekInterfaceMethods(mutableClass, mdxSeekFingerprintResultMethod, mdxSeekRelativeFingerprintResultMethod) + addSeekInterfaceMethods(classDef, mdxSeekFingerprintResultMethod, mdxSeekRelativeFingerprintResultMethod) } - with(createVideoPlayerSeekbarMatch) { - val videoLengthMethodMatch = videoLengthFingerprint.apply { match(context, classDef) }.match!! + with(createVideoPlayerSeekbarFingerprint) { + val videoLengthMethodMatch = videoLengthFingerprint.match(originalClassDef) - with(videoLengthMethodMatch.mutableMethod) { + videoLengthMethodMatch.method.apply { val videoLengthRegisterIndex = videoLengthMethodMatch.patternMatch!!.endIndex - 2 val videoLengthRegister = getInstruction(videoLengthRegisterIndex).registerA val dummyRegisterForLong = videoLengthRegister + 1 // required for long values since they are wide @@ -157,9 +154,9 @@ val videoInformationPatch = bytecodePatch( /* * Set the video time method */ - timeMethod = context.navigate(playerControllerSetTimeReferenceMatch.method) - .at(playerControllerSetTimeReferenceMatch.patternMatch!!.startIndex) - .mutable() + timeMethod = navigate(playerControllerSetTimeReferenceFingerprint.originalMethod) + .to(playerControllerSetTimeReferenceFingerprint.patternMatch!!.startIndex) + .stop() /* * Hook the methods which set the time @@ -169,7 +166,7 @@ val videoInformationPatch = bytecodePatch( /* * Hook the user playback speed selection */ - onPlaybackSpeedItemClickMatch.mutableMethod.apply { + onPlaybackSpeedItemClickFingerprint.method.apply { val speedSelectionMethodInstructions = implementation!!.instructions val speedSelectionValueInstructionIndex = speedSelectionMethodInstructions.indexOfFirst { it.opcode == Opcode.IGET @@ -188,11 +185,11 @@ val videoInformationPatch = bytecodePatch( } // Handle new playback speed menu. - playbackSpeedMenuSpeedChangedFingerprint.applyMatch( - context, - newVideoQualityChangedMatch, - ).mutableMethod.apply { + playbackSpeedMenuSpeedChangedFingerprint.match( + newVideoQualityChangedFingerprint.originalClassDef, + ).method.apply { val index = indexOfFirstInstructionOrThrow(Opcode.IGET) + speedSelectionInsertMethod = this speedSelectionInsertIndex = index + 1 speedSelectionValueRegister = getInstruction(index).registerA @@ -201,6 +198,7 @@ val videoInformationPatch = bytecodePatch( userSelectedPlaybackSpeedHook(EXTENSION_CLASS_DESCRIPTOR, "userSelectedPlaybackSpeed") } } + private fun addSeekInterfaceMethods(targetClass: MutableClass, seekToMethod: Method, seekToRelativeMethod: Method) { // Add the interface and methods that extension calls. targetClass.interfaces.add(EXTENSION_PLAYER_INTERFACE) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt index 3febd4a73..2a9a91245 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/playerresponse/PlayerResponseMethodHookPatch.kt @@ -34,17 +34,16 @@ val playerResponseMethodHookPatch = bytecodePatch { versionCheckPatch, ) - val playerParameterBuilderMatch by playerParameterBuilderFingerprint() - val playerParameterBuilderLegacyMatch by playerParameterBuilderLegacyFingerprint() - execute { - if (is_19_23_or_greater) { - playerResponseMethod = playerParameterBuilderMatch.mutableMethod + playerResponseMethod = if (is_19_23_or_greater) { parameterIsShortAndOpeningOrPlaying = 12 + + playerParameterBuilderFingerprint } else { - playerResponseMethod = playerParameterBuilderLegacyMatch.mutableMethod parameterIsShortAndOpeningOrPlaying = 11 - } + + playerParameterBuilderLegacyFingerprint + }.method // On some app targets the method has too many registers pushing the parameters past v15. // If needed, move the parameters to 4-bit registers, so they can be passed to the extension. diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/quality/RememberVideoQualityPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/quality/RememberVideoQualityPatch.kt index 61c466a64..8a2dfe4cc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/quality/RememberVideoQualityPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/quality/RememberVideoQualityPatch.kt @@ -15,10 +15,10 @@ import app.revanced.patches.youtube.misc.settings.settingsPatch import app.revanced.patches.youtube.shared.newVideoQualityChangedFingerprint import app.revanced.patches.youtube.video.information.onCreateHook import app.revanced.patches.youtube.video.information.videoInformationPatch -import app.revanced.util.applyMatch import com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction import com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.sun.org.apache.bcel.internal.generic.InstructionConst.getInstruction private const val EXTENSION_CLASS_DESCRIPTOR = "Lapp/revanced/extension/youtube/patches/playback/quality/RememberVideoQualityPatch;" @@ -46,11 +46,7 @@ val rememberVideoQualityPatch = bytecodePatch( ), ) - val videoQualitySetterMatch by videoQualitySetterFingerprint() - val videoQualityItemOnClickParentMatch by videoQualityItemOnClickParentFingerprint() - val newVideoQualityChangedMatch by newVideoQualityChangedFingerprint() - - execute { context -> + execute { addResources("youtube", "video.quality.rememberVideoQualityPatch") PreferenceScreen.VIDEO.addPreferences( @@ -79,9 +75,8 @@ val rememberVideoQualityPatch = bytecodePatch( onCreateHook(EXTENSION_CLASS_DESCRIPTOR, "newVideoStarted") // Inject a call to set the remembered quality once a video loads. - setQualityByIndexMethodClassFieldReferenceFingerprint.applyMatch( - context, - videoQualitySetterMatch, + setQualityByIndexMethodClassFieldReferenceFingerprint.match( + videoQualitySetterFingerprint.originalClassDef, ).let { match -> // This instruction refers to the field with the type that contains the setQualityByIndex method. val instructions = match.method.implementation!!.instructions @@ -94,7 +89,7 @@ val rememberVideoQualityPatch = bytecodePatch( val setQualityByIndexMethodClassFieldReference = getSetQualityByIndexMethodClassFieldReference as FieldReference - val setQualityByIndexMethodClass = context.classes + val setQualityByIndexMethodClass = classes .find { classDef -> classDef.type == setQualityByIndexMethodClassFieldReference.type }!! // Get the name of the setQualityByIndex method. @@ -102,7 +97,7 @@ val rememberVideoQualityPatch = bytecodePatch( .find { method -> method.parameterTypes.first() == "I" } ?: throw PatchException("Could not find setQualityByIndex method") - videoQualitySetterMatch.mutableMethod.addInstructions( + videoQualitySetterFingerprint.method.addInstructions( 0, """ # Get the object instance to invoke the setQualityByIndex method on. @@ -124,19 +119,20 @@ val rememberVideoQualityPatch = bytecodePatch( } // Inject a call to remember the selected quality. - videoQualityItemOnClickParentMatch.mutableClass.methods.find { it.name == "onItemClick" }?.apply { - val listItemIndexParameter = 3 + videoQualityItemOnClickParentFingerprint.classDef.methods.find { it.name == "onItemClick" } + ?.apply { + val listItemIndexParameter = 3 - addInstruction( - 0, - "invoke-static { p$listItemIndexParameter }, " + - "$EXTENSION_CLASS_DESCRIPTOR->userChangedQuality(I)V", - ) - } ?: throw PatchException("Failed to find onItemClick method") + addInstruction( + 0, + "invoke-static { p$listItemIndexParameter }, " + + "$EXTENSION_CLASS_DESCRIPTOR->userChangedQuality(I)V", + ) + } ?: throw PatchException("Failed to find onItemClick method") // Remember video quality if not using old layout menu. - newVideoQualityChangedMatch.mutableMethod.apply { - val index = newVideoQualityChangedMatch.patternMatch!!.startIndex + newVideoQualityChangedFingerprint.method.apply { + val index = newVideoQualityChangedFingerprint.patternMatch!!.startIndex val qualityRegister = getInstruction(index).registerA addInstruction( diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt index ac499b3b9..1acc3ca74 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/button/PlaybackSpeedButtonPatch.kt @@ -15,8 +15,8 @@ import app.revanced.util.copyResources private val playbackSpeedButtonResourcePatch = resourcePatch { dependsOn(playerControlsResourcePatch) - execute { context -> - context.copyResources( + execute { + copyResources( "speedbutton", ResourceGroup( "drawable", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch.kt index 10da13a47..bd6668993 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/CustomPlaybackSpeedPatch.kt @@ -63,12 +63,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch( addResourcesPatch, ) - val speedArrayGeneratorMatch by speedArrayGeneratorFingerprint() - val speedLimiterMatch by speedLimiterFingerprint() - val getOldPlaybackSpeedsMatch by getOldPlaybackSpeedsFingerprint() - val showOldPlaybackSpeedMenuExtensionMatch by showOldPlaybackSpeedMenuExtensionFingerprint() - - execute { context -> + execute { addResources("youtube", "video.speed.custom.customPlaybackSpeedPatch") PreferenceScreen.VIDEO.addPreferences( @@ -77,7 +72,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch( ) // Replace the speeds float array with custom speeds. - speedArrayGeneratorMatch.mutableMethod.apply { + speedArrayGeneratorFingerprint.method.apply { val sizeCallIndex = indexOfFirstInstructionOrThrow { getReference()?.name == "size" } val sizeCallResultRegister = getInstruction(sizeCallIndex + 1).registerA @@ -109,7 +104,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch( } // Override the min/max speeds that can be used. - speedLimiterMatch.mutableMethod.apply { + speedLimiterFingerprint.method.apply { val limitMinIndex = indexOfFirstLiteralInstructionOrThrow(0.25f.toRawBits().toLong()) var limitMaxIndex = indexOfFirstLiteralInstruction(2.0f.toRawBits().toLong()) // Newer targets have 4x max speed. @@ -126,30 +121,30 @@ internal val customPlaybackSpeedPatch = bytecodePatch( // Add a static INSTANCE field to the class. // This is later used to call "showOldPlaybackSpeedMenu" on the instance. + val instanceField = ImmutableField( - getOldPlaybackSpeedsMatch.classDef.type, + getOldPlaybackSpeedsFingerprint.originalClassDef.type, "INSTANCE", - getOldPlaybackSpeedsMatch.classDef.type, + getOldPlaybackSpeedsFingerprint.originalClassDef.type, AccessFlags.PUBLIC.value or AccessFlags.STATIC.value, null, null, null, ).toMutable() - getOldPlaybackSpeedsMatch.mutableClass.staticFields.add(instanceField) + getOldPlaybackSpeedsFingerprint.classDef.staticFields.add(instanceField) // Set the INSTANCE field to the instance of the class. // In order to prevent a conflict with another patch, add the instruction at index 1. - getOldPlaybackSpeedsMatch.mutableMethod.addInstruction(1, "sput-object p0, $instanceField") + getOldPlaybackSpeedsFingerprint.method.addInstruction(1, "sput-object p0, $instanceField") // Get the "showOldPlaybackSpeedMenu" method. // This is later called on the field INSTANCE. - val showOldPlaybackSpeedMenuMethod = showOldPlaybackSpeedMenuFingerprint.applyMatch( - context, - getOldPlaybackSpeedsMatch, + val showOldPlaybackSpeedMenuMethod = showOldPlaybackSpeedMenuFingerprint.match( + getOldPlaybackSpeedsFingerprint.classDef, ).method.toString() // Insert the call to the "showOldPlaybackSpeedMenu" method on the field INSTANCE. - showOldPlaybackSpeedMenuExtensionMatch.mutableMethod.apply { + showOldPlaybackSpeedMenuExtensionFingerprint.method.apply { addInstructionsWithLabels( instructions.lastIndex, """ diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/remember/RememberPlaybackSpeedPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/remember/RememberPlaybackSpeedPatch.kt index accc2498e..3c51559ea 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/remember/RememberPlaybackSpeedPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/remember/RememberPlaybackSpeedPatch.kt @@ -27,8 +27,6 @@ internal val rememberPlaybackSpeedPatch = bytecodePatch { addResourcesPatch, ) - val initializePlaybackSpeedValuesMatch by initializePlaybackSpeedValuesFingerprint() - execute { addResources("youtube", "video.speed.remember.rememberPlaybackSpeedPatch") @@ -52,7 +50,7 @@ internal val rememberPlaybackSpeedPatch = bytecodePatch { /* * Hook the code that is called when the playback speeds are initialized, and sets the playback speed */ - initializePlaybackSpeedValuesMatch.mutableMethod.apply { + initializePlaybackSpeedValuesFingerprint.method.apply { // Infer everything necessary for calling the method setPlaybackSpeed(). val onItemClickListenerClassFieldReference = getInstruction(0).reference diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt index 35d95d8da..6d69381cd 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoid/VideoIdPatch.kt @@ -9,7 +9,6 @@ import app.revanced.patches.youtube.misc.playertype.playerTypeHookPatch import app.revanced.patches.youtube.video.playerresponse.Hook import app.revanced.patches.youtube.video.playerresponse.addPlayerResponseMethodHook import app.revanced.patches.youtube.video.playerresponse.playerResponseMethodHookPatch -import app.revanced.util.applyMatch import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstruction import com.android.tools.smali.dexlib2.iface.Method @@ -96,18 +95,15 @@ val videoIdPatch = bytecodePatch( playerResponseMethodHookPatch, ) - val videoIdParentMatch by videoIdParentFingerprint() - val videoIdBackgroundPlayMatch by videoIdBackgroundPlayFingerprint() - - execute { context -> - videoIdFingerprint.applyMatch(context, videoIdParentMatch).mutableMethod.apply { + execute { + videoIdFingerprint.match(videoIdParentFingerprint.originalClassDef).method.apply { videoIdMethod = this val index = indexOfPlayerResponseModelString() videoIdRegister = getInstruction(index + 1).registerA videoIdInsertIndex = index + 2 } - videoIdBackgroundPlayMatch.mutableMethod.apply { + videoIdBackgroundPlayFingerprint.method.apply { backgroundPlaybackMethod = this val index = indexOfPlayerResponseModelString() backgroundPlaybackVideoIdRegister = getInstruction(index + 1).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuPatch.kt index 6e4e47a01..886db27df 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/videoqualitymenu/RestoreOldVideoQualityMenuPatch.kt @@ -83,16 +83,13 @@ val restoreOldVideoQualityMenuPatch = bytecodePatch( ), ) - val videoQualityMenuViewInflateMatch by videoQualityMenuViewInflateFingerprint() - val videoQualityMenuOptionsMatch by videoQualityMenuOptionsFingerprint() - execute { // region Patch for the old type of the video quality menu. // Used for regular videos when spoofing to old app version, // and for the Shorts quality flyout on newer app versions. - videoQualityMenuViewInflateMatch.mutableMethod.apply { - val checkCastIndex = videoQualityMenuViewInflateMatch.patternMatch!!.endIndex + videoQualityMenuViewInflateFingerprint.method.apply { + val checkCastIndex = videoQualityMenuViewInflateFingerprint.patternMatch!!.endIndex val listViewRegister = getInstruction(checkCastIndex).registerA addInstruction( @@ -104,12 +101,12 @@ val restoreOldVideoQualityMenuPatch = bytecodePatch( } // Force YT to add the 'advanced' quality menu for Shorts. - val patternMatch = videoQualityMenuOptionsMatch.patternMatch!! + val patternMatch = videoQualityMenuOptionsFingerprint.patternMatch!! val startIndex = patternMatch.startIndex if (startIndex != 0) throw PatchException("Unexpected opcode start index: $startIndex") val insertIndex = patternMatch.endIndex - videoQualityMenuOptionsMatch.mutableMethod.apply { + videoQualityMenuOptionsFingerprint.method.apply { val register = getInstruction(insertIndex).registerA // A condition controls whether to show the three or four items quality menu. diff --git a/patches/src/main/kotlin/app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPatch.kt b/patches/src/main/kotlin/app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPatch.kt index 6ca1d5e57..c6689540d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/yuka/misc/unlockpremium/UnlockPremiumPatch.kt @@ -2,7 +2,6 @@ package app.revanced.patches.yuka.misc.unlockpremium import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.patch.bytecodePatch -import app.revanced.util.matchOrThrow @Suppress("unused") val unlockPremiumPatch = bytecodePatch( @@ -10,12 +9,10 @@ val unlockPremiumPatch = bytecodePatch( ) { compatibleWith("io.yuka.android"("4.29")) - val yukaUserConstructorMatch by yukaUserConstructorFingerprint() - - execute { context -> - isPremiumFingerprint.apply { - match(context, yukaUserConstructorMatch.classDef) - }.matchOrThrow.mutableMethod.addInstructions( + execute { + isPremiumFingerprint.match( + yukaUserConstructorFingerprint.originalClassDef, + ).method.addInstructions( 0, """ const/4 v0, 0x1 diff --git a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index b00fb8f1d..db7d2664b 100644 --- a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -1,8 +1,6 @@ package app.revanced.util -import app.revanced.patcher.Fingerprint import app.revanced.patcher.FingerprintBuilder -import app.revanced.patcher.Match import app.revanced.patcher.extensions.InstructionExtensions.addInstruction import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.addInstructionsWithLabels @@ -24,17 +22,6 @@ import com.android.tools.smali.dexlib2.iface.instruction.WideLiteralInstruction import com.android.tools.smali.dexlib2.iface.reference.Reference import com.android.tools.smali.dexlib2.util.MethodUtil -val Fingerprint.matchOrThrow - get() = match ?: throw exception - -/** - * The [PatchException] of failing to match a [Fingerprint]. - * - * @return The [PatchException]. - */ -val Fingerprint.exception - get() = PatchException("Failed to match the fingerprint: $this") - /** * Find the [MutableMethod] from a given [Method] in a [MutableClass]. * @@ -358,13 +345,11 @@ fun Method.indexOfFirstInstructionReversedOrThrow(startIndex: Int? = null, filte * _Returns an empty list if no indices are found_ * @see findInstructionIndicesReversedOrThrow */ -fun Method.findInstructionIndicesReversed(filter: Instruction.() -> Boolean): List { - return instructions - .withIndex() - .filter { (_, instruction) -> filter(instruction) } - .map { (index, _) -> index } - .asReversed() -} +fun Method.findInstructionIndicesReversed(filter: Instruction.() -> Boolean): List = instructions + .withIndex() + .filter { (_, instruction) -> filter(instruction) } + .map { (index, _) -> index } + .asReversed() /** * @return An immutable list of indices of the instructions in reverse order. @@ -417,12 +402,6 @@ fun BytecodePatchContext.forEachLiteralValueInstruction( } } -/** - * Return the matched method early. - */ -fun Fingerprint.returnEarly(bool: Boolean = false) = - matchOrThrow.mutableMethod. returnEarly(bool) - /** * Return the method early. */ @@ -435,31 +414,20 @@ fun MutableMethod.returnEarly(bool: Boolean = false) { const/4 v0, $const return-object v0 """ + 'V' -> "return-void" 'I', 'Z' -> """ const/4 v0, $const return v0 """ + else -> throw Exception("This case should never happen.") } addInstructions(0, stringInstructions) } -/** - * Return the matched methods early. - */ -fun Iterable.returnEarly(bool: Boolean = false) = forEach { fingerprint -> - fingerprint.returnEarly(bool) -} - -/** - * Matches this fingerprint using the classDef of a parent fingerprint match. - */ -fun Fingerprint.applyMatch(context: BytecodePatchContext, parentMatch: Match) = - apply { match(context, parentMatch.classDef) }.matchOrThrow - /** * Set the custom condition for this fingerprint to check for a literal value. * diff --git a/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt b/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt index 02671bbd4..3faf55a8f 100644 --- a/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/ResourceUtils.kt @@ -1,7 +1,7 @@ package app.revanced.util -import app.revanced.patcher.patch.ResourcePatchContext import app.revanced.patcher.patch.PatchException +import app.revanced.patcher.patch.ResourcePatchContext import app.revanced.patcher.util.Document import app.revanced.util.resource.BaseResource import org.w3c.dom.Attr @@ -23,7 +23,8 @@ fun NodeList.asSequence() = (0 until this.length).asSequence().map { this.item(i * Returns a sequence for all child nodes. */ @Suppress("UNCHECKED_CAST") -fun Node.childElementsSequence() = this.childNodes.asSequence().filter { it.nodeType == Node.ELEMENT_NODE } as Sequence +fun Node.childElementsSequence() = + this.childNodes.asSequence().filter { it.nodeType == Node.ELEMENT_NODE } as Sequence /** * Performs the given [action] on each child element. @@ -97,7 +98,7 @@ fun ResourcePatchContext.iterateXmlNodeChildren( resource: String, targetTag: String, callback: (node: Node) -> Unit, -) = document[classLoader.getResourceAsStream(resource)!!].use { document -> +) = document(classLoader.getResourceAsStream(resource)!!).use { document -> val stringsNode = document.getElementsByTagName(targetTag).item(0).childNodes for (i in 1 until stringsNode.length - 1) callback(stringsNode.item(i)) } @@ -164,9 +165,8 @@ internal fun NodeList.findElementByAttributeValue(attributeName: String, value: return null } -internal fun NodeList.findElementByAttributeValueOrThrow(attributeName: String, value: String): Element { - return findElementByAttributeValue(attributeName, value) ?: throw PatchException("Could not find: $attributeName $value") -} +internal fun NodeList.findElementByAttributeValueOrThrow(attributeName: String, value: String) = + findElementByAttributeValue(attributeName, value) ?: throw PatchException("Could not find: $attributeName $value") internal fun Element.copyAttributesFrom(oldContainer: Element) { // Copy attributes from the old element to the new element diff --git a/patches/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt b/patches/src/main/kotlin/app/revanced/util/microg/MicroGBytecodeHelper.kt deleted file mode 100644 index e69de29bb..000000000 diff --git a/patches/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt b/patches/src/main/kotlin/app/revanced/util/microg/MicroGResourceHelper.kt deleted file mode 100644 index e69de29bb..000000000