From 3185d840c456d76140d1f40b7a0c8818dba3b18f Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sat, 4 Mar 2023 11:28:23 +0100 Subject: [PATCH] fix: fixed several bugs in find function --- .../java/ftbsc/lll/tools/PatternMatcher.java | 23 ++++++++++++------- 1 file 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!");