add opcode instructions api

This commit is contained in:
oSumAtrIX
2026-01-17 19:44:14 +01:00
parent afe27b960b
commit b30b8f00dc
4 changed files with 23 additions and 27 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 <T> Iterable<T>.matchIndexed(
key: Any, vararg items: IndexedMatcherPredicate<T>
) = indexedMatcher<T>()(key, this) { items.forEach { +it } }
fun <T> at(
index: Int = 0, predicate: IndexedMatcherPredicate<T>
): IndexedMatcherPredicate<T> = { lastMatchedIndex, currentIndex, setNextIndex ->
currentIndex == index && predicate(lastMatchedIndex, currentIndex, setNextIndex)
}
fun <T> at(index: Int = 0, predicate: Predicate<T>) = at<T>(index) { _, _, _ -> predicate() }
fun <T> at(predicate: IndexedMatcherPredicate<T>): IndexedMatcherPredicate<T> =
at(0) { lastMatchedIndex, currentIndex, setNextIndex ->
predicate(
lastMatchedIndex, currentIndex, setNextIndex
)
fun <T> at(index: Int, predicate: IndexedMatcherPredicate<T>): IndexedMatcherPredicate<T> =
{ lastMatchedIndex, currentIndex, setNextIndex ->
currentIndex == index && predicate(lastMatchedIndex, currentIndex, setNextIndex)
}
fun <T> at(predicate: Predicate<T>) = at<T> { _, _, _ -> predicate() }
fun <T> at(index: Int, predicate: Predicate<T>) = at<T>(index) { _, _, _ -> predicate() }
fun <T> after(
range: IntRange = 1..1, predicate: IndexedMatcherPredicate<T>
@@ -936,6 +927,15 @@ fun MutablePredicateList<Method>.custom(block: Predicate<Method>) {
predicate { block() }
}
fun MutablePredicateList<Method>.opcodes(
vararg opcodes: Opcode
) = instructions { opcodes.forEach { +it() } }
context(matcher: IndexedMatcher<Instruction>)
fun MutablePredicateList<Method>.opcodes(
vararg opcodes: Opcode
) = instructions { opcodes.forEach { +it() } }
object InstructionMatchingFunctions {
inline fun <reified T : Instruction> `is`(
crossinline predicate: Predicate<T> = { true }

View File

@@ -37,7 +37,7 @@ class MatchingTest : PatcherTestBase() {
strings(StringMatchingFunctions.string("Hello", String::startsWith))
instructions(
at(Opcode.CONST_STRING()),
at(0, Opcode.CONST_STRING()),
`is`<TwoRegisterInstruction>(),
noneOf(registers()),
string("test", String::contains),
@@ -147,7 +147,7 @@ class MatchingTest : PatcherTestBase() {
val matcher = indexedMatcher<Int>()
matcher.apply {
+at<Int> { this > 5 }
+at<Int>(0) { this > 5 }
}
assertFalse(
matcher(iterable),
@@ -155,7 +155,7 @@ class MatchingTest : PatcherTestBase() {
)
matcher.clear()
matcher.apply { +at<Int> { this == 1 } }(iterable)
matcher.apply { +at<Int>(0) { this == 1 } }(iterable)
assertEquals(
listOf(0),
matcher.indices,
@@ -176,7 +176,7 @@ class MatchingTest : PatcherTestBase() {
matcher.clear()
matcher.apply {
+at<Int> { this == 1 }
+at<Int>(0) { this == 1 }
add { _, _, _ -> this == 2 }
add { _, _, _ -> this == 4 }
}(iterable)
@@ -216,7 +216,7 @@ class MatchingTest : PatcherTestBase() {
matcher.clear()
matcher.apply {
+at<Int> { this == 1 }
+at<Int>(0) { this == 1 }
+after<Int>(2..5) { this == 4 }
add { _, _, _ -> this == 8 }
add { _, _, _ -> this == 9 }