Search in sources :

Example 31 with Signature

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

the class MappingDumper method dump.

@Test
public void dump() throws IOException {
    ClassGroup group = JarUtil.loadJar(new File(properties.getRsClient()));
    final String GAP = "%-40s";
    int classes = 0, methods = 0, fields = 0;
    StringBuilder mBuilder = new StringBuilder();
    StringBuilder sBuilder = new StringBuilder();
    StringBuilder tmp;
    for (ClassFile cf : group.getClasses()) {
        String implName = DeobAnnotations.getImplements(cf);
        String className = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
        if (implName != null) {
            mBuilder.append("\n").append(implName).append(" -> ").append(className).append("\n");
            ++classes;
        }
        for (Field f : cf.getFields()) {
            String exportName = DeobAnnotations.getExportedName(f.getAnnotations());
            if (exportName == null) {
                continue;
            }
            ++fields;
            String fieldName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
            Type type = f.getType();
            Number getter = DeobAnnotations.getObfuscatedGetter(f);
            String fieldType = typeToString(type);
            if (f.isStatic()) {
                tmp = sBuilder;
            } else {
                tmp = mBuilder;
            }
            tmp.append("\t").append(String.format(GAP, fieldType)).append(String.format(GAP, exportName)).append(className).append(".").append(fieldName);
            if (getter != null) {
                tmp.append(" * ").append(getter).append("\n");
            } else {
                tmp.append("\n");
            }
        }
        for (Method m : cf.getMethods()) {
            String exportName = DeobAnnotations.getExportedName(m.getAnnotations());
            if (exportName == null) {
                continue;
            }
            methods++;
            String methodName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
            Signature signature = DeobAnnotations.getObfuscatedSignature(m);
            String garbageValue = DeobAnnotations.getObfuscatedValue(m);
            if (signature == null) {
                signature = m.getDescriptor();
            }
            String returnType = typeToString(m.getDescriptor().getReturnValue());
            String[] paramTypes = new String[signature.size()];
            for (int i = 0; i < paramTypes.length; i++) {
                paramTypes[i] = typeToString(signature.getTypeOfArg(i));
            }
            if (m.isStatic()) {
                tmp = sBuilder;
            } else {
                tmp = mBuilder;
            }
            tmp.append("\t").append(String.format(GAP, returnType)).append(String.format(GAP, exportName)).append(className).append(".").append(methodName);
            tmp.append("(");
            for (int i = 0; i < paramTypes.length; i++) {
                tmp.append(paramTypes[i]);
                if (i == paramTypes.length - 1) {
                    if (garbageValue != null) {
                        tmp.append(" = ").append(garbageValue);
                    }
                } else {
                    tmp.append(", ");
                }
            }
            tmp.append(")\n");
        }
    }
    System.out.println("RuneLite http://github.com/runelite");
    System.out.println("Run " + Instant.now());
    System.out.println("Classes: " + classes + ", methods: " + methods + ", fields: " + fields);
    System.out.println("Gamepack " + properties.getRsVersion());
    System.out.println(mBuilder.toString());
    System.out.println("Static ->");
    System.out.println(sBuilder.toString());
}
Also used : Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method) File(java.io.File) ClassFile(net.runelite.asm.ClassFile) Test(org.junit.Test)

Example 32 with Signature

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

the class ReflectionTransformer method transformFindClass.

// invokestatic          java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
// to
// invokestatic          net/runelite/rs/Reflection/findClass(Ljava/lang/String;)Ljava/lang/Class;
private void transformFindClass(Instruction i) {
    if (!(i instanceof InvokeStatic)) {
        return;
    }
    InvokeStatic is = (InvokeStatic) i;
    if (is.getMethod().getClazz().getName().equals("java/lang/Class") && is.getMethod().getName().equals("forName")) {
        is.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "findClass", new Signature("(Ljava/lang/String;)Ljava/lang/Class;")));
        logger.info("Transformed Class.forName call");
    }
}
Also used : Signature(net.runelite.asm.signature.Signature) InvokeStatic(net.runelite.asm.attributes.code.instructions.InvokeStatic)

Example 33 with Signature

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

the class ReflectionTransformer method transformMethodName.

// invokevirtual         java/lang/reflect/Method/getName()Ljava/lang/String;
// to
// invokestatic          net/runelite/rs/Reflection/getMethodName(Ljava/lang/reflect/Method;)Ljava/lang/String;
private void transformMethodName(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("getName")) {
        InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "getMethodName", new Signature("(Ljava/lang/reflect/Method;)Ljava/lang/String;")));
        instructions.replace(iv, is);
        logger.info("Transformed Method.getName 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 34 with Signature

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

the class ReflectionTransformer method transformGetInt.

// invokevirtual         java/lang/reflect/Field/getInt(Ljava/lang/Object;)I
private void transformGetInt(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("getInt")) {
        InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "getInt", new Signature("(Ljava/lang/reflect/Field;Ljava/lang/Object;)I")));
        instructions.replace(iv, is);
        logger.info("Transformed Field.getInt 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 35 with Signature

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

the class ReflectionTransformer method transformGetDeclaredField.

// invokevirtual         java/lang/Class/getDeclaredField(Ljava/lang/String;)Ljava/lang/reflect/Field;
// to
// invokestatic          net/runelite/rs/Reflection/findField
private void transformGetDeclaredField(Instructions instructions, Instruction i) {
    if (!(i instanceof InvokeVirtual)) {
        return;
    }
    InvokeVirtual iv = (InvokeVirtual) i;
    if (iv.getMethod().getClazz().getName().equals("java/lang/Class") && iv.getMethod().getName().equals("getDeclaredField")) {
        InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "findField", new Signature("(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Field;")));
        instructions.replace(iv, is);
        logger.info("Transformed Class.getDeclaredField 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)

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