Search in sources :

Example 31 with ClassFile

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

the class FieldInliner method findFieldIns.

private void findFieldIns() {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null)
                continue;
            for (Instruction i : code.getInstructions().getInstructions()) {
                if (!(i instanceof FieldInstruction))
                    continue;
                FieldInstruction sf = (FieldInstruction) i;
                if (sf.getMyField() == null)
                    continue;
                fieldInstructions.put(sf.getMyField(), sf);
            }
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) 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) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 32 with ClassFile

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

the class IllegalStateExceptions method findInteresting.

/* find if, new, ..., athrow, replace with goto */
private void findInteresting(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null)
                continue;
            Instructions instructions = c.getInstructions();
            List<Instruction> ilist = instructions.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction ins = ilist.get(i);
                if (// the if
                !(ins instanceof ComparisonInstruction))
                    continue;
                Instruction ins2 = ilist.get(i + 1);
                if (!(ins2 instanceof New))
                    continue;
                New new2 = (New) ins2;
                net.runelite.asm.pool.Class clazz = new2.getNewClass();
                if (!clazz.getName().contains("java/lang/IllegalStateException"))
                    continue;
                interesting.add(ins);
            }
        }
    }
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) ClassFile(net.runelite.asm.ClassFile) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 33 with ClassFile

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

the class RuntimeExceptions method run.

@Override
public void run(ClassGroup group) {
    boolean foundInit = false;
    int i = 0;
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null)
                continue;
            // keeps the client error handling related methods
            if (cf.getName().equals("client") && m.getName().equals("init")) {
                foundInit = true;
                continue;
            }
            for (net.runelite.asm.attributes.code.Exception e : new ArrayList<>(c.getExceptions().getExceptions())) {
                if (e.getCatchType() != null && e.getCatchType().getName().equals("java/lang/RuntimeException")) {
                    c.getExceptions().remove(e);
                    ++i;
                }
            }
        }
    }
    if (!foundInit) {
        throw new IllegalStateException("client.init(...) method seems to be missing!");
    }
    logger.info("Remove {} exception handlers", i);
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

Example 34 with ClassFile

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

the class Renamer method renameClass.

private void renameClass(ClassGroup group, ClassFile cf, String name) {
    for (ClassFile c : group.getClasses()) {
        // rename on child interfaces and classes
        renameClass(c, cf, name);
        for (Method method : c.getMethods()) {
            // rename on instructions. this includes method calls and field accesses.
            if (method.getCode() != null) {
                Code code = method.getCode();
                // rename on instructions
                for (Instruction i : code.getInstructions().getInstructions()) {
                    i.renameClass(cf.getName(), name);
                }
                // rename on exception handlers
                Exceptions exceptions = code.getExceptions();
                exceptions.renameClass(cf, name);
            }
            // rename on parameters
            Signature.Builder builder = new Signature.Builder();
            Signature signature = method.getDescriptor();
            for (int i = 0; i < signature.size(); ++i) {
                Type type = signature.getTypeOfArg(i);
                if (type.getInternalName().equals(cf.getName())) {
                    builder.addArgument(Type.getType("L" + name + ";", type.getDimensions()));
                } else {
                    builder.addArgument(type);
                }
            }
            // rename return type
            if (signature.getReturnValue().getInternalName().equals(cf.getName())) {
                builder.setReturnType(Type.getType("L" + name + ";", signature.getReturnValue().getDimensions()));
            } else {
                builder.setReturnType(signature.getReturnValue());
            }
            Signature newSignature = builder.build();
            if (!method.getDescriptor().equals(newSignature)) {
                // Signature was updated. Annotate it
                if (method.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE) == null) {
                    // Signature was not previously renamed
                    method.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", method.getDescriptor().toString());
                }
            }
            method.setDescriptor(newSignature);
            // rename on exceptions thrown
            if (method.getExceptions() != null) {
                method.getExceptions().renameClass(cf, name);
            }
        }
        // rename on fields
        for (Field field : c.getFields()) {
            if (field.getType().getInternalName().equals(cf.getName())) {
                if (field.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE) == null) {
                    // Signature was updated. Annotate it
                    field.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", field.getType().toString());
                }
                field.setType(Type.getType("L" + name + ";", field.getType().getDimensions()));
            }
        }
    }
    if (cf.getAnnotations().find(DeobAnnotations.OBFUSCATED_NAME) == null) {
        cf.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_NAME, "value", cf.getName());
    }
    group.renameClass(cf, name);
}
Also used : Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Exceptions(net.runelite.asm.attributes.code.Exceptions) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 35 with ClassFile

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

the class Renamer method regeneratePool.

private void regeneratePool(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null) {
                continue;
            }
            c.getInstructions().regeneratePool();
        }
    }
}
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