Search in sources :

Example 51 with ClassFile

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

the class UnusedClass method run.

@Override
public void run(ClassGroup group) {
    int count = 0;
    for (ClassFile cf : new ArrayList<>(group.getClasses())) {
        if (!cf.getFields().isEmpty()) {
            continue;
        }
        if (!cf.getMethods().isEmpty()) {
            continue;
        }
        if (isImplemented(group, cf)) {
            continue;
        }
        group.removeClass(cf);
        ++count;
    }
    logger.info("Removed {} classes", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList)

Example 52 with ClassFile

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

the class UnusedMethods method run.

@Override
public void run(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method method : cf.getMethods()) {
            run(method);
        }
    }
    int count = 0;
    for (ClassFile cf : group.getClasses()) {
        boolean extendsApplet = extendsApplet(cf);
        for (Method method : new ArrayList<>(cf.getMethods())) {
            // constructors can't be renamed, but are obfuscated
            if (!Deob.isObfuscated(method.getName()) && !method.getName().equals("<init>")) {
                continue;
            }
            if (extendsApplet && method.getName().equals("<init>")) {
                continue;
            }
            if (!methods.contains(method)) {
                logger.debug("Removing unused method {}", method);
                cf.removeMethod(method);
                ++count;
            }
        }
    }
    logger.info("Removed {} methods", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method)

Example 53 with ClassFile

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

the class Renamer method run.

@Override
public void run(ClassGroup group) {
    group.buildClassGraph();
    group.lookup();
    int classes = 0, fields = 0, methods = 0;
    // rename fields
    for (ClassFile cf : group.getClasses()) {
        for (Field field : cf.getFields()) {
            String newName = mappings.get(field.getPoolField());
            if (newName == null) {
                continue;
            }
            if (field.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
                field.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", field.getName());
            }
            field.setName(newName);
            ++fields;
        }
    }
    // rename methods
    for (ClassFile cf : group.getClasses()) {
        for (Method method : cf.getMethods()) {
            String newName = mappings.get(method.getPoolMethod());
            // rename on obfuscated signature
            Annotation an = method.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE);
            if (an != null) {
                Signature obfuscatedSig = new Signature(an.getElement().getString());
                Signature updatedSig = renameSignature(obfuscatedSig);
                an.getElement().setValue(updatedSig.toString());
            }
            if (newName == null) {
                continue;
            }
            List<Method> virtualMethods = VirtualMethods.getVirtualMethods(method);
            assert !virtualMethods.isEmpty();
            for (Method m : virtualMethods) {
                if (m.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
                    m.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", m.getName());
                }
                m.setName(newName);
            }
            methods += virtualMethods.size();
        }
    }
    for (ClassFile cf : group.getClasses()) {
        String newName = mappings.get(cf.getPoolClass());
        if (newName == null) {
            continue;
        }
        renameClass(group, cf, newName);
        ++classes;
    }
    this.regeneratePool(group);
    logger.info("Renamed {} classes, {} fields, and {} methods", classes, fields, methods);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 54 with ClassFile

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

the class PutStatic method getMyField.

@Override
public net.runelite.asm.Field getMyField() {
    Class clazz = field.getClazz();
    ClassGroup group = this.getInstructions().getCode().getMethod().getClassFile().getGroup();
    ClassFile cf = group.findClass(clazz.getName());
    if (cf == null) {
        return null;
    }
    net.runelite.asm.Field f2 = cf.findFieldDeep(field.getName(), field.getType());
    return f2;
}
Also used : ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Class(net.runelite.asm.pool.Class)

Example 55 with ClassFile

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

the class RWOpcodeFinder method find.

public void find() {
    IsaacCipherFinder ic = new IsaacCipherFinder(group);
    ic.find();
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            find(ic, m, code);
        }
    }
    logger.debug("Found readOpcode {}, writeOpcode {}", readOpcode, writeOpcode);
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

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