fix: failure to restart matcher after failing to find pattern once

This commit is contained in:
zaaarf 2023-03-13 02:47:09 +01:00
parent 592e38066f
commit 30f7660ded
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
2 changed files with 14 additions and 20 deletions

View file

@ -78,31 +78,25 @@ 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;
}
}
//check if we found the last one
if(match == predicates.size()) {
if(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);
}
last = reverse ? last.getPrevious() : last.getNext();
}
}
}
throw new PatternNotFoundException("Failed to find pattern!");