Search in sources :

Example 36 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class ReflectionTransformer method transformSetInt.

// invokevirtual         java/lang/reflect/Field/setInt(Ljava/lang/Object;I)V
private void transformSetInt(Instructions instructions, Instruction i) {
    if (!(i instanceof InvokeVirtual)) {
        return;
    }
    InvokeVirtual iv = (InvokeVirtual) i;
    if (iv.getMethod().getClazz().getName().equals("java/lang/reflect/Field") && iv.getMethod().getName().equals("setInt")) {
        InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "setInt", new Signature("(Ljava/lang/reflect/Field;Ljava/lang/Object;I)V")));
        instructions.replace(iv, is);
        logger.info("Transformed Field.setInt call");
    }
}
Also used : InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) InvokeStatic(net.runelite.asm.attributes.code.instructions.InvokeStatic)

Example 37 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class ReflectionTransformer method transformGetParameterTypes.

// invokevirtual         java/lang/reflect/Method/getParameterTypes()[Ljava/lang/Class;
// to
// invokestatic          net/runelite/rs/Reflection/getParameterTypes(Ljava/lang/reflect/Method;)[Ljava/lang/Class;
private void transformGetParameterTypes(Instructions instructions, Instruction i) {
    if (!(i instanceof InvokeVirtual)) {
        return;
    }
    InvokeVirtual iv = (InvokeVirtual) i;
    if (iv.getMethod().getClazz().getName().equals("java/lang/reflect/Method") && iv.getMethod().getName().equals("getParameterTypes")) {
        InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "getParameterTypes", new Signature("(Ljava/lang/reflect/Method;)[Ljava/lang/Class;")));
        instructions.replace(iv, is);
        logger.info("Transformed Method.getParameterTypes call");
    }
}
Also used : InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) InvokeStatic(net.runelite.asm.attributes.code.instructions.InvokeStatic)

Example 38 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class RuneliteBufferTransformer method injectPacketFinish.

private void injectPacketFinish(ClassGroup group) {
    PacketFlushFinder pff = new PacketFlushFinder(group);
    pff.find();
    for (InstructionContext queueForWriteCtx : pff.getQueueForWrite()) {
        Instruction before = // socket
        queueForWriteCtx.getPops().get(3).getPushed().getInstruction();
        GetStatic getBuffer;
        try {
            getBuffer = (GetStatic) // buffer
            queueForWriteCtx.getPops().get(2).getPushed().getPops().get(// getstatic
            0).getPushed().getInstruction();
        } catch (ClassCastException ex) {
            continue;
        }
        Instructions instructions = before.getInstructions();
        int idx = instructions.getInstructions().indexOf(before);
        assert idx != -1;
        instructions.addInstruction(idx++, getBuffer.clone());
        net.runelite.asm.pool.Method method = new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(getBuffer.getField().getType().getInternalName()), RUNELITE_FINISH_PACKET, new Signature("()V"));
        instructions.addInstruction(idx++, new InvokeVirtual(instructions, method));
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) PacketFlushFinder(net.runelite.deob.deobfuscators.transformers.buffer.PacketFlushFinder) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature)

Example 39 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class PacketFlushFinder method find.

private void find(Method method) {
    Code code = method.getCode();
    Set<Instruction> checked = new HashSet<>();
    Execution e = new Execution(group);
    e.addMethod(method);
    e.noInvoke = true;
    e.noExceptions = true;
    e.addExecutionVisitor(ic -> {
        Instruction i = ic.getInstruction();
        if (checked.contains(i)) {
            return;
        }
        checked.add(i);
        if (i.getType() != INVOKEVIRTUAL) {
            return;
        }
        InvokeVirtual iv = (InvokeVirtual) i;
        // queueForWrite
        if (!iv.getMethod().getType().equals(new Signature("([BII)V"))) {
            return;
        }
        InstructionContext lengthCtx = ic.getPops().get(0).getPushed();
        if (lengthCtx.getInstruction().getType() != GETFIELD) {
            return;
        }
        queueForWrite.add(ic);
    });
    e.run();
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) HashSet(java.util.HashSet)

Example 40 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class ConstructorMapper method mapConstructors.

/**
 * Map constructors based on the class mappings of the given mapping
 */
public void mapConstructors() {
    for (ClassFile cf : source.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(cf);
        if (other == null) {
            continue;
        }
        for (Method m : cf.getMethods()) {
            if (!m.getName().equals("<init>")) {
                continue;
            }
            Signature otherSig = toOtherSignature(m.getDescriptor());
            if (otherSig == null) {
                continue;
            }
            logger.debug("Converted signature {} -> {}", m.getDescriptor(), otherSig);
            Method m2 = other.findMethod(m.getName(), otherSig);
            if (m2 == null) {
                logger.warn("Unable to find other constructor for {}, looking for signature {} on class {}", m, otherSig, other);
                continue;
            }
            ParallelExecutorMapping p = MappingExecutorUtil.map(m, m2);
            p.map(null, m, m2);
            mapping.merge(p);
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Aggregations

Signature (net.runelite.asm.signature.Signature)51 Method (net.runelite.asm.Method)29 ClassFile (net.runelite.asm.ClassFile)17 Type (net.runelite.asm.Type)16 Instruction (net.runelite.asm.attributes.code.Instruction)16 InvokeVirtual (net.runelite.asm.attributes.code.instructions.InvokeVirtual)16 Code (net.runelite.asm.attributes.Code)15 Instructions (net.runelite.asm.attributes.code.Instructions)15 InvokeStatic (net.runelite.asm.attributes.code.instructions.InvokeStatic)14 Field (net.runelite.asm.Field)10 ClassGroup (net.runelite.asm.ClassGroup)8 ALoad (net.runelite.asm.attributes.code.instructions.ALoad)8 LDC (net.runelite.asm.attributes.code.instructions.LDC)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)7 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)6 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)6 GetStatic (net.runelite.asm.attributes.code.instructions.GetStatic)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)5