Search in sources :

Example 46 with ClassGroup

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

the class ExprArgOrderTest method test5.

@Test
public void test5() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Label label = new Label(ins);
    Instruction[] body = { // if (0 == 3 + var0) -> if (var0 + 3 == 0)
    new LDC(ins, 0), new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new IfICmpEq(ins, label), label, new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    // ldc iload add -> iload ldc iadd
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    // idc moves from 2 to 5
    assertEquals(LDC, instructions.get(5).getType());
    assertEquals(IF_ICMPEQ, instructions.get(6).getType());
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 47 with ClassGroup

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

the class ExprArgOrderTest method test6.

@Test
public void test6() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Label label = new Label(ins);
    /*
		iconst_0
		ldc                   8388608
		iload_3
		iadd
		ldc                   -16777216
		iand
		if_icmpeq             LABEL0x49
		 */
    Instruction[] body = { new LDC(ins, 0), new LDC(ins, 8388608), new ILoad(ins, 0), new IAdd(ins), new LDC(ins, -16777216), new IAnd(ins), // 8
    new IfICmpEq(ins, label), label, new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    assertEquals(LDC, instructions.get(5).getType());
    assertEquals(IAND, instructions.get(6).getType());
    assertEquals(LDC, instructions.get(7).getType());
    assertEquals(IF_ICMPEQ, instructions.get(8).getType());
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) IAnd(net.runelite.asm.attributes.code.instructions.IAnd) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 48 with ClassGroup

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

the class ExprArgOrderTest method test.

@Test
public void test() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    Instruction[] body = { // 2
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 49 with ClassGroup

use of net.runelite.asm.ClassGroup 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 50 with ClassGroup

use of net.runelite.asm.ClassGroup 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)

Aggregations

ClassGroup (net.runelite.asm.ClassGroup)66 Test (org.junit.Test)41 Code (net.runelite.asm.attributes.Code)29 ClassFile (net.runelite.asm.ClassFile)28 Instruction (net.runelite.asm.attributes.code.Instruction)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 LDC (net.runelite.asm.attributes.code.instructions.LDC)28 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)26 IStore (net.runelite.asm.attributes.code.instructions.IStore)23 Deobfuscator (net.runelite.deob.Deobfuscator)22 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)21 Execution (net.runelite.asm.execution.Execution)21 IMul (net.runelite.asm.attributes.code.instructions.IMul)18 Method (net.runelite.asm.Method)12 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)11 Pop (net.runelite.asm.attributes.code.instructions.Pop)11 File (java.io.File)9 Label (net.runelite.asm.attributes.code.Label)9 Type (net.runelite.asm.Type)8 Signature (net.runelite.asm.signature.Signature)8