Search in sources :

Example 71 with Instructions

use of net.runelite.asm.attributes.code.Instructions 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 72 with Instructions

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

the class IfICmpEqTest method testIsSame.

@Test
public void testIsSame() {
    Instructions ins = mock(Instructions.class);
    Frame frame = mock(Frame.class);
    Stack stack = new Stack(42);
    Variables variables = new Variables(42);
    when(frame.getStack()).thenReturn(stack);
    when(frame.getVariables()).thenReturn(variables);
    IfICmpEq ifeq = new IfICmpEq(ins, InstructionType.IF_ICMPEQ);
    InstructionContext ifeqCtx = new InstructionContext(ifeq, frame);
    ifeqCtx.pop(new StackContext(getConstantCtx(ins, 1), INT, new Value(1)));
    ifeqCtx.pop(new StackContext(getConstantCtx(ins, 1), INT, new Value(1)));
    IfNe ifne = new IfNe(ins, InstructionType.IFNE);
    InstructionContext ifneCtx = new InstructionContext(ifne, frame);
    ifneCtx.pop(new StackContext(getConstantCtx(ins, 42), INT, new Value(42)));
    assertTrue(ifeq.isSame(ifeqCtx, ifneCtx));
}
Also used : Variables(net.runelite.asm.execution.Variables) InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) StackContext(net.runelite.asm.execution.StackContext) Value(net.runelite.asm.execution.Value) Instructions(net.runelite.asm.attributes.code.Instructions) Stack(net.runelite.asm.execution.Stack) Test(org.junit.Test)

Example 73 with Instructions

use of net.runelite.asm.attributes.code.Instructions 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)

Example 74 with Instructions

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

the class PacketLengthFinder method run.

// getstatic             class272/field3690 [I
// getstatic             Client/packetType I
// iaload
// putstatic             Client/packetLength I
private void run(Code code) {
    if (code == null) {
        return;
    }
    Instructions instructions = code.getInstructions();
    Field type = packetType.getPacketType();
    for (int i = 0; i < instructions.getInstructions().size() - 3; ++i) {
        Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1), i3 = instructions.getInstructions().get(i + 2), i4 = instructions.getInstructions().get(i + 3);
        if (!(i1 instanceof GetStatic)) {
            continue;
        }
        if (!(i2 instanceof GetStatic)) {
            continue;
        }
        GetStatic gs = (GetStatic) i2;
        if (gs.getMyField() != type) {
            continue;
        }
        if (!(i3 instanceof IALoad)) {
            continue;
        }
        if (!(i4 instanceof PutStatic)) {
            continue;
        }
        PutStatic ps = (PutStatic) i4;
        assert packetLength == null : "packetLength already found";
        packetLength = ps.getMyField();
        getArray = (GetStatic) i1;
        getType = gs;
        load = (IALoad) i3;
        store = ps;
        return;
    }
}
Also used : Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) IALoad(net.runelite.asm.attributes.code.instructions.IALoad) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

Example 75 with Instructions

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

the class PacketTypeFinder method run.

private void run(Code code) {
    if (code == null) {
        return;
    }
    Instructions instructions = code.getInstructions();
    for (int i = 0; i < instructions.getInstructions().size() - 1; ++i) {
        Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1);
        if (i1 instanceof PushConstantInstruction && i2.getType() == InstructionType.PUTSTATIC) {
            PushConstantInstruction pci = (PushConstantInstruction) i1;
            SetFieldInstruction sfi = (SetFieldInstruction) i2;
            Field field = sfi.getMyField();
            if (Objects.equal(-1, pci.getConstant()) && field != null) {
                Integer count = sets.get(field);
                if (count == null) {
                    sets.put(field, 1);
                } else {
                    sets.put(field, count + 1);
                }
            }
        }
    }
}
Also used : Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction)

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