aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-13 02:47:09 +0100
committer zaaarf <zaaarf@proton.me>2023-03-13 02:47:09 +0100
commit30f7660ded76c402a6c434eb4d54a54e2ec8f187 (patch)
tree5f0340109e2a2533ec7d76779ca3a3e991da3929
parent592e38066fb325d2412c914369df1d4aa5c1c09c (diff)
fix: failure to restart matcher after failing to find pattern once0.3.3
-rw-r--r--src/main/java/ftbsc/lll/tools/PatternMatcher.java32
-rw-r--r--src/main/java/ftbsc/lll/tools/StackTools.java2
2 files changed, 14 insertions, 20 deletions
diff --git a/src/main/java/ftbsc/lll/tools/PatternMatcher.java b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
index a941b72..c2df7d5 100644
--- a/src/main/java/ftbsc/lll/tools/PatternMatcher.java
+++ b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
@@ -78,30 +78,24 @@ public class PatternMatcher {
*/
public InsnSequence find(AbstractInsnNode node) {
if(node != null) {
- int match = 0;
- AbstractInsnNode first = null;
- AbstractInsnNode last = null;
+ AbstractInsnNode first;
+ AbstractInsnNode last;
for(AbstractInsnNode cur = node; cur != null; cur = reverse ? cur.getPrevious() : cur.getNext()) {
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
- if(predicates.get(match) != null) {
- if(predicates.get(match).test(cur)) {
- match++;
- if (first == null)
- first = cur;
- } else { //reset
- first = null;
- match = 0;
+ if(predicates.size() == 0)
+ return new InsnSequence(cur); //match whatever
+ first = cur;
+ last = cur;
+ for(int match = 0; match < predicates.size(); match++) {
+ if(last == null) break;
+ if(!predicates.get(match).test(last)) break;
+ if(match == predicates.size() - 1) {
+ if(reverse) return new InsnSequence(last, first); //we are matching backwards
+ else return new InsnSequence(first, last);
}
- }
- //check if we found the last one
- if(match == predicates.size()) {
- if(match == 0)
- return new InsnSequence(cur); //match whatever
- last = cur;
- if(reverse) return new InsnSequence(last, first); //we are matching backwards
- else return new InsnSequence(first, last);
+ last = reverse ? last.getPrevious() : last.getNext();
}
}
}
diff --git a/src/main/java/ftbsc/lll/tools/StackTools.java b/src/main/java/ftbsc/lll/tools/StackTools.java
index 6816860..9268d56 100644
--- a/src/main/java/ftbsc/lll/tools/StackTools.java
+++ b/src/main/java/ftbsc/lll/tools/StackTools.java
@@ -43,7 +43,7 @@ public class StackTools implements Opcodes {
public static InsnList instantiate(String name, String desc, InsnList args) {
InsnSequence list = new InsnSequence();
list.add(new TypeInsnNode(NEW, name), new InsnNode(DUP));
- if (args != null) list.add(args);
+ if(args != null) list.add(args);
list.add(new MethodInsnNode(INVOKESPECIAL, name, "<init>", desc, false));
return list;
}