use of net.runelite.asm.attributes.code.instructions.IfICmpNe in project runelite by runelite.
the class MenuActionDeobfuscator method insert.
private void insert(Method method, List<Comparison> comparisons) {
Instructions instructions = method.getCode().getInstructions();
List<Instruction> ins = instructions.getInstructions();
// replace all if(var == constant) with a jump to the false branch
// then, insert before the first jump the ifs to jump to the old
// true branch
//
// this is probably actually lookupswitch but it isn't mappable
// currently...
int min = -1;
for (Comparison comp : comparisons) {
if (min == -1) {
min = ins.indexOf(comp.lvt);
} else {
min = Math.min(min, ins.indexOf(comp.lvt));
}
if (comp.cmp.getType() == InstructionType.IF_ICMPEQ) {
If cmp = (If) comp.cmp;
// remove
instructions.remove(comp.ldc);
instructions.remove((Instruction) comp.lvt);
instructions.remove(comp.cmp);
comp.next = cmp.getJumps().get(0);
} else if (comp.cmp.getType() == InstructionType.IF_ICMPNE) {
// replace with goto dest
If cmp = (If) comp.cmp;
int idx = ins.indexOf(cmp);
assert idx != -1;
comp.next = instructions.createLabelFor(ins.get(idx + 1));
instructions.remove(comp.ldc);
instructions.remove((Instruction) comp.lvt);
instructions.replace(comp.cmp, new Goto(instructions, cmp.getJumps().get(0)));
} else {
throw new IllegalStateException();
}
}
assert min != -1;
// sort comparisons - but if they jump to the same address, they are equal..
List<Comparison> sortedComparisons = new ArrayList<>(comparisons);
Collections.sort(sortedComparisons, (c1, c2) -> compare(comparisons, c1, c2));
// reinsert jumps
for (int i = 0; i < sortedComparisons.size(); ++i) {
Comparison comp = sortedComparisons.get(i);
Instruction lvt = (Instruction) comp.lvt;
lvt.setInstructions(instructions);
comp.ldc.setInstructions(instructions);
instructions.addInstruction(min++, lvt);
instructions.addInstruction(min++, comp.ldc);
// use if_icmpeq if what follows also jumps to the same location
boolean multiple = i + 1 < sortedComparisons.size() && sortedComparisons.get(i + 1).next == comp.next;
if (multiple) {
instructions.addInstruction(min++, new IfICmpEq(instructions, comp.next));
} else {
// fernflower decompiles a series of if_icmpeq as chains of not equal expressions
Label label = instructions.createLabelFor(ins.get(min));
instructions.addInstruction(min++, new IfICmpNe(instructions, label));
instructions.addInstruction(min++, new Goto(instructions, comp.next));
// go past label
++min;
}
}
}
use of net.runelite.asm.attributes.code.instructions.IfICmpNe in project runelite by runelite.
the class ExprArgOrder method visit.
private void visit(InstructionContext ctx) {
Instruction ins = ctx.getInstruction();
if (ins instanceof IAdd || ins instanceof IMul || ins instanceof IfICmpEq || ins instanceof IfICmpNe || ins instanceof IfACmpEq || ins instanceof IfACmpNe) {
Expression expression = new Expression(ctx);
parseExpr(expression, ctx);
if (!exprs.containsKey(ins)) {
exprIns.add(ins);
exprs.put(ins, expression);
}
}
}
Aggregations