summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-04 11:28:23 +0100
committer zaaarf <zaaarf@proton.me>2023-03-04 11:28:23 +0100
commit3185d840c456d76140d1f40b7a0c8818dba3b18f (patch)
tree5e049dda61d5d6c761b2928a495a7afba0190a23 /src/main/java/ftbsc
parent118fae8fe79fe3bfdca79bfd4d08c27b1732ec45 (diff)
fix: fixed several bugs in find function
Diffstat (limited to 'src/main/java/ftbsc')
-rw-r--r--src/main/java/ftbsc/lll/tools/PatternMatcher.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/ftbsc/lll/tools/PatternMatcher.java b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
index 79539df..161a3fa 100644
--- a/src/main/java/ftbsc/lll/tools/PatternMatcher.java
+++ b/src/main/java/ftbsc/lll/tools/PatternMatcher.java
@@ -85,17 +85,24 @@ public class PatternMatcher {
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
- if(match == predicates.size()) {
- last = cur.getPrevious(); //it was actually the previous run in this case
- if(first != null && last != null) {
- if(reverse) return new InsnSequence(last, first);
- else return new InsnSequence(first, last);
- }
- } else if (predicates.get(match).test(cur)) {
+ if(predicates.get(match).test(cur)) {
match++;
if(first == null)
first = cur;
- } else match = 0;
+ } else { //reset
+ first = null;
+ match = 0;
+ }
+ //check if we found the last one
+ if(match == predicates.size()) {
+ last = cur;
+ break;
+ }
+ }
+ //only return value if we found both a start and an end
+ if(first != null && last != null) {
+ if(reverse) return new InsnSequence(last, first); //we are matching backwards
+ else return new InsnSequence(first, last);
}
}
throw new PatternNotFoundException("Failed to find pattern!");