Search in sources :

Example 26 with Type

use of net.runelite.asm.Type 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 27 with Type

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

the class ModArith method guess.

private void guess() {
    for (ClassFile cf : group.getClasses()) {
        for (Field f : cf.getFields()) {
            FieldInfo fieldInfo = getFieldInfo(f);
            // all constants in instructions associated with the field
            Collection<AssociatedConstant> col = fieldInfo.constants;
            if (col.isEmpty()) {
                continue;
            }
            Type type = f.getType();
            assert type.equals(Type.INT) || type.equals(Type.LONG);
            Class typeOfField = type.equals(Type.INT) ? Integer.class : Long.class;
            // filter collect constants of the correct type
            Collection<AssociatedConstant> col2 = col.stream().filter(i -> i.value.getClass() == typeOfField).collect(Collectors.toList());
            // filer out ones that have another field in the expression
            List<Number> noOther = col2.stream().filter(i -> !i.other && !i.constant).map(i -> i.value).distinct().collect(Collectors.toList());
            List<Number> other = col2.stream().filter(i -> i.other || i.constant).map(i -> i.value).collect(Collectors.toList());
            other.addAll(noOther);
            other = ImmutableSet.copyOf(other).asList();
            // guess with constants not associated with other fields
            Pair p = this.guess(f, noOther);
            if (p == null) {
                // fall back to all constants
                p = this.guess(f, other);
            }
            // check that this guess doesn't increase constants
            if (p != null && !fieldInfo.guessDecreasesConstants(p)) {
                continue;
            }
            if (p != null) {
                pairs.add(p);
            }
        }
    }
}
Also used : DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) IMul(net.runelite.asm.attributes.code.instructions.IMul) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Code(net.runelite.asm.attributes.Code) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) StackContext(net.runelite.asm.execution.StackContext) HashSet(java.util.HashSet) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) DMath.modInverse(net.runelite.deob.deobfuscators.arithmetic.DMath.modInverse) Method(net.runelite.asm.Method) Map(java.util.Map) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) If(net.runelite.asm.attributes.code.instructions.If) LAdd(net.runelite.asm.attributes.code.instructions.LAdd) ISub(net.runelite.asm.attributes.code.instructions.ISub) ArrayLoad(net.runelite.asm.attributes.code.instruction.types.ArrayLoad) ImmutableSet(com.google.common.collect.ImmutableSet) DeobAnnotations(net.runelite.deob.DeobAnnotations) Logger(org.slf4j.Logger) Collection(java.util.Collection) LCmp(net.runelite.asm.attributes.code.instructions.LCmp) Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Set(java.util.Set) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) DMath.multiply(net.runelite.deob.deobfuscators.arithmetic.DMath.multiply) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Collectors(java.util.stream.Collectors) InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) LDC(net.runelite.asm.attributes.code.instructions.LDC) MethodContext(net.runelite.asm.execution.MethodContext) Instructions(net.runelite.asm.attributes.code.Instructions) LMul(net.runelite.asm.attributes.code.instructions.LMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) If0(net.runelite.asm.attributes.code.instructions.If0) LSub(net.runelite.asm.attributes.code.instructions.LSub) IShR(net.runelite.asm.attributes.code.instructions.IShR) Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile)

Example 28 with Type

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

the class ModArith method findConstants.

// find associated constants with each field
private void findConstants(MethodContext mctx) {
    for (InstructionContext ctx : mctx.getInstructionContexts()) {
        if (ctx.getInstruction() instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) ctx.getInstruction();
            if (fi.getMyField() == null) {
                continue;
            }
            if ((!fi.getField().getType().equals(Type.INT) && !fi.getField().getType().equals(Type.LONG)) || fi.getField().getType().isArray()) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(fi.getMyField());
            List<InstructionContext> l = getInsInExpr(ctx, new HashSet(), false);
            // check if this contains another field
            boolean other = false;
            boolean getter = false, setter = false;
            for (InstructionContext i : l) {
                if (i.getInstruction() instanceof FieldInstruction) {
                    FieldInstruction fi2 = (FieldInstruction) i.getInstruction();
                    Field myField = fi2.getMyField();
                    if (myField != null && myField != fi.getMyField()) {
                        Type t = myField.getType();
                        if (t.equals(fi.getMyField().getType())) {
                            other = true;
                        }
                    } else if (myField != null && myField == fi.getMyField()) {
                        if (fi2 instanceof SetFieldInstruction) {
                            setter = true;
                        } else {
                            getter = true;
                        }
                    }
                }
            }
            // check if this is a constant assignment
            boolean constant = false;
            if (fi instanceof SetFieldInstruction) {
                // value being set
                InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
                pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
                if (pushedsfi.getInstruction() instanceof LDC) {
                    constant = true;
                }
            }
            for (InstructionContext i : l) {
                if (i.getInstruction() instanceof LDC) {
                    PushConstantInstruction w = (PushConstantInstruction) i.getInstruction();
                    if (w.getConstant() instanceof Integer || w.getConstant() instanceof Long) {
                        AssociatedConstant n = new AssociatedConstant();
                        n.value = (Number) w.getConstant();
                        n.other = other;
                        n.constant = constant;
                        n.getter = getter;
                        n.setter = setter;
                        fieldInfo.constants.add(n);
                    }
                }
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LDC(net.runelite.asm.attributes.code.instructions.LDC) Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) HashSet(java.util.HashSet)

Example 29 with Type

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

the class ConstructorMapper method toOtherSignature.

private Signature toOtherSignature(Signature s) {
    Signature.Builder builder = new Signature.Builder().setReturnType(toOtherType(s.getReturnValue()));
    for (Type t : s.getArguments()) {
        Type other = toOtherType(t);
        if (other == null) {
            return null;
        }
        builder.addArgument(other);
    }
    return builder.build();
}
Also used : Type(net.runelite.asm.Type) Signature(net.runelite.asm.signature.Signature)

Example 30 with Type

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

the class ConstructorMapper method toOtherType.

private Type toOtherType(Type type) {
    if (type.isPrimitive()) {
        return type;
    }
    ClassFile cf = source.findClass(type.getInternalName());
    if (cf == null) {
        return type;
    }
    ClassFile other = (ClassFile) mapping.get(cf);
    if (other == null) {
        logger.debug("Unable to map other type due to no class mapping for {}", cf);
        return null;
    }
    return new Type("L" + other.getName() + ";");
}
Also used : Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile)

Aggregations

Type (net.runelite.asm.Type)34 Signature (net.runelite.asm.signature.Signature)16 Method (net.runelite.asm.Method)15 ClassFile (net.runelite.asm.ClassFile)13 InstructionType (net.runelite.asm.attributes.code.InstructionType)13 Instruction (net.runelite.asm.attributes.code.Instruction)11 Field (net.runelite.asm.Field)10 Code (net.runelite.asm.attributes.Code)9 Instructions (net.runelite.asm.attributes.code.Instructions)9 ClassGroup (net.runelite.asm.ClassGroup)7 LDC (net.runelite.asm.attributes.code.instructions.LDC)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 ALoad (net.runelite.asm.attributes.code.instructions.ALoad)5 InstructionContext (net.runelite.asm.execution.InstructionContext)5 Annotation (net.runelite.asm.attributes.annotation.Annotation)4 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)4