From bae293e3dd249c98fc3abcce34013b547980128b Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Sun, 25 Jan 2026 21:03:07 +0100 Subject: [PATCH] some more migration --- .../fix/user/UseUserEndpointPatch.kt | 7 ++- .../interaction/seekbar/Fingerprints.kt | 57 +++++-------------- .../speed/custom/CustomPlaybackSpeedPatch.kt | 9 ++- .../video/speed/custom/Fingerprints.kt | 6 +- .../kotlin/app/revanced/util/BytecodeUtils.kt | 11 ++-- 5 files changed, 32 insertions(+), 58 deletions(-) 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 15504ee06..376191ba5 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 @@ -3,11 +3,12 @@ package app.revanced.patches.reddit.customclients.sync.syncforreddit.fix.user import app.revanced.patcher.extensions.getInstruction import app.revanced.patcher.extensions.replaceInstruction import app.revanced.patcher.extensions.stringReference -import app.revanced.patcher.patch.creatingBytecodePatch +import app.revanced.patcher.patch.bytecodePatch import com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction -@Suppress("unused", "ObjectPropertyName") -val `Use /user/ endpoint` by creatingBytecodePatch( +@Suppress("unused") +val useUserEndpointPatch = bytecodePatch( + name = "Use /user/ endpoint", description = "Replaces the deprecated endpoint for viewing user profiles /u with /user, that used to fix a bug.", use = false, diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt index bc5b34e07..0d24c3ae3 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/interaction/seekbar/Fingerprints.kt @@ -1,36 +1,15 @@ package app.revanced.patches.youtube.interaction.seekbar -import app.revanced.patcher.accessFlags -import app.revanced.patcher.after -import app.revanced.patcher.afterAtMost -import app.revanced.patcher.allOf -import app.revanced.patcher.custom -import app.revanced.patcher.field -import app.revanced.patcher.firstMethodComposite -import app.revanced.patcher.firstMutableMethodDeclaratively -import app.revanced.patcher.gettingFirstMethodDeclaratively -import app.revanced.patcher.gettingFirstMutableMethodDeclaratively -import app.revanced.patcher.instructions -import app.revanced.patcher.invoke -import app.revanced.patcher.method -import app.revanced.patcher.name -import app.revanced.patcher.opcodes -import app.revanced.patcher.parameterTypes +import app.revanced.patcher.* +import app.revanced.patcher.extensions.instructions +import app.revanced.patcher.extensions.stringReference import app.revanced.patcher.patch.BytecodePatchContext -import app.revanced.patcher.returnType -import app.revanced.patcher.type -import app.revanced.patches.youtube.misc.playservice.is_19_34_or_greater -import app.revanced.patches.youtube.misc.playservice.is_19_47_or_greater -import app.revanced.patches.youtube.misc.playservice.is_20_19_or_greater -import app.revanced.patches.youtube.misc.playservice.is_20_20_or_greater -import app.revanced.patches.youtube.misc.playservice.is_20_31_or_greater -import app.revanced.util.getReference +import app.revanced.patches.youtube.misc.playservice.* import app.revanced.util.indexOfFirstInstruction import app.revanced.util.literal import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode import com.android.tools.smali.dexlib2.iface.ClassDef -import com.android.tools.smali.dexlib2.iface.reference.StringReference internal val BytecodePatchContext.swipingUpGestureParentMethod by gettingFirstMethodDeclaratively { returnType("Z") @@ -70,6 +49,7 @@ internal val BytecodePatchContext.disableFastForwardLegacyMethod by gettingFirst } internal val BytecodePatchContext.disableFastForwardGestureMethod by gettingFirstMethodDeclaratively { + definingClass { endsWith("/NextGenWatchLayout;") } accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("Z") parameterTypes() @@ -78,26 +58,22 @@ internal val BytecodePatchContext.disableFastForwardGestureMethod by gettingFirs Opcode.INVOKE_VIRTUAL, Opcode.MOVE_RESULT, ) - custom { methodDef, classDef -> - methodDef.implementation!!.instructions.count() > 30 && - classDef.type.endsWith("/NextGenWatchLayout;") - } + custom { instructions.count() > 30 } } -internal val BytecodePatchContext.customTapAndHoldMethod by gettingFirstMethodDeclaratively { +internal val customTapAndHoldMethodMatch = firstMethodComposite { + name("run") accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returnType("V") parameterTypes() - instructions( - 2.0f(), - ) - custom { method, _ -> + instructions(2.0f.toRawBits().toLong()()) + custom { // Code is found in different methods with different strings. val findSearchLandingKey = (is_19_34_or_greater && !is_19_47_or_greater) || (is_20_19_or_greater && !is_20_20_or_greater) || is_20_31_or_greater - method.name == "run" && method.indexOfFirstInstruction { - val string = getReference()?.string + indexOfFirstInstruction { + val string = stringReference?.string string == "Failed to easy seek haptics vibrate." || (findSearchLandingKey && string == "search_landing_cache_key") } >= 0 @@ -105,6 +81,7 @@ internal val BytecodePatchContext.customTapAndHoldMethod by gettingFirstMethodDe } internal val BytecodePatchContext.onTouchEventHandlerMethod by gettingFirstMethodDeclaratively { + name("onTouchEvent") accessFlags(AccessFlags.PUBLIC, AccessFlags.PUBLIC) returnType("Z") parameterTypes("L") @@ -124,7 +101,6 @@ internal val BytecodePatchContext.onTouchEventHandlerMethod by gettingFirstMetho Opcode.INVOKE_VIRTUAL, Opcode.INVOKE_VIRTUAL, // oMethodReference ) - custom { method, _ -> method.name == "onTouchEvent" } } internal val BytecodePatchContext.seekbarTappingMethod by gettingFirstMethodDeclaratively { @@ -134,12 +110,9 @@ internal val BytecodePatchContext.seekbarTappingMethod by gettingFirstMethodDecl parameterTypes("Landroid/view/MotionEvent;") instructions( Int.MAX_VALUE.toLong()(), - allOf(Opcode.NEW_INSTANCE, type("Landroid/graphics/Point;")), + allOf(Opcode.NEW_INSTANCE(), type("Landroid/graphics/Point;")), after(method { toString() == "Landroid/graphics/Point;->(II)V" }), - methodCall( - smali = "Lj\$/util/Optional;->of(Ljava/lang/Object;)Lj\$/util/Optional;", - after(), - ), + after(method { toString() == "Landroid/view/MotionEvent;->getX()F" }), after(Opcode.MOVE_RESULT_OBJECT()), after(allOf(Opcode.IPUT_OBJECT(), field { type == "Lj\$/util/Optional;" })), afterAtMost(10, Opcode.INVOKE_VIRTUAL()), 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 a5b57c68f..8072fda61 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 @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.video.speed.custom +import app.revanced.patcher.classDef import app.revanced.patcher.extensions.addInstruction import app.revanced.patcher.extensions.addInstructions import app.revanced.patcher.extensions.addInstructionsWithLabels @@ -14,7 +15,7 @@ import app.revanced.patches.shared.misc.mapping.resourceMappingPatch import app.revanced.patches.shared.misc.settings.preference.InputType import app.revanced.patches.shared.misc.settings.preference.SwitchPreference import app.revanced.patches.shared.misc.settings.preference.TextPreference -import app.revanced.patches.youtube.interaction.seekbar.customTapAndHoldMethod +import app.revanced.patches.youtube.interaction.seekbar.customTapAndHoldMethodMatch import app.revanced.patches.youtube.misc.extension.sharedExtensionPatch import app.revanced.patches.youtube.misc.litho.filter.addLithoFilter import app.revanced.patches.youtube.misc.litho.filter.lithoFilterPatch @@ -139,9 +140,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch( // Get the "showOldPlaybackSpeedMenu" method. // This is later called on the field INSTANCE. - val showOldPlaybackSpeedMenuMethod = showOldPlaybackSpeedMenuMethod.match( - getOldPlaybackSpeedsMethod.classDef, - ).method + val showOldPlaybackSpeedMenuMethod = getOldPlaybackSpeedsMethod.classDef.getShowOldPlaybackSpeedMenuMethod() // Insert the call to the "showOldPlaybackSpeedMenu" method on the field INSTANCE. showOldPlaybackSpeedMenuExtensionMethod.apply { @@ -170,7 +169,7 @@ internal val customPlaybackSpeedPatch = bytecodePatch( // region Custom tap and hold 2x speed. if (is_19_47_or_greater) { - customTapAndHoldMethod.let { + customTapAndHoldMethodMatch.let { it.method.apply { val index = it.instructionMatches.first().index val register = getInstruction(index).registerA diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/Fingerprints.kt index 2bc3c472c..43ce7443d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/speed/custom/Fingerprints.kt @@ -5,6 +5,7 @@ import app.revanced.patcher.patch.BytecodePatchContext 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.getOldPlaybackSpeedsMethod by gettingFirstMutableMethodDeclaratively( "menu_item_playback_speed", @@ -12,13 +13,14 @@ internal val BytecodePatchContext.getOldPlaybackSpeedsMethod by gettingFirstMuta parameterTypes("[L", "I") } -internal val BytecodePatchContext.showOldPlaybackSpeedMenuMethod by gettingFirstMethodDeclaratively { +context(_: BytecodePatchContext) +internal fun ClassDef.getShowOldPlaybackSpeedMenuMethod() = firstMutableMethodDeclaratively { instructions( ResourceType.STRING("varispeed_unavailable_message"), ) } -internal val BytecodePatchContext.showOldPlaybackSpeedMenuExtensionMethod by gettingFirstMethodDeclaratively { +internal val BytecodePatchContext.showOldPlaybackSpeedMenuExtensionMethod by gettingFirstMutableMethodDeclaratively { name("showOldPlaybackSpeedMenu") } diff --git a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt index c9f4b20c1..a58b38637 100644 --- a/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt +++ b/patches/src/main/kotlin/app/revanced/util/BytecodeUtils.kt @@ -1,6 +1,7 @@ package app.revanced.util -import app.revanced.patcher.FingerprintBuilder +import app.revanced.patcher.MutablePredicateList +import app.revanced.patcher.custom import app.revanced.patcher.extensions.* import app.revanced.patcher.firstMutableClassDef import app.revanced.patcher.firstMutableClassDefOrNull @@ -1254,11 +1255,9 @@ internal fun BytecodePatchContext.addStaticFieldToExtension( * * @param literalSupplier The supplier for the literal value to check for. */ -@Deprecated("Instead use instruction filters and `literal()`") -fun FingerprintBuilder.literal(literalSupplier: () -> Long) { - custom { method, _ -> - method.containsLiteralInstruction(literalSupplier()) - } +@Deprecated("Instead use `literal()`") +fun MutablePredicateList.literal(literalSupplier: () -> Long) { + custom { containsLiteralInstruction(literalSupplier()) } } private class InstructionUtils {