Search in sources :

Example 56 with Method

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

the class VirtualMethods method getVirtualMethods.

public static List<Method> getVirtualMethods(Method method) {
    List<Method> list = new ArrayList<>();
    if (method.isStatic()) {
        list.add(method);
        return list;
    }
    // base methods method overrides
    List<Method> bases = findBaseMethods(method);
    // must contain at least a method
    assert !bases.isEmpty();
    // now search up from bases, appending to list.
    for (Method m : bases) findMethodUp(list, new HashSet<>(), m.getClassFile(), m.getName(), m.getDescriptor());
    return list;
}
Also used : ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method) HashSet(java.util.HashSet)

Example 57 with Method

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

the class MappingDumper method dumpJson.

@Test
public void dumpJson() throws IOException {
    ClassGroup group = JarUtil.loadJar(new File(properties.getRsClient()));
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    JsonObject jObject = new JsonObject();
    JsonArray jFields = new JsonArray();
    JsonArray jMethods = new JsonArray();
    for (ClassFile cf : group.getClasses()) {
        String implName = DeobAnnotations.getImplements(cf);
        String className = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
        for (Field f : cf.getFields()) {
            String exportName = DeobAnnotations.getExportedName(f.getAnnotations());
            if (exportName == null) {
                continue;
            }
            String fieldName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
            Type obfType = DeobAnnotations.getObfuscatedType(f);
            Number getter = DeobAnnotations.getObfuscatedGetter(f);
            JsonObject jField = new JsonObject();
            jField.addProperty("name", exportName);
            jField.addProperty("owner", f.isStatic() ? "" : implName);
            jField.addProperty("class", className);
            jField.addProperty("field", fieldName);
            jField.addProperty("obfSignature", (obfType != null ? obfType.toString() : ""));
            jField.addProperty("signature", f.getType().toString());
            jField.addProperty("multiplier", (getter != null ? getter : 0));
            jField.addProperty("static", f.isStatic());
            jFields.add(jField);
        }
        for (Method m : cf.getMethods()) {
            String exportName = DeobAnnotations.getExportedName(m.getAnnotations());
            if (exportName == null) {
                continue;
            }
            String methodName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
            Signature obfSignature = DeobAnnotations.getObfuscatedSignature(m);
            String predicate = DeobAnnotations.getObfuscatedValue(m);
            JsonObject jMethod = new JsonObject();
            jMethod.addProperty("name", exportName);
            jMethod.addProperty("owner", m.isStatic() ? "" : implName);
            jMethod.addProperty("class", className);
            jMethod.addProperty("field", methodName);
            jMethod.addProperty("obfSignature", (obfSignature != null ? obfSignature.toString() : ""));
            jMethod.addProperty("signature", m.getDescriptor().toString());
            jMethod.addProperty("predicate", (predicate != null ? predicate : ""));
            jMethod.addProperty("static", m.isStatic());
            jMethods.add(jMethod);
        }
    }
    jObject.addProperty("runelite", "http://github.com/runelite");
    jObject.addProperty("run", Instant.now().toString());
    jObject.addProperty("gamepack", properties.getRsVersion());
    jObject.add("fields", jFields);
    jObject.add("methods", jMethods);
    System.out.println(gson.toJson(jObject));
}
Also used : ClassFile(net.runelite.asm.ClassFile) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) JsonObject(com.google.gson.JsonObject) Method(net.runelite.asm.Method) JsonArray(com.google.gson.JsonArray) Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) Signature(net.runelite.asm.signature.Signature) File(java.io.File) ClassFile(net.runelite.asm.ClassFile) Test(org.junit.Test)

Example 58 with Method

use of net.runelite.asm.Method 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 59 with Method

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

the class HookImporter method importHooks.

@Test
@Ignore
public void importHooks() {
    int classes = 0, fields = 0, methods = 0;
    NameMappings mappings = new NameMappings();
    for (HookClass hc : hooks) {
        ClassFile cf = findClassWithObfuscatedName(hc.name);
        assert cf != null;
        String implementsName = getAnnotation(cf.getAnnotations(), IMPLEMENTS);
        if (implementsName.isEmpty()) {
            String deobfuscatedClassName = hc.clazz;
            cf.getAnnotations().addAnnotation(IMPLEMENTS, "value", deobfuscatedClassName);
            mappings.map(cf.getPoolClass(), deobfuscatedClassName);
            ++classes;
        }
        for (HookField fh : hc.fields) {
            ClassFile cf2 = findClassWithObfuscatedName(fh.owner);
            assert cf2 != null;
            Field f = findFieldWithObfuscatedName(cf2, fh.name);
            if (f == null) {
                // inlined constant maybe?
                logger.warn("Missing field {}", fh);
                continue;
            }
            String exportedName = getAnnotation(f.getAnnotations(), EXPORT);
            if (exportedName.isEmpty()) {
                String deobfuscatedFieldName = fh.field;
                Field other = cf2.findField(deobfuscatedFieldName);
                if (other != null) {
                    logger.warn("Name collision for field {}", deobfuscatedFieldName);
                    continue;
                }
                f.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedFieldName);
                mappings.map(f.getPoolField(), deobfuscatedFieldName);
                ++fields;
            }
        }
        outer: for (HookMethod hm : hc.methods) {
            ClassFile cf2 = findClassWithObfuscatedName(hm.owner);
            assert cf2 != null;
            Method m = findMethodWithObfuscatedName(cf2, hm.name, hm.descriptor);
            assert m != null;
            // maybe only the base class method is exported
            List<Method> virtualMethods = VirtualMethods.getVirtualMethods(m);
            for (Method method : virtualMethods) {
                String exportedName = getAnnotation(method.getAnnotations(), EXPORT);
                if (!exportedName.isEmpty()) {
                    continue outer;
                }
            }
            String deobfuscatedMethodName = hm.method;
            m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
            mappings.map(m.getPoolMethod(), deobfuscatedMethodName);
            ++methods;
        }
    }
    Renamer renamer = new Renamer(mappings);
    renamer.run(group);
    logger.info("Imported {} classes, {} fields, {} methods", classes, fields, methods);
}
Also used : Renamer(net.runelite.deob.deobfuscators.Renamer) Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) List(java.util.List) Method(net.runelite.asm.Method) NameMappings(net.runelite.deob.util.NameMappings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 60 with Method

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

the class UpdateMappingsTest method summary.

public static void summary(ParallelExecutorMapping finalm, ClassGroup in) {
    int fields = 0, staticMethod = 0, method = 0, total = 0, classes = 0;
    for (Map.Entry<Object, Object> e : finalm.getMap().entrySet()) {
        Object o = e.getKey();
        if (o instanceof Field) {
            ++fields;
            Field f = (Field) o;
            assert f.getClassFile().getGroup() == in;
        } else if (o instanceof Method) {
            Method m = (Method) o;
            assert m.getClassFile().getGroup() == in;
            if (m.isStatic()) {
                ++staticMethod;
            } else {
                ++method;
            }
        } else if (o instanceof ClassFile) {
            ++classes;
        }
        ++total;
    }
    logger.info("Total mapped: {}. {} fields, {} static methods, {} member methods, {} classes", total, fields, staticMethod, method, classes);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Map(java.util.Map)

Aggregations

Method (net.runelite.asm.Method)90 ClassFile (net.runelite.asm.ClassFile)64 Field (net.runelite.asm.Field)34 Instruction (net.runelite.asm.attributes.code.Instruction)29 Code (net.runelite.asm.attributes.Code)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 Signature (net.runelite.asm.signature.Signature)28 ClassGroup (net.runelite.asm.ClassGroup)20 ArrayList (java.util.ArrayList)18 Type (net.runelite.asm.Type)18 List (java.util.List)13 Test (org.junit.Test)13 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)10 DeobAnnotations (net.runelite.deob.DeobAnnotations)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)8 Label (net.runelite.asm.attributes.code.Label)8