diff --git a/patches/api/patches.api b/patches/api/patches.api index 5a340ac00..fb9eb716f 100644 --- a/patches/api/patches.api +++ b/patches/api/patches.api @@ -835,8 +835,8 @@ public final class app/revanced/patches/shared/misc/mapping/ResourceMappingPatch public static final fun getResourceId (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;)J public static final fun getResourceMappingPatch ()Lapp/revanced/patcher/patch/ResourcePatch; public static final fun hasResourceId (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;)Z - public static final fun resourceLiteral (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;I)Lapp/revanced/patcher/LiteralFilter; - public static synthetic fun resourceLiteral$default (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;IILjava/lang/Object;)Lapp/revanced/patcher/LiteralFilter; + public static final fun resourceLiteral (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;Lapp/revanced/patcher/InstructionLocation;)Lapp/revanced/patcher/LiteralFilter; + public static synthetic fun resourceLiteral$default (Lapp/revanced/patches/shared/misc/mapping/ResourceType;Ljava/lang/String;Lapp/revanced/patcher/InstructionLocation;ILjava/lang/Object;)Lapp/revanced/patcher/LiteralFilter; } public final class app/revanced/patches/shared/misc/mapping/ResourceType : java/lang/Enum { diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/layout/theme/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/shared/layout/theme/Fingerprints.kt index 692c27b97..af61ed008 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/layout/theme/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/layout/theme/Fingerprints.kt @@ -1,5 +1,7 @@ package app.revanced.patches.shared.layout.theme +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -21,18 +23,18 @@ internal val lithoOnBoundsChangeFingerprint = fingerprint { definingClass = "this", name = "isStateful", returnType = "Z", - maxAfter = 5 + location = MatchAfterWithin(5) ), fieldAccess( opcode = Opcode.IGET_OBJECT, definingClass = "this", type = "Landroid/graphics/Paint", - maxAfter = 5 + location = MatchAfterWithin(5) ), methodCall( smali = "Landroid/graphics/Paint;->setColor(I)V", - maxAfter = 0 + location = MatchAfterImmediately() ) ) custom { method, _ -> 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 bb6aefcd0..16b7f6fcc 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 @@ -1,6 +1,6 @@ package app.revanced.patches.shared.misc.mapping -import app.revanced.patcher.InstructionFilter.Companion.METHOD_MAX_INSTRUCTIONS +import app.revanced.patcher.InstructionLocation import app.revanced.patcher.LiteralFilter import app.revanced.patcher.literal import app.revanced.patcher.patch.PatchException @@ -77,8 +77,8 @@ fun hasResourceId(type: ResourceType, name: String) = resourceMappings[type.valu fun resourceLiteral( type: ResourceType, name: String, - maxBefore: Int = METHOD_MAX_INSTRUCTIONS, -) = literal({ getResourceId(type, name) }, null, maxBefore) + location : InstructionLocation = InstructionLocation.MatchAfterAnywhere() +) = literal({ getResourceId(type, name) }, null, location) val resourceMappingPatch = resourcePatch { diff --git a/patches/src/main/kotlin/app/revanced/patches/shared/misc/privacy/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/shared/misc/privacy/Fingerprints.kt index 832ac7108..aab50cef0 100644 --- a/patches/src/main/kotlin/app/revanced/patches/shared/misc/privacy/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/shared/misc/privacy/Fingerprints.kt @@ -1,5 +1,7 @@ package app.revanced.patches.shared.misc.privacy +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.checkCast import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint @@ -13,15 +15,15 @@ internal val youTubeCopyTextFingerprint = fingerprint { parameters("L", "Ljava/util/Map;") instructions( opcode(Opcode.IGET_OBJECT), - string("text/plain", maxAfter = 2), + string("text/plain", location = MatchAfterWithin(2)), methodCall( smali = "Landroid/content/ClipData;->newPlainText(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Landroid/content/ClipData;", - maxAfter = 2 + location = MatchAfterWithin(2) ), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 2), + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterWithin(2)), methodCall( smali = "Landroid/content/ClipboardManager;->setPrimaryClip(Landroid/content/ClipData;)V", - maxAfter = 2 + location = MatchAfterWithin(2) ) ) } @@ -36,18 +38,18 @@ internal val youTubeSystemShareSheetFingerprint = fingerprint { methodCall( smali = "Ljava/util/List;->iterator()Ljava/util/Iterator;", - maxAfter = 4 + location = MatchAfterWithin(4) ), fieldAccess( opcode = Opcode.IGET_OBJECT, type = "Ljava/lang/String;", - maxAfter = 15 + location = MatchAfterWithin(15) ), methodCall( smali = "Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;", - maxAfter = 15 + location = MatchAfterWithin(15) ) ) } @@ -57,8 +59,8 @@ internal val youTubeShareSheetFingerprint = fingerprint { parameters("L", "Ljava/util/Map;") instructions( opcode(Opcode.IGET_OBJECT), - checkCast("Ljava/lang/String;", maxAfter = 0), - opcode(Opcode.GOTO, maxAfter = 0), + checkCast("Ljava/lang/String;", location = MatchAfterImmediately()), + opcode(Opcode.GOTO, location = MatchAfterImmediately()), methodCall(smali = "Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;"), 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 b80c68b26..39479e114 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,5 +1,7 @@ package app.revanced.patches.youtube.interaction.seekbar +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -121,12 +123,12 @@ internal val seekbarTappingFingerprint = fingerprint { literal(Int.MAX_VALUE), newInstance("Landroid/graphics/Point;"), - methodCall(smali = "Landroid/graphics/Point;->(II)V", maxAfter = 0), - methodCall(smali = "Lj\$/util/Optional;->of(Ljava/lang/Object;)Lj\$/util/Optional;", maxAfter = 0), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0), - fieldAccess(opcode = Opcode.IPUT_OBJECT, type = "Lj\$/util/Optional;", maxAfter = 0), + methodCall(smali = "Landroid/graphics/Point;->(II)V", location = MatchAfterImmediately()), + methodCall(smali = "Lj\$/util/Optional;->of(Ljava/lang/Object;)Lj\$/util/Optional;", location = MatchAfterImmediately()), + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()), + fieldAccess(opcode = Opcode.IPUT_OBJECT, type = "Lj\$/util/Optional;", location = MatchAfterImmediately()), - opcode(Opcode.INVOKE_VIRTUAL, maxAfter = 10) + opcode(Opcode.INVOKE_VIRTUAL, location = MatchAfterWithin(10)) ) custom { method, _ -> method.name == "onTouchEvent" } } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt index 7e2798026..e7168be19 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/buttons/navigation/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.buttons.navigation +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately import app.revanced.patcher.fingerprint import app.revanced.patcher.literal import app.revanced.patcher.methodCall @@ -12,7 +13,7 @@ internal val addCreateButtonViewFingerprint = fingerprint { instructions( string("Android Wear"), opcode(Opcode.IF_EQZ), - string("Android Automotive", maxAfter = 0), + string("Android Automotive", location = MatchAfterImmediately()), ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/formfactor/ChangeFormFactorPatch.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/formfactor/ChangeFormFactorPatch.kt index d24da1dac..d3519f333 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/formfactor/ChangeFormFactorPatch.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/formfactor/ChangeFormFactorPatch.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.formfactor +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.extensions.InstructionExtensions.addInstructions import app.revanced.patcher.extensions.InstructionExtensions.getInstruction import app.revanced.patcher.fieldAccess @@ -56,7 +57,7 @@ val changeFormFactorPatch = bytecodePatch( fieldAccess( definingClass = formFactorEnumConstructorFingerprint.originalClassDef.type, type = "I", - maxAfter = 50 + location = MatchAfterWithin(50) ) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/Fingerprints.kt index 91af81e8a..e286e21cc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/hide/general/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.hide.general +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.StringMatchType import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint @@ -23,7 +24,7 @@ internal val hideShowMoreButtonFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.LAYOUT, "expand_button_down"), methodCall(smali = "Landroid/view/LayoutInflater;->inflate(ILandroid/view/ViewGroup;Z)Landroid/view/View;"), - opcode(Opcode.MOVE_RESULT_OBJECT, 0) + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()) ) } @@ -41,8 +42,9 @@ internal val parseElementFromBufferFingerprint = fingerprint { instructions( opcode(Opcode.IGET_OBJECT), // IGET_BOOLEAN // 20.07+ - opcode(Opcode.INVOKE_INTERFACE, maxAfter = 1), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0), + opcode(Opcode.INVOKE_INTERFACE, location = MatchAfterWithin(1)), + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()), + string("Failed to parse Element", matchType = StringMatchType.STARTS_WITH) ) } @@ -135,8 +137,8 @@ internal val showFloatingMicrophoneButtonFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "fab"), - checkCast("/FloatingActionButton;", maxAfter = 10), - opcode(Opcode.IGET_BOOLEAN, maxAfter = 10) + checkCast("/FloatingActionButton;", location = MatchAfterWithin(10)), + opcode(Opcode.IGET_BOOLEAN, location = MatchAfterWithin(15)) ) } 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 312c9a561..e33965c62 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,5 +1,6 @@ package app.revanced.patches.youtube.layout.hide.shorts +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.fingerprint import app.revanced.patcher.literal import app.revanced.patcher.methodCall @@ -29,17 +30,17 @@ internal val renderBottomNavigationBarFingerprint = fingerprint { returns("V") parameters("Ljava/lang/String;") instructions( - opcode(Opcode.IGET_OBJECT, maxAfter = 0), - opcode(Opcode.MONITOR_ENTER, maxAfter = 0), - opcode(Opcode.IGET_OBJECT, maxAfter = 0), - opcode(Opcode.IF_EQZ, maxAfter = 0), - opcode(Opcode.INVOKE_INTERFACE, maxAfter = 0), + opcode(Opcode.IGET_OBJECT, MatchFirst()), + opcode(Opcode.MONITOR_ENTER, MatchAfterImmediately()), + opcode(Opcode.IGET_OBJECT, MatchAfterImmediately()), + opcode(Opcode.IF_EQZ, MatchAfterImmediately()), + opcode(Opcode.INVOKE_INTERFACE, MatchAfterImmediately()), opcode(Opcode.MONITOR_EXIT), - opcode(Opcode.RETURN_VOID, maxAfter = 0), - opcode(Opcode.MOVE_EXCEPTION, maxAfter = 0), - opcode(Opcode.MONITOR_EXIT, maxAfter = 0), - opcode(Opcode.THROW, maxAfter = 0), + opcode(Opcode.RETURN_VOID, MatchAfterImmediately()), + opcode(Opcode.MOVE_EXCEPTION, MatchAfterImmediately()), + opcode(Opcode.MONITOR_EXIT, MatchAfterImmediately()), + opcode(Opcode.THROW, MatchAfterImmediately()), ) } 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 11469ceb5..16c64efb7 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 @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.hide.time +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -16,17 +17,17 @@ internal val timeCounterFingerprint = fingerprint { methodCall( opcode = Opcode.INVOKE_STATIC, returnType = "Ljava/lang/CharSequence;", - maxAfter = 0 + location = MatchAfterImmediately() ), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0), - fieldAccess(opcode = Opcode.IGET_WIDE, type = "J", maxAfter = 0), - fieldAccess(opcode = Opcode.IGET_WIDE, type = "J", maxAfter = 0), - opcode(Opcode.SUB_LONG_2ADDR, maxAfter = 0), + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()), + fieldAccess(opcode = Opcode.IGET_WIDE, type = "J", location = MatchAfterImmediately()), + fieldAccess(opcode = Opcode.IGET_WIDE, type = "J", location = MatchAfterImmediately()), + opcode(Opcode.SUB_LONG_2ADDR, location = MatchAfterImmediately()), methodCall( opcode = Opcode.INVOKE_STATIC, returnType = "Ljava/lang/CharSequence;", - maxAfter = 5 + location = MatchAfterWithin(5) ) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt index e4f1e72c1..94d44fe6f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/miniplayer/Fingerprints.kt @@ -2,6 +2,7 @@ package app.revanced.patches.youtube.layout.miniplayer +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -105,7 +106,7 @@ internal val miniplayerModernForwardButtonFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "modern_miniplayer_forward_button"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 5) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterWithin(5)) ) } @@ -114,7 +115,7 @@ internal val miniplayerModernOverlayViewFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "scrim_overlay"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 5) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterWithin(5)) ) } @@ -127,7 +128,7 @@ internal val miniplayerModernRewindButtonFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "modern_miniplayer_rewind_button"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 5) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterWithin(5)) ) } @@ -140,7 +141,7 @@ internal val miniplayerModernActionButtonFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "modern_miniplayer_overlay_action_button"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 5) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterWithin(5)) ) } @@ -161,7 +162,7 @@ internal val miniplayerOverrideFingerprint = fingerprint { methodCall( parameters = listOf("Landroid/content/Context;"), returnType = "Z", - maxAfter = 10 + location = MatchAfterWithin(10) ) ) } @@ -216,4 +217,3 @@ internal val miniplayerSetIconsFingerprint = fingerprint { resourceLiteral(ResourceType.DRAWABLE, "yt_fill_pause_black_36") ) } - diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/fullscreen/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/fullscreen/Fingerprints.kt index 4a3ddd2c2..aecf9e228 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/fullscreen/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/fullscreen/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.player.fullscreen +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fingerprint import app.revanced.patcher.literal import app.revanced.patcher.opcode @@ -15,8 +16,8 @@ internal val openVideosFullscreenPortraitFingerprint = fingerprint { instructions( opcode(Opcode.MOVE_RESULT), // Conditional check to modify. // Open videos fullscreen portrait feature flag. - literal(45666112L, maxAfter = 5), // Cannot be more than 5. - opcode(Opcode.MOVE_RESULT, maxAfter = 10), + literal(45666112L, location = MatchAfterWithin(5)), // Cannot be more than 5. + opcode(Opcode.MOVE_RESULT, location = MatchAfterWithin(10)), ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/Fingerprints.kt index 7af7d3490..e8db1e651 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/player/overlay/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.player.overlay +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patches.shared.misc.mapping.ResourceType @@ -9,6 +10,6 @@ internal val createPlayerOverviewFingerprint = fingerprint { returns("V") instructions( resourceLiteral(ResourceType.ID, "scrim_overlay"), - checkCast("Landroid/widget/ImageView;", maxAfter = 10) + checkCast("Landroid/widget/ImageView;", location = MatchAfterWithin(10)) ) } 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 4ec8d2ad5..442290e5b 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 @@ -1,14 +1,16 @@ package app.revanced.patches.youtube.layout.seekbar +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.anyInstruction import app.revanced.patcher.fingerprint -import app.revanced.patches.youtube.shared.YOUTUBE_MAIN_ACTIVITY_CLASS_TYPE import app.revanced.patcher.literal import app.revanced.patcher.methodCall import app.revanced.patcher.opcode import app.revanced.patcher.string import app.revanced.patches.shared.misc.mapping.ResourceType import app.revanced.patches.shared.misc.mapping.resourceLiteral +import app.revanced.patches.youtube.shared.YOUTUBE_MAIN_ACTIVITY_CLASS_TYPE import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode @@ -86,8 +88,8 @@ internal val playerLinearGradientFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.COLOR, "yt_youtube_magenta"), - opcode(Opcode.FILLED_NEW_ARRAY, maxAfter = 5), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.FILLED_NEW_ARRAY, location = MatchAfterWithin(5)), + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()) ) } @@ -100,7 +102,7 @@ internal val playerLinearGradientLegacyFingerprint = fingerprint { resourceLiteral(ResourceType.COLOR, "yt_youtube_magenta"), opcode(Opcode.FILLED_NEW_ARRAY), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0), + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()), ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/Fingerprints.kt index ca23f1818..0f809987e 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/shortsautoplay/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.shortsautoplay +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -43,8 +44,20 @@ internal val reelPlaybackFingerprint = fingerprint { parameters("J") returns("V") instructions( - fieldAccess(definingClass = "Ljava/util/concurrent/TimeUnit;", name = "MILLISECONDS"), - methodCall(name = "", parameters = listOf("I", "L", "L"), maxAfter = 15), - methodCall(opcode = Opcode.INVOKE_VIRTUAL, parameters = listOf("L"), returnType = "I", maxAfter = 5) + fieldAccess( + definingClass = "Ljava/util/concurrent/TimeUnit;", + name = "MILLISECONDS" + ), + methodCall( + name = "", + parameters = listOf("I", "L", "L"), + location = MatchAfterWithin(15) + ), + methodCall( + opcode = Opcode.INVOKE_VIRTUAL, + parameters = listOf("L"), + returnType = "I", + location = MatchAfterWithin(5) + ) ) } \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/Fingerprints.kt index 0ca701418..d7ea30c3d 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/sponsorblock/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.sponsorblock +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -22,7 +23,7 @@ internal val appendTimeFingerprint = fingerprint { resourceLiteral(ResourceType.STRING, "total_time"), methodCall(smali = "Landroid/content/res/Resources;->getString(I[Ljava/lang/Object;)Ljava/lang/String;"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()) ) } @@ -31,7 +32,7 @@ internal val controlsOverlayFingerprint = fingerprint { parameters() instructions( resourceLiteral(ResourceType.ID, "inset_overlay_view_layout"), - checkCast("Landroid/widget/FrameLayout;", maxAfter = 20) + checkCast("Landroid/widget/FrameLayout;", MatchAfterWithin(20)) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/Fingerprints.kt index bb2fe09b4..c74071893 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/layout/spoofappversion/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.spoofappversion +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -15,10 +16,10 @@ internal val toolBarButtonFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.ID, "menu_item_view"), methodCall(returnType = "I", opcode = Opcode.INVOKE_INTERFACE), - opcode(Opcode.MOVE_RESULT, maxAfter = 0), - fieldAccess(type = "Landroid/widget/ImageView;", opcode = Opcode.IGET_OBJECT, maxAfter = 6), - methodCall("Landroid/content/res/Resources;", "getDrawable", maxAfter = 8), - methodCall("Landroid/widget/ImageView;", "setImageDrawable", maxAfter = 4) + opcode(Opcode.MOVE_RESULT, MatchAfterImmediately()), + fieldAccess(type = "Landroid/widget/ImageView;", opcode = Opcode.IGET_OBJECT, location = MatchAfterWithin(6)), + methodCall("Landroid/content/res/Resources;", "getDrawable", location = MatchAfterWithin(8)), + methodCall("Landroid/widget/ImageView;", "setImageDrawable", location = MatchAfterWithin(4)) ) custom { method, _ -> // 20.37+ has second parameter of "Landroid/content/Context;" 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 6fcdac9f1..58889645d 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 @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.layout.startupshortsreset +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.StringMatchType import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint @@ -19,10 +20,10 @@ internal val userWasInShortsAlternativeFingerprint = fingerprint { parameters("Ljava/lang/Object;") instructions( checkCast("Ljava/lang/Boolean;"), - methodCall(smali = "Ljava/lang/Boolean;->booleanValue()Z", maxAfter = 0), - opcode(Opcode.MOVE_RESULT, maxAfter = 0), + methodCall(smali = "Ljava/lang/Boolean;->booleanValue()Z", location = MatchAfterImmediately()), + opcode(Opcode.MOVE_RESULT, MatchAfterImmediately()), // 20.40+ string was merged into another string and is a partial match. - string("userIsInShorts: ", matchType = StringMatchType.CONTAINS, maxAfter = 15) + string("userIsInShorts: ", matchType = StringMatchType.CONTAINS, location = MatchAfterWithin(15)) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/Fingerprints.kt index f40e57025..a084703e4 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/fix/backtoexitgesture/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.fix.backtoexitgesture +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -26,10 +27,10 @@ internal val recyclerViewTopScrollingFingerprint = fingerprint { parameters() instructions( methodCall(smali = "Ljava/util/Iterator;->next()Ljava/lang/Object;"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0), - checkCast("Landroid/support/v7/widget/RecyclerView;", maxAfter = 0), - literal(0, maxAfter = 0), - methodCall(definingClass = "Landroid/support/v7/widget/RecyclerView;", maxAfter = 0), - opcode(Opcode.GOTO, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()), + checkCast("Landroid/support/v7/widget/RecyclerView;", MatchAfterImmediately()), + literal(0, location = MatchAfterImmediately()), + methodCall(definingClass = "Landroid/support/v7/widget/RecyclerView;", location = MatchAfterImmediately()), + opcode(Opcode.GOTO, MatchAfterImmediately()) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/gms/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/gms/Fingerprints.kt index 701f6553f..0353e3841 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/gms/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/gms/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.gms +import app.revanced.patcher.InstructionLocation.* import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall import app.revanced.patcher.opcode @@ -16,7 +17,7 @@ internal val specificNetworkErrorViewControllerFingerprint = fingerprint { resourceLiteral(ResourceType.DRAWABLE, "ic_offline_no_content_upside_down"), resourceLiteral(ResourceType.STRING, "offline_no_content_body_text_not_offline_eligible"), methodCall(name = "getString", returnType = "Ljava/lang/String;"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterImmediately()) ) } @@ -30,6 +31,6 @@ internal val loadingFrameLayoutControllerFingerprint = fingerprint { resourceLiteral(ResourceType.DRAWABLE, "ic_offline_no_content_upside_down"), resourceLiteral(ResourceType.STRING, "offline_no_content_body_text_not_offline_eligible"), methodCall(name = "getString", returnType = "Ljava/lang/String;"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()) ) } \ No newline at end of file diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/Fingerprints.kt index a3f92fbf0..bf6d4f8fc 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/navigation/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.navigation +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patcher.methodCall @@ -35,7 +36,7 @@ internal val appCompatToolbarBackButtonFingerprint = fingerprint { accessFlags(AccessFlags.PUBLIC, AccessFlags.FINAL) returns("Landroid/graphics/drawable/Drawable;") parameters() - custom { methodDef, classDef -> + custom { _, classDef -> classDef.type == "Landroid/support/v7/widget/Toolbar;" } } @@ -143,7 +144,7 @@ internal val imageEnumConstructorFingerprint = fingerprint { internal val setEnumMapFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.DRAWABLE, "yt_fill_bell_black_24"), - methodCall(smali = "Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;", maxAfter = 10), - methodCall(smali = "Ljava/util/EnumMap;->put(Ljava/lang/Enum;Ljava/lang/Object;)Ljava/lang/Object;", maxAfter = 10) + methodCall(smali = "Ljava/lang/Integer;->valueOf(I)Ljava/lang/Integer;", location = MatchAfterWithin(10)), + methodCall(smali = "Ljava/util/EnumMap;->put(Ljava/lang/Enum;Ljava/lang/Object;)Ljava/lang/Object;", location = MatchAfterWithin(10)) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/Fingerprints.kt index 0148bb30f..91c36f6cf 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playercontrols/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.playercontrols +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately import app.revanced.patcher.checkCast import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -68,7 +69,7 @@ internal val playerTopControlsInflateFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.ID, "controls_layout_stub"), methodCall("Landroid/view/ViewStub;", "inflate"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()) ) } @@ -78,7 +79,7 @@ internal val playerBottomControlsInflateFingerprint = fingerprint { instructions( resourceLiteral(ResourceType.ID, "bottom_ui_container_stub"), methodCall("Landroid/view/ViewStub;", "inflate"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT_OBJECT, MatchAfterImmediately()) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/Fingerprints.kt index 2a6b3a86a..308445ca9 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/playertype/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.playertype +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fingerprint import app.revanced.patcher.opcode import app.revanced.patcher.string @@ -30,7 +31,7 @@ internal val reelWatchPagerFingerprint = fingerprint { returns("Landroid/view/View;") instructions( resourceLiteral(ResourceType.ID, "reel_watch_player"), - opcode(Opcode.MOVE_RESULT_OBJECT, maxAfter = 10) + opcode(Opcode.MOVE_RESULT_OBJECT, location = MatchAfterWithin(10)) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/Fingerprints.kt index c3e94b66e..31e3c87a8 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/misc/settings/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.misc.settings +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fingerprint import app.revanced.patcher.literal import app.revanced.patcher.opcode @@ -31,7 +32,7 @@ internal val cairoFragmentConfigFingerprint = fingerprint { returns("Z") instructions( literal(45532100L), - opcode(Opcode.MOVE_RESULT, 10) + opcode(Opcode.MOVE_RESULT, location = MatchAfterWithin(10)) ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/shared/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/shared/Fingerprints.kt index 6ada54fb2..16eb8630f 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/shared/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/shared/Fingerprints.kt @@ -1,5 +1,6 @@ package app.revanced.patches.youtube.shared +import app.revanced.patcher.InstructionLocation.MatchAfterImmediately import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -104,7 +105,7 @@ internal val seekbarFingerprint = fingerprint { internal val seekbarOnDrawFingerprint = fingerprint { instructions( methodCall(smali = "Ljava/lang/Math;->round(F)I"), - opcode(Opcode.MOVE_RESULT, maxAfter = 0) + opcode(Opcode.MOVE_RESULT, location = MatchAfterImmediately()) ) custom { method, _ -> method.name == "onDraw" } } @@ -127,6 +128,6 @@ internal val videoQualityChangedFingerprint = fingerprint { newInstance("Lcom/google/android/libraries/youtube/innertube/model/media/VideoQuality;"), opcode(Opcode.IGET_OBJECT), opcode(Opcode.CHECK_CAST), - fieldAccess(type = "I", opcode = Opcode.IGET, maxAfter = 0), // Video resolution (human readable). + fieldAccess(type = "I", opcode = Opcode.IGET, location = MatchAfterImmediately()), // Video resolution (human readable). ) } diff --git a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/Fingerprints.kt b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/Fingerprints.kt index 98a292358..2d11c62c1 100644 --- a/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/Fingerprints.kt +++ b/patches/src/main/kotlin/app/revanced/patches/youtube/video/information/Fingerprints.kt @@ -1,5 +1,8 @@ package app.revanced.patches.youtube.video.information +import app.revanced.patcher.InstructionFilter +import app.revanced.patcher.InstructionLocation +import app.revanced.patcher.InstructionLocation.MatchAfterWithin import app.revanced.patcher.fieldAccess import app.revanced.patcher.fingerprint import app.revanced.patcher.literal @@ -9,7 +12,10 @@ import app.revanced.patches.youtube.shared.videoQualityChangedFingerprint import app.revanced.util.getReference import com.android.tools.smali.dexlib2.AccessFlags import com.android.tools.smali.dexlib2.Opcode +import com.android.tools.smali.dexlib2.iface.Method +import com.android.tools.smali.dexlib2.iface.instruction.Instruction import com.android.tools.smali.dexlib2.iface.reference.FieldReference +import com.android.tools.smali.dexlib2.iface.reference.StringReference internal val createVideoPlayerSeekbarFingerprint = fingerprint { returns("V") @@ -48,6 +54,21 @@ internal val playerInitFingerprint = fingerprint { internal val seekFingerprint = fingerprint { instructions( string("Attempting to seek during an ad"), + object : InstructionFilter { + override fun matches( + enclosingMethod: Method, + instruction: Instruction + ): Boolean { + TODO("Not yet implemented") + } + + override val location: InstructionLocation = InstructionLocation.MatchFirst() + }, + + // Custom inline filter. Uses default match anywhere after the previous filter. + { _, instruction -> + instruction.getReference()?.string?.let { it.length > 10 } ?: false + } ) } @@ -129,7 +150,7 @@ internal val videoEndFingerprint = fingerprint { parameters = listOf(), returnType = "V" ), - literal(45368273L, maxAfter = 5), + literal(45368273L, location = MatchAfterWithin(5)), string("Attempting to seek when video is not playing"), ) }