Search in sources :

Example 91 with Instruction

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

the class ExprArgOrder method canRemove.

private boolean canRemove(MethodContext mctx, Instructions ins, Instruction i) {
    Set<InstructionContext> ctxs = new HashSet<>(mctx.getInstructonContexts(i));
    if (!alwaysPoppedBySameInstruction(ctxs, i) || !alwaysPopsFromSameInstructions(ctxs, i)) {
        return false;
    }
    if (i instanceof InvokeInstruction) {
        // func1() + func2() vs func2() + func1() is not the same thing
        return false;
    }
    int idx = ins.getInstructions().indexOf(i);
    if (idx == -1) {
        return false;
    }
    for (InstructionContext ictx : ctxs) {
        for (StackContext sctx : ictx.getPops()) {
            Instruction pushed = sctx.getPushed().getInstruction();
            int idx2 = ins.getInstructions().indexOf(pushed);
            if (idx2 == -1) {
                return false;
            }
            assert idx > idx2;
            // instructions, we can't move them
            for (int j = idx2; j <= idx; ++j) {
                Instruction i2 = ins.getInstructions().get(j);
                if (i2 instanceof LVTInstruction) {
                    if (((LVTInstruction) i2).store()) {
                        return false;
                    }
                }
                if (i2 instanceof IInc) {
                    return false;
                }
            }
            if (!canRemove(mctx, ins, pushed)) {
                return false;
            }
        }
    }
    return true;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) StackContext(net.runelite.asm.execution.StackContext) IInc(net.runelite.asm.attributes.code.instructions.IInc) 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) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) HashSet(java.util.HashSet)

Example 92 with Instruction

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

the class ExprArgOrder method insert.

private void insert(Instructions ins, InstructionContext ic, Instruction before) {
    Instruction i = ic.getInstruction();
    assert i.getInstructions() == null;
    int idx = ins.getInstructions().indexOf(before);
    assert idx != -1;
    i.setInstructions(ins);
    ins.addInstruction(idx, i);
}
Also used : 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)

Example 93 with Instruction

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

the class Mapping method merge.

public void merge(Mapping other) {
    assert object == other.object;
    count += other.count;
    for (Instruction i : other.ins) {
        addInstruction(i);
    }
    wasExecuted |= other.wasExecuted;
    weight = Math.max(weight, other.weight);
}
Also used : Instruction(net.runelite.asm.attributes.code.Instruction)

Example 94 with Instruction

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

the class StaticInitializerIndexer method index.

public void index() {
    for (ClassFile cf : group.getClasses()) {
        Method method = cf.findMethod("<clinit>");
        if (method == null) {
            continue;
        }
        Instructions instructions = method.getCode().getInstructions();
        for (Instruction i : instructions.getInstructions()) {
            if (i.getType() != InstructionType.PUTSTATIC) {
                continue;
            }
            PutStatic putstatic = (PutStatic) i;
            if (!putstatic.getField().getClazz().equals(cf.getPoolClass()) || putstatic.getMyField() == null) {
                continue;
            }
            fields.add(putstatic.getMyField());
        }
    }
    logger.debug("Indexed {} statically initialized fields", fields.size());
}
Also used : ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

Example 95 with Instruction

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

the class HandlerFinder method findHandlers.

private List<PacketHandler> findHandlers(Method process, Field packetOpcode) {
    List<PacketHandler> handlers = new ArrayList<>();
    Instructions ins = process.getCode().getInstructions();
    for (int j = 0; j < ins.getInstructions().size(); ++j) {
        Instruction i = ins.getInstructions().get(j);
        if (i.getType() != InstructionType.GETSTATIC) {
            continue;
        }
        GetStatic gs = (GetStatic) i;
        if (gs.getMyField() != packetOpcode) {
            continue;
        }
        Instruction push = ins.getInstructions().get(j + 1);
        if (!(push instanceof PushConstantInstruction)) {
            continue;
        }
        PushConstantInstruction pci = (PushConstantInstruction) push;
        if (!(pci.getConstant() instanceof Number)) {
            continue;
        }
        int opcode = ((Number) pci.getConstant()).intValue();
        if (opcode == -1) {
            continue;
        }
        Instruction jump = ins.getInstructions().get(j + 2);
        if (jump.getType() != InstructionType.IF_ICMPEQ && jump.getType() != InstructionType.IF_ICMPNE) {
            continue;
        }
        Instruction start, end;
        if (jump.getType() == InstructionType.IF_ICMPEQ) {
            // this seems to not ever happen
            start = ((If) jump).getJumps().get(0);
            // end = ins.getInstructions().get(j + 3);
            end = null;
        } else {
            start = ins.getInstructions().get(j + 3);
            end = ((If) jump).getJumps().get(0);
        }
        PacketHandler handler = new PacketHandler(process, jump, start, push, opcode);
        handlers.add(handler);
        if (end != null) {
            // Anything else which jumps to here instead needs to return.
            insertReturn(ins, jump, end);
        }
        logger.info("Found packet handler {} opcode {}", handler, handler.getOpcode());
    }
    return handlers;
}
Also used : GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ArrayList(java.util.ArrayList) Instructions(net.runelite.asm.attributes.code.Instructions) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) If(net.runelite.asm.attributes.code.instructions.If)

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