Search in sources :

Example 1 with RWOpcodeFinder

use of net.runelite.deob.c2s.RWOpcodeFinder in project runelite by runelite.

the class RuneliteBufferTransformer method injectLengthHeader.

/**
 * inject the length header after the packet opcode
 *
 * @param group
 */
private void injectLengthHeader(ClassGroup group) {
    RWOpcodeFinder rw = new RWOpcodeFinder(group);
    rw.find();
    Method writeOpcode = rw.getWriteOpcode();
    Code code = writeOpcode.getCode();
    Instructions instructions = code.getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    Instruction start = ins.get(0);
    Instruction end = ins.stream().filter(i -> i.getType() == RETURN).findFirst().get();
    Label labelForStart = instructions.createLabelFor(start);
    Label labelForEnd = instructions.createLabelFor(end);
    final net.runelite.asm.pool.Field runelitePacketField = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
    int idx = ins.indexOf(labelForStart);
    instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
    instructions.addInstruction(idx++, new IfEq(instructions, labelForStart));
    net.runelite.asm.pool.Method method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_FINISH_PACKET, new Signature("()V"));
    instructions.addInstruction(idx++, new ALoad(instructions, 0));
    instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
    idx = ins.indexOf(labelForEnd);
    instructions.addInstruction(idx++, new GetStatic(instructions, runelitePacketField));
    instructions.addInstruction(idx++, new IfEq(instructions, labelForEnd));
    method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(writeOpcode.getClassFile().getName()), RUNELITE_INIT_PACKET, new Signature("()V"));
    instructions.addInstruction(idx++, new ALoad(instructions, 0));
    instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
    logger.info("Injected finish/init packet calls into {}", writeOpcode);
}
Also used : RWOpcodeFinder(net.runelite.deob.c2s.RWOpcodeFinder) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) ALoad(net.runelite.asm.attributes.code.instructions.ALoad)

Example 2 with RWOpcodeFinder

use of net.runelite.deob.c2s.RWOpcodeFinder in project runelite by runelite.

the class PacketWriteDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    rw = new RWOpcodeFinder(group);
    rw.find();
    Execution e = new Execution(group);
    e.addExecutionVisitor(this::visit);
    e.populateInitialMethods();
    e.run();
    end();
    opcodeReplacer.run(group, writes.values());
    int count = 0;
    int writesCount = 0;
    for (PacketWrite write : writes.values()) {
        if (write.writes.isEmpty()) {
            continue;
        }
        insert(group, write);
        ++count;
        writesCount += write.writes.size();
    }
    logger.info("Converted buffer write methods for {} opcodes ({} writes)", count, writesCount);
}
Also used : Execution(net.runelite.asm.execution.Execution) RWOpcodeFinder(net.runelite.deob.c2s.RWOpcodeFinder)

Aggregations

RWOpcodeFinder (net.runelite.deob.c2s.RWOpcodeFinder)2 Field (net.runelite.asm.Field)1 Method (net.runelite.asm.Method)1 Code (net.runelite.asm.attributes.Code)1 Instruction (net.runelite.asm.attributes.code.Instruction)1 Instructions (net.runelite.asm.attributes.code.Instructions)1 Label (net.runelite.asm.attributes.code.Label)1 ALoad (net.runelite.asm.attributes.code.instructions.ALoad)1 GetStatic (net.runelite.asm.attributes.code.instructions.GetStatic)1 IfEq (net.runelite.asm.attributes.code.instructions.IfEq)1 InvokeVirtual (net.runelite.asm.attributes.code.instructions.InvokeVirtual)1 Execution (net.runelite.asm.execution.Execution)1 Signature (net.runelite.asm.signature.Signature)1