Search in sources :

Example 56 with ClassFile

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

the class IsaacCipherFinder method find.

public void find() {
    Method highest = null;
    int count = 0;
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            int i = find(m, code);
            if (i > count) {
                count = i;
                highest = m;
            }
        }
    }
    assert highest != null;
    isaacCipher = highest.getClassFile();
    // find nextInt
    for (Method method : isaacCipher.getMethods()) {
        if (method.getDescriptor().size() == 0 && method.getDescriptor().getReturnValue().equals(Type.INT)) {
            getNext = method;
        }
    }
    logger.debug("Found cipher {}, getNext {}", isaacCipher, getNext);
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

Example 57 with ClassFile

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

the class InvokeVirtual method map.

@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    InvokeVirtual otherIv = (InvokeVirtual) other.getInstruction();
    List<net.runelite.asm.Method> myMethods = this.getMethods(), otherMethods = otherIv.getMethods();
    assert MappingExecutorUtil.isMaybeEqual(method.getType(), otherIv.method.getType());
    assert myMethods.size() == otherMethods.size();
    for (int i = 0; i < myMethods.size(); ++i) {
        net.runelite.asm.Method m1 = myMethods.get(i), otherMethod = null;
        ClassFile c1 = m1.getClassFile();
        if (myMethods.size() == 1) {
            otherMethod = otherMethods.get(0);
        } else {
            for (int j = 0; j < myMethods.size(); ++j) {
                net.runelite.asm.Method m2 = otherMethods.get(j);
                ClassFile c2 = m2.getClassFile();
                if (MappingExecutorUtil.isMaybeEqual(c1, c2)) {
                    if (otherMethod != null) {
                        otherMethod = null;
                        break;
                    }
                    otherMethod = m2;
                }
            }
        }
        if (otherMethod != null) {
            mapping.map(this, m1, otherMethod);
        }
    }
    /* map arguments */
    assert ctx.getPops().size() == other.getPops().size();
    for (int i = 0; i < ctx.getPops().size(); ++i) {
        StackContext s1 = ctx.getPops().get(i), s2 = other.getPops().get(i);
        InstructionContext base1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
        InstructionContext base2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
        if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
            GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
            Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
            if (f1 != null && f2 != null) {
                mapping.map(this, f1, f2);
            }
        }
    }
    /* map field that was invoked on */
    StackContext object1 = ctx.getPops().get(method.getType().size()), object2 = other.getPops().get(otherIv.method.getType().size());
    InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1);
    InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2);
    if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
        Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
        if (f1 != null && f2 != null) {
            mapping.map(this, f1, f2);
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.pool.Method) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 58 with ClassFile

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

the class Execution method getInitialMethods.

public List<Method> getInitialMethods() {
    List<Method> methods = new ArrayList<>();
    // required when looking up methods
    group.buildClassGraph();
    // lookup methods
    group.lookup();
    for (ClassFile cf : group.getClasses()) {
        boolean extendsApplet = extendsApplet(cf);
        for (Method m : cf.getMethods()) {
            if (!Deob.isObfuscated(m.getName()) && !m.getName().equals("<init>")) {
                if (m.getCode() == null) {
                    methods.add(m);
                    continue;
                }
                // I guess this method name is overriding a jre interface (init, run, ?).
                methods.add(m);
                logger.debug("Adding initial method {}", m);
            }
            if (m.getName().equals("<init>") && extendsApplet) {
                methods.add(m);
            }
        }
    }
    return methods;
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method)

Example 59 with ClassFile

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

the class NonloadingClassWriter method getCommonSuperClass.

@Override
protected String getCommonSuperClass(String type1, String type2) {
    ClassFile cf1 = group.findClass(type1), cf2 = group.findClass(type2);
    if (cf1 == null && cf2 == null) {
        // not mine
        try {
            return super.getCommonSuperClass(type1, type2);
        } catch (RuntimeException ex) {
            // java.lang.RuntimeException: java.lang.ClassNotFoundException: com.sun.deploy.appcontext.AppContext
            return "java/lang/Object";
        }
    }
    if (cf1 != null && cf2 != null) {
        for (ClassFile c = cf1; c != null; c = c.getParent()) for (ClassFile c2 = cf2; c2 != null; c2 = c2.getParent()) if (c == c2)
            return c.getName();
        return "java/lang/Object";
    }
    ClassFile found;
    String other;
    if (cf1 == null) {
        found = cf2;
        other = type1;
    } else {
        assert cf2 == null;
        found = cf1;
        other = type2;
    }
    ClassFile prev = null;
    for (ClassFile c = found; c != null; c = c.getParent()) {
        prev = c;
        if (c.getName().equals(other))
            return other;
    }
    return super.getCommonSuperClass(prev.getSuperName(), other);
}
Also used : ClassFile(net.runelite.asm.ClassFile)

Example 60 with ClassFile

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

the class VirtualMethods method findMethodUp.

private static void findMethodUp(List<Method> methods, Set<ClassFile> visited, ClassFile cf, String name, Signature type) {
    if (cf == null || visited.contains(cf))
        return;
    // can do diamond inheritance with interfaces
    visited.add(cf);
    Method m = cf.findMethod(name, type);
    if (m != null && !m.isStatic())
        methods.add(m);
    for (ClassFile child : cf.getChildren()) findMethodUp(methods, visited, child, name, type);
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

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