Search in sources :

Example 26 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class CodeVisitor method visitLabel.

@Override
public void visitLabel(Label label) {
    Instruction i = code.getInstructions().findOrCreateLabel(label);
    code.getInstructions().addInstruction(i);
}
Also used : FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) TypeInstruction(net.runelite.asm.attributes.code.instruction.types.TypeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) IntInstruction(net.runelite.asm.attributes.code.instruction.types.IntInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 27 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class ModArith method insertGetterSetterMuls.

private void insertGetterSetterMuls(Encryption encr) {
    // before setfield insert imul * getter
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null) {
                continue;
            }
            Instructions ins = code.getInstructions();
            List<Instruction> ilist = ins.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction in = ilist.get(i);
                if (in instanceof SetFieldInstruction) {
                    SetFieldInstruction sfi = (SetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // insert imul
                    if (p.getType() == Integer.class) {
                        ilist.add(i++, new LDC(ins, (int) p.getter));
                        ilist.add(i++, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(i++, new LDC(ins, (long) p.getter));
                        ilist.add(i++, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                } else if (in instanceof GetFieldInstruction) {
                    GetFieldInstruction sfi = (GetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // imul
                    if (p.getType() == Integer.class) {
                        ilist.add(++i, new LDC(ins, (int) p.setter));
                        ilist.add(++i, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(++i, new LDC(ins, (long) p.setter));
                        ilist.add(++i, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                }
            }
        }
    }
}
Also used : SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Field(net.runelite.asm.Field) IMul(net.runelite.asm.attributes.code.instructions.IMul) LMul(net.runelite.asm.attributes.code.instructions.LMul) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 28 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class MultiplicationDeobfuscator method visit.

private void visit(MethodContext ctx) {
    for (InstructionContext ictx : ctx.getInstructionContexts()) {
        Instruction instruction = ictx.getInstruction();
        if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) {
            continue;
        }
        MultiplicationExpression expression;
        try {
            expression = parseExpression(ictx, instruction.getClass());
        } catch (IllegalStateException ex) {
            continue;
        }
        if (expression == null) {
            continue;
        }
        if (done.contains(instruction)) {
            continue;
        }
        done.add(instruction);
        assert instruction instanceof IMul || instruction instanceof LMul;
        if (instruction instanceof IMul) {
            count += expression.simplify(1);
        } else if (instruction instanceof LMul) {
            count += expression.simplify(1L);
        } else {
            throw new IllegalStateException();
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) IMul(net.runelite.asm.attributes.code.instructions.IMul) LMul(net.runelite.asm.attributes.code.instructions.LMul) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) DupInstruction(net.runelite.asm.attributes.code.instruction.types.DupInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 29 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class MultiplicationExpression method simplify.

int simplify(Number start) {
    int count = 0;
    Number result = start;
    // calculate result
    for (InstructionContext i : instructions) {
        PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction();
        Number value = (Number) pci.getConstant();
        result = DMath.multiply(result, value);
    }
    if (dupmagic != null) {
        // mul dupmagic by result of dup ins?
        PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
        Number value = (Number) pci.getConstant();
        for (InstructionContext ic : dupedInstructions) {
            PushConstantInstruction pci2 = (PushConstantInstruction) ic.getInstruction();
            Number value2 = (Number) pci2.getConstant();
            value = DMath.multiply(value, value2);
        }
        Instruction newIns = pci.setConstant(value);
        assert newIns == (Instruction) pci;
    }
    // multiply subexpressions by result
    if (!subexpressions.isEmpty()) {
        for (MultiplicationExpression me : subexpressions) {
            count += me.simplify(result);
        }
        if (dupmagic != null) {
            PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
            Number value = (Number) pci.getConstant();
            value = DMath.multiply(value, DMath.modInverse(result));
            pci.setConstant(value);
        }
        // constant has been distributed, outer numbers all go to 1
        if (result instanceof Long)
            result = 1L;
        else
            result = 1;
    }
    // set result on ins
    for (InstructionContext i : instructions) {
        PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction();
        Instruction newIns = pci.setConstant(result);
        ++count;
        assert newIns == pci;
        // rest of the results go to 1
        if (result instanceof Long)
            result = 1L;
        else
            result = 1;
    }
    return count;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 30 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class ControlFlowDeobfuscator method runJumpLabel.

/**
 * remove jumps followed immediately by the label they are jumping to
 *
 * @param code
 */
private void runJumpLabel(Code code) {
    Instructions ins = code.getInstructions();
    List<Instruction> instructions = ins.getInstructions();
    for (int i = 0; i < instructions.size() - 1; ++i) {
        Instruction i1 = instructions.get(i), i2 = instructions.get(i + 1);
        if (!(i1 instanceof Goto)) {
            continue;
        }
        Goto g = (Goto) i1;
        assert g.getJumps().size() == 1;
        if (g.getJumps().get(0) != i2) {
            continue;
        }
        // remove jump
        ins.remove(i1);
        ++removedJumps;
    // i now points to i2, so next loop we go to next instruction
    }
}
Also used : Goto(net.runelite.asm.attributes.code.instructions.Goto) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)109 Instructions (net.runelite.asm.attributes.code.Instructions)69 Code (net.runelite.asm.attributes.Code)48 LDC (net.runelite.asm.attributes.code.instructions.LDC)39 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)32 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)32 ClassGroup (net.runelite.asm.ClassGroup)31 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)29 IMul (net.runelite.asm.attributes.code.instructions.IMul)28 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)28 Test (org.junit.Test)27 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)25 Method (net.runelite.asm.Method)24 IStore (net.runelite.asm.attributes.code.instructions.IStore)24 Execution (net.runelite.asm.execution.Execution)23 Deobfuscator (net.runelite.deob.Deobfuscator)22 Label (net.runelite.asm.attributes.code.Label)19 ArrayList (java.util.ArrayList)17 InstructionContext (net.runelite.asm.execution.InstructionContext)17 Field (net.runelite.asm.Field)16