Skip to content

Commit

Permalink
Fix permissiveness behaviour in BeforeInvoke, fixes SpongePowered#204
Browse files Browse the repository at this point in the history
  • Loading branch information
Mumfrey committed Aug 15, 2017
1 parent 2f63e40 commit ad79bf9
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,22 @@ public BeforeInvoke setLogging(boolean logging) {
*/
@Override
public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes) {
int ordinal = 0;
boolean found = false;

this.log("{} is searching for an injection point in method with descriptor {}", this.className, desc);

if (!this.find(desc, insns, nodes, this.target)) {
return this.find(desc, insns, nodes, this.permissiveTarget);
}
return true;
}

protected boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> nodes, MemberInfo target) {
if (target == null) {
return false;
}

int ordinal = 0;
boolean found = false;

ListIterator<AbstractInsnNode> iter = insns.iterator();
while (iter.hasNext()) {
AbstractInsnNode insn = iter.next();
Expand All @@ -135,7 +146,7 @@ public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> no
MemberInfo nodeInfo = new MemberInfo(insn);
this.log("{} is considering insn {}", this.className, nodeInfo);

if (this.matches(nodeInfo)) {
if (target.matches(nodeInfo.owner, nodeInfo.name, nodeInfo.desc)) {
this.log("{} > found a matching insn, checking preconditions...", this.className);

if (this.matchesInsn(nodeInfo, ordinal)) {
Expand All @@ -158,14 +169,6 @@ public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> no
return found;
}

private boolean matches(MemberInfo nodeInfo) {
if (this.target.matches(nodeInfo.owner, nodeInfo.name, nodeInfo.desc)) {
return true;
}

return this.permissiveTarget != null && this.permissiveTarget.matches(nodeInfo.owner, nodeInfo.name, nodeInfo.desc);
}

protected boolean addInsn(InsnList insns, Collection<AbstractInsnNode> nodes, AbstractInsnNode insn) {
nodes.add(insn);
return true;
Expand Down

0 comments on commit ad79bf9

Please sign in to comment.