Search in sources :

Example 26 with Instructions

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

the class PacketHandlerOrder method insertPacketLength.

private void insertPacketLength(ClassGroup group, PacketTypeFinder ptf) {
    PacketLengthFinder pfl = new PacketLengthFinder(group, ptf);
    pfl.find();
    GetStatic getArray = pfl.getGetArray();
    // instruction to store packet length
    PutStatic ps = pfl.getStore();
    Instructions instructions = ps.getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    Label getArrayLabel = instructions.createLabelFor(getArray);
    Label storeLabel = instructions.createLabelFor(ps);
    int idx = ins.indexOf(getArray);
    assert idx != -1;
    // to go before label, which must exist
    --idx;
    net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
    instructions.addInstruction(idx++, new GetStatic(instructions, field));
    instructions.addInstruction(idx++, new IfEq(instructions, getArrayLabel));
    // 2 byte length
    instructions.addInstruction(idx++, new LDC(instructions, -2));
    instructions.addInstruction(idx++, new Goto(instructions, storeLabel));
}
Also used : Goto(net.runelite.asm.attributes.code.instructions.Goto) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) PacketLengthFinder(net.runelite.deob.deobfuscators.packethandler.PacketLengthFinder) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) MappableInstruction(net.runelite.asm.attributes.code.instruction.types.MappableInstruction) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Example 27 with Instructions

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

the class UnreachedCode method removeUnused.

private int removeUnused(Method m) {
    Instructions ins = m.getCode().getInstructions();
    int count = 0;
    List<Instruction> insCopy = new ArrayList<>(ins.getInstructions());
    for (int j = 0; j < insCopy.size(); ++j) {
        Instruction i = insCopy.get(j);
        if (!execution.executed.contains(i)) {
            // if this is an exception handler, the exception handler is never used...
            for (net.runelite.asm.attributes.code.Exception e : new ArrayList<>(m.getCode().getExceptions().getExceptions())) {
                if (e.getStart().next() == i) {
                    e.setStart(ins.createLabelFor(insCopy.get(j + 1)));
                    if (e.getStart().next() == e.getEnd().next()) {
                        m.getCode().getExceptions().remove(e);
                        continue;
                    }
                }
                if (e.getHandler().next() == i) {
                    m.getCode().getExceptions().remove(e);
                }
            }
            if (i instanceof Label)
                continue;
            ins.remove(i);
            ++count;
        }
    }
    return count;
}
Also used : ArrayList(java.util.ArrayList) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction)

Example 28 with Instructions

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

the class DupDeobfuscator method undup2_x1.

private void undup2_x1(InstructionContext ictx) {
    assert ictx.getInstruction() instanceof Dup2_X1;
    // only support this form
    assert ictx.getPops().size() == 2;
    // I L -> L I L
    Instructions instructions = ictx.getInstruction().getInstructions();
    // can't swap a long on the stack, so
    int idx = instructions.getInstructions().indexOf(ictx.getInstruction());
    assert idx != -1;
    // remove dup2_x1
    instructions.remove(ictx.getInstruction());
    // pop long
    instructions.addInstruction(idx++, new Pop2(instructions));
    // pop int
    instructions.addInstruction(idx++, new Pop(instructions));
    // insert copy of long
    idx = copy(ictx.getPops().get(0), instructions, idx);
    // insert copy of int
    idx = copy(ictx.getPops().get(1), instructions, idx);
    // insert copy of long
    /* idx = */
    copy(ictx.getPops().get(0), instructions, idx);
}
Also used : Pop(net.runelite.asm.attributes.code.instructions.Pop) Dup2_X1(net.runelite.asm.attributes.code.instructions.Dup2_X1) Pop2(net.runelite.asm.attributes.code.instructions.Pop2) Instructions(net.runelite.asm.attributes.code.Instructions)

Example 29 with Instructions

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

the class DupDeobfuscator method undup_x1.

private void undup_x1(InstructionContext ictx) {
    assert ictx.getInstruction() instanceof Dup_X1;
    Instructions instructions = ictx.getInstruction().getInstructions();
    StackContext duplicated = ictx.getPops().get(0);
    // replace dup_x1 with swap
    int idx = instructions.replace(ictx.getInstruction(), new Swap(instructions));
    // copy imul and insert after idx
    copy(duplicated, instructions, idx + 1);
}
Also used : Swap(net.runelite.asm.attributes.code.instructions.Swap) StackContext(net.runelite.asm.execution.StackContext) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) Instructions(net.runelite.asm.attributes.code.Instructions)

Example 30 with Instructions

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

the class DupDeobfuscator method undup.

private void undup(InstructionContext ictx) {
    assert ictx.getInstruction() instanceof Dup;
    Instructions instructions = ictx.getInstruction().getInstructions();
    StackContext duplicated = ictx.getPops().get(0);
    int idx = instructions.getInstructions().indexOf(ictx.getInstruction());
    assert idx != -1;
    // replace dup with duplicated instructions
    instructions.remove(ictx.getInstruction());
    // insert copy
    copy(duplicated, instructions, idx);
}
Also used : StackContext(net.runelite.asm.execution.StackContext) Instructions(net.runelite.asm.attributes.code.Instructions) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Aggregations

Instructions (net.runelite.asm.attributes.code.Instructions)86 Instruction (net.runelite.asm.attributes.code.Instruction)72 Code (net.runelite.asm.attributes.Code)47 LDC (net.runelite.asm.attributes.code.instructions.LDC)40 ClassGroup (net.runelite.asm.ClassGroup)32 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)30 Test (org.junit.Test)30 Method (net.runelite.asm.Method)26 IMul (net.runelite.asm.attributes.code.instructions.IMul)26 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)24 IStore (net.runelite.asm.attributes.code.instructions.IStore)24 Execution (net.runelite.asm.execution.Execution)22 Deobfuscator (net.runelite.deob.Deobfuscator)22 ClassFile (net.runelite.asm.ClassFile)17 Field (net.runelite.asm.Field)17 Type (net.runelite.asm.Type)17 Label (net.runelite.asm.attributes.code.Label)17 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)16 Signature (net.runelite.asm.signature.Signature)16 Pop (net.runelite.asm.attributes.code.instructions.Pop)14