Search in sources :

Example 1 with New

use of net.runelite.asm.attributes.code.instructions.New in project runelite by runelite.

the class MaxMemoryTransformer method insert.

private void insert(Instructions ins, int idx) {
    Class randomClass = new net.runelite.asm.pool.Class("java/util/Random");
    ins.getInstructions().remove(idx);
    // pop runtime
    ins.getInstructions().add(idx++, new Pop(ins));
    ins.getInstructions().add(idx++, new New(ins, randomClass));
    ins.getInstructions().add(idx++, new Dup(ins));
    // new Random
    ins.getInstructions().add(idx++, new InvokeSpecial(ins, new net.runelite.asm.pool.Method(randomClass, "<init>", new Signature("()V"))));
    ins.getInstructions().add(idx++, new LDC(ins, 31457280));
    // nextInt(31457280)
    ins.getInstructions().add(idx++, new InvokeVirtual(ins, new net.runelite.asm.pool.Method(randomClass, "nextInt", new Signature("(I)I"))));
    ins.getInstructions().add(idx++, new LDC(ins, 230686720));
    // 230686720 + nextInt(31457280)
    ins.getInstructions().add(idx++, new IAdd(ins));
    ins.getInstructions().add(idx++, new I2L(ins));
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) I2L(net.runelite.asm.attributes.code.instructions.I2L) InvokeSpecial(net.runelite.asm.attributes.code.instructions.InvokeSpecial) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) Pop(net.runelite.asm.attributes.code.instructions.Pop) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Class(net.runelite.asm.pool.Class) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Example 2 with New

use of net.runelite.asm.attributes.code.instructions.New in project runelite by runelite.

the class IllegalStateExceptions method findInteresting.

/* find if, new, ..., athrow, replace with goto */
private void findInteresting(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null)
                continue;
            Instructions instructions = c.getInstructions();
            List<Instruction> ilist = instructions.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction ins = ilist.get(i);
                if (// the if
                !(ins instanceof ComparisonInstruction))
                    continue;
                Instruction ins2 = ilist.get(i + 1);
                if (!(ins2 instanceof New))
                    continue;
                New new2 = (New) ins2;
                net.runelite.asm.pool.Class clazz = new2.getNewClass();
                if (!clazz.getName().contains("java/lang/IllegalStateException"))
                    continue;
                interesting.add(ins);
            }
        }
    }
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) ClassFile(net.runelite.asm.ClassFile) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 3 with New

use of net.runelite.asm.attributes.code.instructions.New in project runelite by runelite.

the class InjectConstruct method injectConstruct.

public void injectConstruct(ClassFile targetClass, java.lang.reflect.Method apiMethod) throws InjectionException {
    logger.info("Injecting construct for {}", apiMethod);
    assert targetClass.findMethod(apiMethod.getName()) == null;
    Class<?> typeToConstruct = apiMethod.getReturnType();
    ClassFile vanillaClass = inject.findVanillaForInterface(typeToConstruct);
    if (vanillaClass == null) {
        throw new InjectionException("Unable to find vanilla class which implements interface " + typeToConstruct);
    }
    Signature sig = inject.javaMethodToSignature(apiMethod);
    Signature constructorSig = new Signature.Builder().addArguments(Stream.of(apiMethod.getParameterTypes()).map(arg -> {
        ClassFile vanilla = inject.findVanillaForInterface(arg);
        if (vanilla != null) {
            return new Type("L" + vanilla.getName() + ";");
        }
        return Inject.classToType(arg);
    }).collect(Collectors.toList())).setReturnType(Type.VOID).build();
    Method vanillaConstructor = vanillaClass.findMethod("<init>", constructorSig);
    if (vanillaConstructor == null) {
        throw new InjectionException("Unable to find constructor for " + vanillaClass.getName() + ".<init>" + constructorSig);
    }
    Method setterMethod = new Method(targetClass, apiMethod.getName(), sig);
    setterMethod.setAccessFlags(ACC_PUBLIC);
    targetClass.addMethod(setterMethod);
    Code code = new Code(setterMethod);
    setterMethod.setCode(code);
    Instructions instructions = code.getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    ins.add(new New(instructions, vanillaClass.getPoolClass()));
    ins.add(new Dup(instructions));
    int idx = 1;
    int parameter = 0;
    for (Type type : vanillaConstructor.getDescriptor().getArguments()) {
        Instruction load = inject.createLoadForTypeIndex(instructions, type, idx);
        idx += type.getSize();
        ins.add(load);
        Type paramType = sig.getTypeOfArg(parameter);
        if (!type.equals(paramType)) {
            CheckCast checkCast = new CheckCast(instructions);
            checkCast.setType(type);
            ins.add(checkCast);
        }
        ++parameter;
    }
    ins.add(new InvokeSpecial(instructions, vanillaConstructor.getPoolMethod()));
    ins.add(new Return(instructions));
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) ClassFile(net.runelite.asm.ClassFile) Return(net.runelite.asm.attributes.code.instructions.Return) InvokeSpecial(net.runelite.asm.attributes.code.instructions.InvokeSpecial) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) CheckCast(net.runelite.asm.attributes.code.instructions.CheckCast) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Type(net.runelite.asm.Type) Signature(net.runelite.asm.signature.Signature) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Aggregations

Method (net.runelite.asm.Method)3 New (net.runelite.asm.attributes.code.instructions.New)3 ClassFile (net.runelite.asm.ClassFile)2 Code (net.runelite.asm.attributes.Code)2 Instruction (net.runelite.asm.attributes.code.Instruction)2 Instructions (net.runelite.asm.attributes.code.Instructions)2 Dup (net.runelite.asm.attributes.code.instructions.Dup)2 InvokeSpecial (net.runelite.asm.attributes.code.instructions.InvokeSpecial)2 Signature (net.runelite.asm.signature.Signature)2 Type (net.runelite.asm.Type)1 ComparisonInstruction (net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction)1 JumpingInstruction (net.runelite.asm.attributes.code.instruction.types.JumpingInstruction)1 CheckCast (net.runelite.asm.attributes.code.instructions.CheckCast)1 I2L (net.runelite.asm.attributes.code.instructions.I2L)1 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)1 InvokeVirtual (net.runelite.asm.attributes.code.instructions.InvokeVirtual)1 LDC (net.runelite.asm.attributes.code.instructions.LDC)1 Pop (net.runelite.asm.attributes.code.instructions.Pop)1 Return (net.runelite.asm.attributes.code.instructions.Return)1 Class (net.runelite.asm.pool.Class)1