Search in sources :

Example 1 with IfICmpNe

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;
        }
    }
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) Goto(net.runelite.asm.attributes.code.instructions.Goto) ArrayList(java.util.ArrayList) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) IfICmpNe(net.runelite.asm.attributes.code.instructions.IfICmpNe) If(net.runelite.asm.attributes.code.instructions.If)

Example 2 with IfICmpNe

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);
        }
    }
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IfACmpEq(net.runelite.asm.attributes.code.instructions.IfACmpEq) IfACmpNe(net.runelite.asm.attributes.code.instructions.IfACmpNe) IfICmpNe(net.runelite.asm.attributes.code.instructions.IfICmpNe) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)2 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)2 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)2 IfICmpEq (net.runelite.asm.attributes.code.instructions.IfICmpEq)2 IfICmpNe (net.runelite.asm.attributes.code.instructions.IfICmpNe)2 ArrayList (java.util.ArrayList)1 Instructions (net.runelite.asm.attributes.code.Instructions)1 Label (net.runelite.asm.attributes.code.Label)1 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)1 Goto (net.runelite.asm.attributes.code.instructions.Goto)1 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)1 IMul (net.runelite.asm.attributes.code.instructions.IMul)1 If (net.runelite.asm.attributes.code.instructions.If)1 IfACmpEq (net.runelite.asm.attributes.code.instructions.IfACmpEq)1 IfACmpNe (net.runelite.asm.attributes.code.instructions.IfACmpNe)1