From 03c7e353a7091aef15ccd87ddbfe5d55e8dd0e9e Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Wed, 28 Jan 2026 14:14:10 +0100 Subject: [PATCH] progres --- .../interaction/speed/PlaybackSpeedPatch.kt | 5 +-- .../tiktok/misc/settings/Fingerprints.kt | 4 +-- .../tiktok/misc/spoof/sim/SpoofSimPatch.kt | 30 ++++++++-------- .../tudortmund/lockscreen/Fingerprints.kt | 2 +- .../youtube/ad/general/Fingerprints.kt | 8 ++--- .../patches/youtube/ad/video/Fingerprints.kt | 4 +-- .../interaction/downloads/Fingerprints.kt | 2 +- .../swipecontrols/SwipeControlsPatch.kt | 1 + .../layout/autocaptions/AutoCaptionsPatch.kt | 4 +-- .../layout/autocaptions/Fingerprints.kt | 6 ++-- .../layout/branding/CustomBrandingPatch.kt | 10 +++--- .../fullscreenambientmode/Fingerprints.kt | 2 +- .../hide/relatedvideooverlay/Fingerprints.kt | 9 +++-- .../HideRelatedVideoOverlayPatch.kt | 28 +++++++-------- .../layout/hide/shorts/Fingerprints.kt | 24 +++++-------- .../hide/shorts/HideShortsComponentsPatch.kt | 31 ++++++++-------- .../hide/signintotvpopup/Fingerprints.kt | 11 ++---- .../youtube/layout/hide/time/Fingerprints.kt | 2 +- .../youtube/layout/searchbar/Fingerprints.kt | 3 +- .../layout/searchbar/WideSearchbarPatch.kt | 36 +++++++++---------- .../youtube/layout/seekbar/Fingerprints.kt | 2 +- .../shortsautoplay/ShortsAutoplayPatch.kt | 4 +-- .../layout/startupshortsreset/Fingerprints.kt | 4 +-- .../kotlin/app/revanced/util/BytecodeUtils.kt | 17 ++------- 24 files changed, 109 insertions(+), 140 deletions(-) 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 c971796fc..237ed7c42 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 @@ -4,6 +4,7 @@ import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.firstMutableClassDef import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patches.tiktok.shared.getEnterFromMethod import app.revanced.patches.tiktok.shared.onRenderFirstFrameMethod @@ -43,7 +44,7 @@ val `Playback speed` by creatingBytecodePatch( """ # 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 }, ${getEnterFromMethod.immutableMethod} + invoke-virtual { p0, v0 }, $getEnterFromMethod move-result-object v0 # Model of current video retrieved using getCurrentAweme method. @@ -53,7 +54,7 @@ val `Playback speed` by creatingBytecodePatch( # 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 }, $setSpeedMethod + invoke-static { v0, v1, v2 }, ${setSpeedMethod.definingClass}->${setSpeedMethod.name}(Ljava/lang/String;Lcom/ss/android/ugc/aweme/feed/model/Aweme;F)V """, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/Fingerprints.kt index 8202cd524..a7a63a235 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tiktok/misc/settings/Fingerprints.kt @@ -19,7 +19,7 @@ internal val BytecodePatchContext.settingsEntryMethod by gettingFirstMethodDecla internal val BytecodePatchContext.settingsEntryInfoMethod by gettingFirstMethod("ExposeItem(title=", ", icon=") -internal val BytecodePatchContext.settingsStatusLoadMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.settingsStatusLoadMethod by gettingFirstMutableMethodDeclaratively { name("load") - definingClass { endsWith("Lapp/revanced/extension/tiktok/settings/SettingsStatus;") } + definingClass("Lapp/revanced/extension/tiktok/settings/SettingsStatus;") } 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 76f789510..65cab18b0 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 @@ -3,11 +3,11 @@ package app.revanced.patches.tiktok.misc.spoof.sim import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.firstMutableMethod import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patches.tiktok.misc.extension.sharedExtensionPatch import app.revanced.patches.tiktok.misc.settings.Settings import app.revanced.patches.tiktok.misc.settings.settingsStatusLoadMethod -import app.revanced.util.findMutableMethodOf import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction import com.android.tools.smali.dexlib2.iface.instruction.formats.Instruction35c @@ -68,23 +68,21 @@ val `SIM spoof` by creatingBytecodePatch( } } }.forEach { (classDef, methods) -> - with(classDef.getOrReplaceMutable()) { - methods.forEach { (method, patches) -> - with(findMutableMethodOf(method)) { - while (!patches.isEmpty()) { - val (index, replacement) = patches.removeLast() + methods.forEach { (method, patches) -> + with(classDef.firstMutableMethod(method)) { + while (!patches.isEmpty()) { + val (index, replacement) = patches.removeLast() - val resultReg = getInstruction(index + 1).registerA + val resultReg = getInstruction(index + 1).registerA - // Patch Android API and return fake sim information. - addInstructions( - index + 2, - """ - invoke-static {v$resultReg}, Lapp/revanced/extension/tiktok/spoof/sim/SpoofSimPatch;->$replacement(Ljava/lang/String;)Ljava/lang/String; - move-result-object v$resultReg - """, - ) - } + // Patch Android API and return fake sim information. + addInstructions( + index + 2, + """ + invoke-static {v$resultReg}, Lapp/revanced/extension/tiktok/spoof/sim/SpoofSimPatch;->$replacement(Ljava/lang/String;)Ljava/lang/String; + move-result-object v$resultReg + """, + ) } } } diff --git a/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/Fingerprints.kt index 82e34c48b..bc2868652 100644 --- a/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/tudortmund/lockscreen/Fingerprints.kt @@ -4,7 +4,7 @@ import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags -internal val BytecodePatchContext.brightnessMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.brightnessMethod by gettingFirstMutableMethodDeclaratively { name("run") definingClass { contains("/ScreenPlugin$") } accessFlags(AccessFlags.PUBLIC) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/Fingerprints.kt index 7313117c2..55c81b0ed 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/general/Fingerprints.kt @@ -1,11 +1,7 @@ package app.revanced.patches.youtube.ad.general -import app.revanced.patcher.accessFlags -import app.revanced.patcher.custom -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.parameterTypes +import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType import app.revanced.util.containsLiteralInstruction import app.revanced.util.getReference import app.revanced.util.indexOfFirstInstructionReversed @@ -13,7 +9,7 @@ import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.iface.Method import com.android.tools.smali.dexlib2.iface.reference.MethodReference -internal val BytecodePatchContext.fullScreenEngagementAdContainerMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.fullScreenEngagementAdContainerMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes() diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/Fingerprints.kt index dacd065a9..ed491a205 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/ad/video/Fingerprints.kt @@ -1,9 +1,9 @@ package app.revanced.patches.youtube.ad.video -import app.revanced.patcher.gettingFirstMethod +import app.revanced.patcher.gettingFirstMutableMethodDeclaratively import app.revanced.patcher.patch.BytecodePatchContext -internal val BytecodePatchContext.loadVideoAdsMethod by gettingFirstMethod( +internal val BytecodePatchContext.loadVideoAdsMethod by gettingFirstMutableMethodDeclaratively( "TriggerBundle doesn't have the required metadata specified by the trigger ", "Ping migration no associated ping bindings for activated trigger: ", ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/Fingerprints.kt index 1eac7848a..ecaa4bdd3 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/downloads/Fingerprints.kt @@ -4,7 +4,7 @@ import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags -internal val BytecodePatchContext.offlineVideoEndpointMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.offlineVideoEndpointMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes( 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 1700af293..881c0eec5 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 @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.interaction.swipecontrols +import app.revanced.patcher.classDef import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patcher.patch.resourcePatch import app.revanced.patches.all.misc.resources.addResources 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 3bf3f340f..355cd56a1 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 @@ -54,8 +54,8 @@ val `Disable auto captions` by creatingBytecodePatch( arrayOf( startVideoInformerMethod to 0, storyboardRendererDecoderRecommendedLevelMethod to 1, - ).forEach { (fingerprint, enabled) -> - fingerprint.method.addInstructions( + ).forEach { (method, enabled) -> + method.addInstructions( 0, """ const/4 v0, 0x$enabled diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/Fingerprints.kt index 2272ed39c..a7c2aa5a7 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/autocaptions/Fingerprints.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.startVideoInformerMethod by gettingFirstMethodDeclaratively("pc") { +internal val BytecodePatchContext.startVideoInformerMethod by gettingFirstMutableMethodDeclaratively("pc") { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") opcodes( @@ -14,13 +14,13 @@ internal val BytecodePatchContext.startVideoInformerMethod by gettingFirstMethod ) } -internal val BytecodePatchContext.storyboardRendererDecoderRecommendedLevelMethod by gettingFirstMethodDeclaratively("#-1#") { +internal val BytecodePatchContext.storyboardRendererDecoderRecommendedLevelMethod by gettingFirstMutableMethodDeclaratively("#-1#") { returnType("V") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) parameterTypes("L") } -internal val BytecodePatchContext.subtitleTrackMethod by gettingFirstMethodDeclaratively("DISABLE_CAPTIONS_OPTION") { +internal val BytecodePatchContext.subtitleTrackMethod by gettingFirstMutableMethodDeclaratively("DISABLE_CAPTIONS_OPTION") { definingClass { endsWith("/SubtitleTrack;") } accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("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 eef223b73..3859ce093 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 @@ -1,10 +1,12 @@ package app.revanced.patches.youtube.layout.branding +import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patches.shared.layout.branding.baseCustomBrandingPatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_MAIN_ACTIVITY_NAME import app.revanced.patches.youtube.misc.gms.Constants.YOUTUBE_PACKAGE_NAME import app.revanced.patches.youtube.misc.settings.PreferenceScreen +import app.revanced.patches.youtube.shared.mainActivityOnCreateMethod @Suppress("unused") val customBrandingPatch = baseCustomBrandingPatch( @@ -14,9 +16,9 @@ val customBrandingPatch = baseCustomBrandingPatch( originalAppPackageName = YOUTUBE_PACKAGE_NAME, isYouTubeMusic = false, numberOfPresetAppNames = 5, - getMainActivityOnCreate = mainActivityOnCreateFingerprint, + getMainActivityOnCreate = BytecodePatchContext::mainActivityOnCreateMethod::get, mainActivityName = YOUTUBE_MAIN_ACTIVITY_NAME, - activityAliasNameWithIntents = "com.google.android.youtube.app.honeycomb.Shell\$HomeActivity", + activityAliasNameWithIntents = $$"com.google.android.youtube.app.honeycomb.Shell$HomeActivity", preferenceScreen = PreferenceScreen.GENERAL_LAYOUT, block = { @@ -28,7 +30,7 @@ val customBrandingPatch = baseCustomBrandingPatch( "20.14.43", "20.21.37", "20.31.40", - ) + ), ) - } + }, ) diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/Fingerprints.kt index cf6183f22..c2a1afa6d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/fullscreenambientmode/Fingerprints.kt @@ -4,7 +4,7 @@ import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags -internal val BytecodePatchContext.setFullScreenBackgroundColorMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.setFullScreenBackgroundColorMethod by gettingFirstMutableMethodDeclaratively { name("onLayout") definingClass { endsWith("/YouTubePlayerViewNotForReflection;") } returnType("V") diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/Fingerprints.kt index a684ea5cc..0399d731d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/Fingerprints.kt @@ -1,11 +1,9 @@ package app.revanced.patches.youtube.layout.hide.relatedvideooverlay -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.instructions -import app.revanced.patcher.parameterTypes +import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType import app.revanced.patches.shared.misc.mapping.ResourceType +import com.android.tools.smali.dexlib2.iface.ClassDef internal val BytecodePatchContext.relatedEndScreenResultsParentMethod by gettingFirstMethodDeclaratively { returnType("V") @@ -14,7 +12,8 @@ internal val BytecodePatchContext.relatedEndScreenResultsParentMethod by getting ) } -internal val BytecodePatchContext.relatedEndScreenResultsMethod by gettingFirstMethodDeclaratively { +context(_: BytecodePatchContext) +internal fun ClassDef.getRelatedEndScreenResultsMethod() = firstMutableMethodDeclaratively { returnType("V") parameterTypes( "I", diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/HideRelatedVideoOverlayPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/HideRelatedVideoOverlayPatch.kt index 05241188a..95e1837a4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/HideRelatedVideoOverlayPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/relatedvideooverlay/HideRelatedVideoOverlayPatch.kt @@ -3,6 +3,7 @@ package app.revanced.patches.youtube.layout.hide.relatedvideooverlay import app.revanced.patcher.extensions.ExternalLabel import app.revanced.patcher.extensions.addInstructionsWithLabels import app.revanced.patcher.extensions.getInstruction +import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patches.all.misc.resources.addResources import app.revanced.patches.all.misc.resources.addResourcesPatch @@ -42,19 +43,18 @@ val `Hide related video overlay` by creatingBytecodePatch( SwitchPreference("revanced_hide_related_videos_overlay"), ) - relatedEndScreenResultsMethod.match( - relatedEndScreenResultsParentMethod.immutableClassDef, - ).method.apply { - addInstructionsWithLabels( - 0, - """ - invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideRelatedVideoOverlay()Z - move-result v0 - if-eqz v0, :show - return-void - """, - ExternalLabel("show", getInstruction(0)), - ) - } + val relatedEndScreenResultsMethod = + relatedEndScreenResultsParentMethod.immutableClassDef.getRelatedEndScreenResultsMethod() + + relatedEndScreenResultsMethod.addInstructionsWithLabels( + 0, + """ + invoke-static {}, $EXTENSION_CLASS_DESCRIPTOR->hideRelatedVideoOverlay()Z + move-result v0 + if-eqz v0, :show + return-void + """, + ExternalLabel("show", relatedEndScreenResultsMethod.getInstruction(0)), + ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/Fingerprints.kt index 6f1fc1d95..9ef8624f1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/shorts/Fingerprints.kt @@ -1,20 +1,13 @@ package app.revanced.patches.youtube.layout.hide.shorts -import app.revanced.patcher.accessFlags -import app.revanced.patcher.after -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.instructions -import app.revanced.patcher.invoke -import app.revanced.patcher.method -import app.revanced.patcher.opcodes -import app.revanced.patcher.parameterTypes +import app.revanced.patcher.* import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType import app.revanced.patches.shared.misc.mapping.ResourceType import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.ClassDef -internal val BytecodePatchContext.shortsBottomBarContainerMethod by gettingFirstMethodDeclaratively { +internal val shortsBottomBarContainerMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes("Landroid/view/View;", "Landroid/os/Bundle;") @@ -29,7 +22,9 @@ internal val BytecodePatchContext.shortsBottomBarContainerMethod by gettingFirst /** * 19.41 to 20.44. */ -internal val BytecodePatchContext.renderBottomNavigationBarMethod by gettingFirstMethodDeclaratively { + +context(_: BytecodePatchContext) +internal fun ClassDef.getRenderBottomNavigationBarMethodMatch() = firstMutableMethodDeclaratively { returnType("V") parameterTypes("Ljava/lang/String;") instructions( @@ -38,7 +33,6 @@ internal val BytecodePatchContext.renderBottomNavigationBarMethod by gettingFirs after(Opcode.IGET_OBJECT()), after(Opcode.IF_EQZ()), after(Opcode.INVOKE_INTERFACE()), - Opcode.MONITOR_EXIT(), after(Opcode.RETURN_VOID()), after(Opcode.MOVE_EXCEPTION()), @@ -97,7 +91,7 @@ internal val BytecodePatchContext.renderBottomNavigationBarParentMethod by getti ) } -internal val BytecodePatchContext.setPivotBarVisibilityMethod by gettingFirstMethodDeclaratively { +internal val setPivotBarVisibilityMethodMatch = firstMethodComposite { accessFlags(AccessFlags.PRIVATE, AccessFlags.FINAL) returnType("V") parameterTypes("Z") @@ -114,7 +108,7 @@ internal val BytecodePatchContext.setPivotBarVisibilityParentMethod by gettingFi ) } -internal val BytecodePatchContext.shortsExperimentalPlayerFeatureFlagMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.shortsExperimentalPlayerFeatureFlagMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Z") parameterTypes() @@ -123,7 +117,7 @@ internal val BytecodePatchContext.shortsExperimentalPlayerFeatureFlagMethod by g ) } -internal val BytecodePatchContext.renderNextUIFeatureFlagMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.renderNextUIFeatureFlagMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Z") parameterTypes() 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 75a42ebe7..abfe6c278 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 @@ -4,6 +4,7 @@ import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.wideLiteral +import app.revanced.patcher.immutableClassDef import app.revanced.patcher.patch.booleanOption import app.revanced.patcher.patch.creatingBytecodePatch import app.revanced.patcher.patch.resourcePatch @@ -209,11 +210,9 @@ val `Hide Shorts components` by creatingBytecodePatch( // region Hide the navigation bar. // Hook to get the pivotBar view. - setPivotBarVisibilityMethod.match( - setPivotBarVisibilityParentMethod.immutableClassDef, - ).let { result -> - result.method.apply { - val insertIndex = result.indices.last() + setPivotBarVisibilityMethodMatch.match(setPivotBarVisibilityParentMethod.immutableClassDef).let { match -> + match.method.apply { + val insertIndex = match.indices.last() val viewRegister = getInstruction(insertIndex - 1).registerA addInstruction( insertIndex, @@ -224,23 +223,21 @@ val `Hide Shorts components` by creatingBytecodePatch( } // Hook to hide the shared navigation bar when the Shorts player is opened. - renderBottomNavigationBarMethod.match( - ( - if (is_20_45_or_greater) { - renderBottomNavigationBarParentMethod - } else if (is_19_41_or_greater) { - renderBottomNavigationBarLegacy1941ParentMethod - } else { - legacyRenderBottomNavigationBarLegacyParentMethod - } - ).immutableClassDef, - ).method.addInstruction( + ( + if (is_20_45_or_greater) { + renderBottomNavigationBarParentMethod + } else if (is_19_41_or_greater) { + renderBottomNavigationBarLegacy1941ParentMethod + } else { + legacyRenderBottomNavigationBarLegacyParentMethod + } + ).immutableClassDef.getRenderBottomNavigationBarMethodMatch().addInstruction( 0, "invoke-static { p1 }, $FILTER_CLASS_DESCRIPTOR->hideNavigationBar(Ljava/lang/String;)V", ) // Hide the bottom bar container of the Shorts player. - shortsBottomBarContainerMethod.let { + shortsBottomBarContainerMethodMatch.let { it.method.apply { val targetIndex = it.indices.last() val heightRegister = getInstruction(targetIndex).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/signintotvpopup/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/signintotvpopup/Fingerprints.kt index 9411df70a..9f32afd3e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/signintotvpopup/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/signintotvpopup/Fingerprints.kt @@ -1,19 +1,14 @@ package app.revanced.patches.youtube.layout.hide.signintotvpopup -import app.revanced.patcher.gettingFirstMethodDeclaratively +import app.revanced.patcher.gettingFirstMutableMethodDeclaratively import app.revanced.patcher.instructions import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.returnType import app.revanced.patches.shared.misc.mapping.ResourceType -internal val BytecodePatchContext.signInToTvPopupMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.signInToTvPopupMethod by gettingFirstMutableMethodDeclaratively { returnType("Z") parameterTypes("Ljava/lang/String;", "Z", "L") - instructions( - resourceLiteral( - ResourceType.STRING, - "mdx_seamless_tv_sign_in_drawer_fragment_title", - ), - ) + instructions(ResourceType.STRING("mdx_seamless_tv_sign_in_drawer_fragment_title")) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/Fingerprints.kt index f641db414..85d99bc19 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/time/Fingerprints.kt @@ -5,7 +5,7 @@ import app.revanced.patcher.patch.BytecodePatchContext import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode -internal val BytecodePatchContext.timeCounterMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.timeCounterMethod by gettingFirstMutableMethodDeclaratively { returnType("V") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) parameterTypes() diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/Fingerprints.kt index 22ebfcb0d..a69824ae8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/searchbar/Fingerprints.kt @@ -2,6 +2,7 @@ package app.revanced.patches.youtube.layout.searchbar import app.revanced.patcher.accessFlags import app.revanced.patcher.gettingFirstMethodDeclaratively +import app.revanced.patcher.gettingFirstMutableMethodDeclaratively import app.revanced.patcher.instructions import app.revanced.patcher.parameterTypes import app.revanced.patcher.patch.BytecodePatchContext @@ -23,7 +24,7 @@ internal val BytecodePatchContext.setWordmarkHeaderMethod by gettingFirstMethodD /** * Matches the same method as [yoodlesImageViewMethod]. */ -internal val BytecodePatchContext.wideSearchbarLayoutMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.wideSearchbarLayoutMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Landroid/view/View;") parameterTypes("L", "L") 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 6bf0f32a4..8aa6ae2c1 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 @@ -62,28 +62,26 @@ val `Wide search bar` by creatingBytecodePatch( SwitchPreference("revanced_wide_searchbar"), ) - setWordmarkHeaderMethod.let { - // Navigate to the method that checks if the YT logo is shown beside the search bar. - val shouldShowLogoMethod = with(it.immutableMethod) { - val invokeStaticIndex = indexOfFirstInstructionOrThrow { - opcode == Opcode.INVOKE_STATIC && - getReference()?.returnType == "Z" - } - navigate(this).to(invokeStaticIndex).stop() + // Navigate to the method that checks if the YT logo is shown beside the search bar. + val shouldShowLogoMethod = with(setWordmarkHeaderMethod) { + val invokeStaticIndex = indexOfFirstInstructionOrThrow { + opcode == Opcode.INVOKE_STATIC && + getReference()?.returnType == "Z" } + navigate(this).to(invokeStaticIndex).stop() + } - shouldShowLogoMethod.apply { - findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index -> - val register = getInstruction(index).registerA + shouldShowLogoMethod.apply { + findInstructionIndicesReversedOrThrow(Opcode.RETURN).forEach { index -> + val register = getInstruction(index).registerA - addInstructionsAtControlFlowLabel( - index, - """ - invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z - move-result v$register - """, - ) - } + addInstructionsAtControlFlowLabel( + index, + """ + invoke-static { v$register }, $EXTENSION_CLASS_DESCRIPTOR->enableWideSearchbar(Z)Z + move-result v$register + """, + ) } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt index 024c66522..46c910abb 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/seekbar/Fingerprints.kt @@ -7,7 +7,7 @@ import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.ClassDef -internal val BytecodePatchContext.fullscreenSeekbarThumbnailsMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.fullscreenSeekbarThumbnailsMethod by gettingFirstMutableMethodDeclaratively { returnType("Z") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) parameterTypes() 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 0f9b9661c..0ee2382a2 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 @@ -116,9 +116,9 @@ val `Shorts autoplay` by creatingBytecodePatch( if (is_20_09_or_greater) { // Variable names are only a rough guess of what these methods do. val userActionMethodReference = - reelPlaybackMethodMatch.method.getInstruction(reelPlaybackMethodMatch.indices[1]).methodReference + reelPlaybackMethodMatch.method.getInstruction(reelPlaybackMethodMatch.indices[1]).methodReference!! val reelSequenceControllerMethodReference = - reelPlaybackMethodMatch.method.getInstruction(reelPlaybackMethodMatch.indices[2]).methodReference + reelPlaybackMethodMatch.method.getInstruction(reelPlaybackMethodMatch.indices[2]).methodReference!! reelPlaybackRepeatMethod.apply { // Find the first call modified by extension code above. diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/Fingerprints.kt index 1d5abef2c..1a8848ce9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/startupshortsreset/Fingerprints.kt @@ -24,7 +24,7 @@ internal val userWasInShortsAlternativeMethodMatch = firstMethodComposite { /** * Pre 20.02 */ -internal val BytecodePatchContext.userWasInShortsLegacyMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.userWasInShortsLegacyMethod by gettingFirstMutableMethodDeclaratively { returnType("V") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) parameterTypes("Ljava/lang/Object;") @@ -36,7 +36,7 @@ internal val BytecodePatchContext.userWasInShortsLegacyMethod by gettingFirstMet /** * 18.15.40+ */ -internal val BytecodePatchContext.userWasInShortsConfigMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.userWasInShortsConfigMethod by gettingFirstMutableMethodDeclaratively { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Z") parameterTypes() diff --git a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index a58b38637..343d16bdb 100644 --- a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -1,10 +1,7 @@ package app.revanced.util -import app.revanced.patcher.MutablePredicateList -import app.revanced.patcher.custom +import app.revanced.patcher.* import app.revanced.patcher.extensions.* -import app.revanced.patcher.firstMutableClassDef -import app.revanced.patcher.firstMutableClassDefOrNull import app.revanced.patcher.patch.BytecodePatchContext import app.revanced.patcher.patch.PatchException import app.revanced.patches.shared.misc.mapping.ResourceType @@ -258,16 +255,6 @@ internal fun Int.toPublicAccessFlags(): Int = this.or(AccessFlags.PUBLIC.value) .and(AccessFlags.PROTECTED.value.inv()) .and(AccessFlags.PRIVATE.value.inv()) -/** - * Find the [MutableMethod] from a given [Method] in a [MutableClass]. - * - * @param method The [Method] to find. - * @return The [MutableMethod]. - */ -fun MutableClassDef.findMutableMethodOf(method: Method) = this.methods.first { - MethodUtil.methodSignaturesMatch(it, method) -} - /** * Apply a transform to all methods of the class. * @@ -805,7 +792,7 @@ fun BytecodePatchContext.forEachInstructionAsSequence( val instructions = method.instructionsOrNull as? List ?: return@flatMap emptySequence<() -> Unit>() - val mutableMethod by lazy { mutableClassDef.findMutableMethodOf(method) } + val mutableMethod by lazy { mutableClassDef.firstMutableMethod(method) } instructions.asReversed().asSequence().mapIndexed { index, instruction -> {