fix: fixed several bugs in find function

This commit is contained in:
zaaarf 2023-03-04 11:28:23 +01:00
parent 118fae8fe7
commit 3185d840c4
No known key found for this signature in database
GPG key ID: AD8563472FD43386

View file

@ -85,17 +85,24 @@ public class PatternMatcher {
if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue; if(ignoreLabels && cur.getType() == AbstractInsnNode.LABEL) continue;
if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue; if(ignoreFrames && cur.getType() == AbstractInsnNode.FRAME) continue;
if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue; if(ignoreLineNumbers && cur.getType() == AbstractInsnNode.LINE) continue;
if(match == predicates.size()) { if(predicates.get(match).test(cur)) {
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)) {
match++; match++;
if(first == null) if(first == null)
first = cur; 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!"); throw new PatternNotFoundException("Failed to find pattern!");