Search in sources :

Example 81 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class OpcodeReplacer method run.

public void run(ClassGroup group, Collection<PacketWrite> writes) {
    int count = 0;
    ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
    assert runeliteOpcodes != null : "Opcodes class must exist";
    for (PacketWrite wp : writes) {
        Instructions ins = wp.getInstructions();
        Instruction param = wp.getOpcodeIns();
        if (!(param instanceof PushConstantInstruction)) {
            continue;
        }
        final String fieldName = "PACKET_CLIENT_" + wp.getOpcode();
        net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(RUNELITE_OPCODES), fieldName, Type.INT);
        ins.replace(param, new GetStatic(ins, field));
        if (runeliteOpcodes.findField(fieldName) == null) {
            Field opField = new Field(runeliteOpcodes, fieldName, Type.INT);
            // ACC_FINAL causes javac to inline the fields, which prevents
            // the mapper from doing field mapping
            opField.setAccessFlags(ACC_PUBLIC | ACC_STATIC);
            // setting a non-final static field value
            // doesn't work with fernflower
            opField.setValue(wp.getOpcode());
            runeliteOpcodes.addField(opField);
            // add initialization
            Method clinit = runeliteOpcodes.findMethod("<clinit>");
            assert clinit != null;
            Instructions instructions = clinit.getCode().getInstructions();
            instructions.addInstruction(0, new LDC(instructions, wp.getOpcode()));
            instructions.addInstruction(1, new PutStatic(instructions, opField));
        }
        ++count;
    }
    logger.info("Injected {} packet writes", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Example 82 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class UnusedFields method run.

@Override
public void run(ClassGroup group) {
    checkForFieldUsage(group);
    int count = 0;
    for (ClassFile cf : group.getClasses()) for (Field f : new ArrayList<>(cf.getFields())) if (!used.contains(f)) {
        cf.removeField(f);
        ++count;
    }
    logger.info("Removed " + count + " unused fields");
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile)

Example 83 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class UnusedParameters method buildUnused.

private void buildUnused(ClassGroup group) {
    unused.clear();
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            if (!Deob.isObfuscated(m.getName())) {
                continue;
            }
            List<Method> ms = VirtualMethods.getVirtualMethods(m);
            Collection<Integer> u = this.findUnusedParameters(ms);
            if (!u.isEmpty()) {
                unused.put(ms, u);
            }
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 84 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class ClassGroupFactory method generateGroup.

public static ClassGroup generateGroup() {
    ClassGroup group = new ClassGroup();
    ClassFile cf = new ClassFile(group);
    cf.setName("test");
    cf.setSuperName("java/lang/Object");
    group.addClass(cf);
    Field field = new Field(cf, "field", Type.INT);
    field.setStatic();
    cf.addField(field);
    Method method = new Method(cf, "func", new Signature("()V"));
    method.setStatic();
    cf.addMethod(method);
    Code code = new Code(method);
    method.setCode(code);
    {
        method = new Method(cf, "func2", new Signature("(III)V"));
        method.setStatic();
        cf.addMethod(method);
        code = new Code(method);
        method.setCode(code);
        Instructions ins = code.getInstructions();
        ins.addInstruction(new VReturn(ins));
    }
    addVoidMethod(cf, "void1");
    addVoidMethod(cf, "void2");
    addVoidMethod(cf, "void3");
    addVoidMethod(cf, "void4");
    return group;
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Signature(net.runelite.asm.signature.Signature) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 85 with ClassFile

use of net.runelite.asm.ClassFile in project runelite by runelite.

the class Inject method deobfuscatedTypeToApiType.

Type deobfuscatedTypeToApiType(Type type) throws InjectionException {
    if (type.isPrimitive()) {
        return type;
    }
    ClassFile cf = deobfuscated.findClass(type.getInternalName());
    if (cf == null) {
        // not my type
        return type;
    }
    java.lang.Class<?> rsApiType;
    try {
        rsApiType = java.lang.Class.forName(API_PACKAGE_BASE + cf.getName().replace("/", "."));
    } catch (ClassNotFoundException ex) {
        throw new InjectionException("Deobfuscated type " + type.getInternalName() + " has no API type", ex);
    }
    java.lang.Class<?> rlApiType = null;
    for (java.lang.Class<?> inter : rsApiType.getInterfaces()) {
        if (inter.getName().startsWith(RL_API_PACKAGE_BASE)) {
            rlApiType = inter;
        }
    }
    if (rlApiType == null) {
        throw new InjectionException("RS API type " + rsApiType + " does not extend RL API interface");
    }
    return Type.getType("L" + rlApiType.getName().replace('.', '/') + ";", type.getDimensions());
}
Also used : ClassFile(net.runelite.asm.ClassFile)

Aggregations

ClassFile (net.runelite.asm.ClassFile)103 Method (net.runelite.asm.Method)62 Field (net.runelite.asm.Field)39 ClassGroup (net.runelite.asm.ClassGroup)32 Code (net.runelite.asm.attributes.Code)21 Instruction (net.runelite.asm.attributes.code.Instruction)18 Test (org.junit.Test)18 Signature (net.runelite.asm.signature.Signature)17 Type (net.runelite.asm.Type)16 Instructions (net.runelite.asm.attributes.code.Instructions)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)9 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)9 HashMap (java.util.HashMap)8 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)7