diff --git a/patcher/api/android/patcher.api b/patcher/api/android/patcher.api index 0eeb45f..88a7ed4 100644 --- a/patcher/api/android/patcher.api +++ b/patcher/api/android/patcher.api @@ -373,10 +373,6 @@ public final class app/revanced/patcher/MatchingKt { public static final fun anyVirtualMethod (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lkotlin/jvm/functions/Function1;)Z public static final fun at (ILkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; public static final fun at (ILkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; - public static final fun at (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; - public static final fun at (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; - public static synthetic fun at$default (ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static synthetic fun at$default (ILkotlin/jvm/functions/Function4;ILjava/lang/Object;)Lkotlin/jvm/functions/Function4; public static final fun custom (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun declarativePredicate (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static final fun definingClass (Lapp/revanced/patcher/MutablePredicateList;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V @@ -403,6 +399,8 @@ public final class app/revanced/patcher/MatchingKt { public static synthetic fun name$default (Lapp/revanced/patcher/MutablePredicateList;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public static final fun noneOf (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun noneOf ([Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; + public static final fun opcodes (Lapp/revanced/patcher/IndexedMatcher;Lapp/revanced/patcher/MutablePredicateList;[Lcom/android/tools/smali/dexlib2/Opcode;)V + public static final fun opcodes (Lapp/revanced/patcher/MutablePredicateList;[Lcom/android/tools/smali/dexlib2/Opcode;)V public static final fun parameterTypes (Lapp/revanced/patcher/MutablePredicateList;[Ljava/lang/String;)V public static final fun predicate (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun rememberDeclarativePredicate (Lapp/revanced/patcher/PredicateContext;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z diff --git a/patcher/api/jvm/patcher.api b/patcher/api/jvm/patcher.api index 0ab10b7..600b1f0 100644 --- a/patcher/api/jvm/patcher.api +++ b/patcher/api/jvm/patcher.api @@ -373,10 +373,6 @@ public final class app/revanced/patcher/MatchingKt { public static final fun anyVirtualMethod (Lcom/android/tools/smali/dexlib2/iface/ClassDef;Lkotlin/jvm/functions/Function1;)Z public static final fun at (ILkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; public static final fun at (ILkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; - public static final fun at (Lkotlin/jvm/functions/Function1;)Lkotlin/jvm/functions/Function4; - public static final fun at (Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; - public static synthetic fun at$default (ILkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lkotlin/jvm/functions/Function4; - public static synthetic fun at$default (ILkotlin/jvm/functions/Function4;ILjava/lang/Object;)Lkotlin/jvm/functions/Function4; public static final fun custom (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun declarativePredicate (Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z public static final fun definingClass (Lapp/revanced/patcher/MutablePredicateList;Ljava/lang/String;Lkotlin/jvm/functions/Function2;)V @@ -403,6 +399,8 @@ public final class app/revanced/patcher/MatchingKt { public static synthetic fun name$default (Lapp/revanced/patcher/MutablePredicateList;Ljava/lang/String;Lkotlin/jvm/functions/Function2;ILjava/lang/Object;)V public static final fun noneOf (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun noneOf ([Lkotlin/jvm/functions/Function4;)Lkotlin/jvm/functions/Function4; + public static final fun opcodes (Lapp/revanced/patcher/IndexedMatcher;Lapp/revanced/patcher/MutablePredicateList;[Lcom/android/tools/smali/dexlib2/Opcode;)V + public static final fun opcodes (Lapp/revanced/patcher/MutablePredicateList;[Lcom/android/tools/smali/dexlib2/Opcode;)V public static final fun parameterTypes (Lapp/revanced/patcher/MutablePredicateList;[Ljava/lang/String;)V public static final fun predicate (Lapp/revanced/patcher/MutablePredicateList;Lkotlin/jvm/functions/Function1;)V public static final fun rememberDeclarativePredicate (Lapp/revanced/patcher/PredicateContext;Ljava/lang/Object;Ljava/lang/Object;Lkotlin/jvm/functions/Function1;)Z diff --git a/patcher/src/commonMain/kotlin/app/revanced/patcher/Matching.kt b/patcher/src/commonMain/kotlin/app/revanced/patcher/Matching.kt index f451674..60ccfd6 100644 --- a/patcher/src/commonMain/kotlin/app/revanced/patcher/Matching.kt +++ b/patcher/src/commonMain/kotlin/app/revanced/patcher/Matching.kt @@ -7,6 +7,7 @@ import app.revanced.patcher.BytecodePatchContextClassDefMatching.firstMutableCla import app.revanced.patcher.BytecodePatchContextMethodMatching.firstMutableMethodOrNull import app.revanced.patcher.BytecodePatchContextMethodMatching.gettingFirstMethodDeclarativelyOrNull import app.revanced.patcher.ClassDefMethodMatching.firstMethodDeclarativelyOrNull +import app.revanced.patcher.InstructionMatchingFunctions.invoke import app.revanced.patcher.IterableClassDefClassDefMatching.firstClassDefOrNull import app.revanced.patcher.IterableClassDefMethodMatching.firstMethodOrNull import app.revanced.patcher.IterableMethodMethodMatching.firstMethodDeclarativelyOrNull @@ -645,22 +646,12 @@ fun Iterable.matchIndexed( key: Any, vararg items: IndexedMatcherPredicate ) = indexedMatcher()(key, this) { items.forEach { +it } } -fun at( - index: Int = 0, predicate: IndexedMatcherPredicate -): IndexedMatcherPredicate = { lastMatchedIndex, currentIndex, setNextIndex -> - currentIndex == index && predicate(lastMatchedIndex, currentIndex, setNextIndex) -} - -fun at(index: Int = 0, predicate: Predicate) = at(index) { _, _, _ -> predicate() } - -fun at(predicate: IndexedMatcherPredicate): IndexedMatcherPredicate = - at(0) { lastMatchedIndex, currentIndex, setNextIndex -> - predicate( - lastMatchedIndex, currentIndex, setNextIndex - ) +fun at(index: Int, predicate: IndexedMatcherPredicate): IndexedMatcherPredicate = + { lastMatchedIndex, currentIndex, setNextIndex -> + currentIndex == index && predicate(lastMatchedIndex, currentIndex, setNextIndex) } -fun at(predicate: Predicate) = at { _, _, _ -> predicate() } +fun at(index: Int, predicate: Predicate) = at(index) { _, _, _ -> predicate() } fun after( range: IntRange = 1..1, predicate: IndexedMatcherPredicate @@ -936,6 +927,15 @@ fun MutablePredicateList.custom(block: Predicate) { predicate { block() } } +fun MutablePredicateList.opcodes( + vararg opcodes: Opcode +) = instructions { opcodes.forEach { +it() } } + +context(matcher: IndexedMatcher) +fun MutablePredicateList.opcodes( + vararg opcodes: Opcode +) = instructions { opcodes.forEach { +it() } } + object InstructionMatchingFunctions { inline fun `is`( crossinline predicate: Predicate = { true } diff --git a/patcher/src/jvmTest/kotlin/app/revanced/patcher/MatchingTest.kt b/patcher/src/jvmTest/kotlin/app/revanced/patcher/MatchingTest.kt index d872898..429a843 100644 --- a/patcher/src/jvmTest/kotlin/app/revanced/patcher/MatchingTest.kt +++ b/patcher/src/jvmTest/kotlin/app/revanced/patcher/MatchingTest.kt @@ -37,7 +37,7 @@ class MatchingTest : PatcherTestBase() { strings(StringMatchingFunctions.string("Hello", String::startsWith)) instructions( - at(Opcode.CONST_STRING()), + at(0, Opcode.CONST_STRING()), `is`(), noneOf(registers()), string("test", String::contains), @@ -147,7 +147,7 @@ class MatchingTest : PatcherTestBase() { val matcher = indexedMatcher() matcher.apply { - +at { this > 5 } + +at(0) { this > 5 } } assertFalse( matcher(iterable), @@ -155,7 +155,7 @@ class MatchingTest : PatcherTestBase() { ) matcher.clear() - matcher.apply { +at { this == 1 } }(iterable) + matcher.apply { +at(0) { this == 1 } }(iterable) assertEquals( listOf(0), matcher.indices, @@ -176,7 +176,7 @@ class MatchingTest : PatcherTestBase() { matcher.clear() matcher.apply { - +at { this == 1 } + +at(0) { this == 1 } add { _, _, _ -> this == 2 } add { _, _, _ -> this == 4 } }(iterable) @@ -216,7 +216,7 @@ class MatchingTest : PatcherTestBase() { matcher.clear() matcher.apply { - +at { this == 1 } + +at(0) { this == 1 } +after(2..5) { this == 4 } add { _, _, _ -> this == 8 } add { _, _, _ -> this == 9 }