Search in sources :

Example 16 with Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class ControlFlowDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null || !code.getExceptions().getExceptions().isEmpty()) {
                continue;
            }
            split(code);
            run(code);
            runJumpLabel(code);
        }
    }
    logger.info("Inserted {} jumps, reordered {} blocks, and removed {} jumps. jump delta {}", insertedJump, placedBlocks, removedJumps, insertedJump - removedJumps);
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

Example 17 with Code

use of net.runelite.asm.attributes.Code 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 18 with Code

use of net.runelite.asm.attributes.Code 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 19 with Code

use of net.runelite.asm.attributes.Code 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 20 with Code

use of net.runelite.asm.attributes.Code in project runelite by runelite.

the class UnusedMethods method run.

private void run(Method method) {
    Code code = method.getCode();
    if (code == null) {
        return;
    }
    for (Instruction i : code.getInstructions().getInstructions()) {
        if (!(i instanceof InvokeInstruction)) {
            continue;
        }
        InvokeInstruction ii = (InvokeInstruction) i;
        methods.addAll(ii.getMethods());
    }
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Aggregations

Code (net.runelite.asm.attributes.Code)62 Instruction (net.runelite.asm.attributes.code.Instruction)49 Instructions (net.runelite.asm.attributes.code.Instructions)45 LDC (net.runelite.asm.attributes.code.instructions.LDC)31 ClassGroup (net.runelite.asm.ClassGroup)30 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)30 Test (org.junit.Test)29 Method (net.runelite.asm.Method)26 IStore (net.runelite.asm.attributes.code.instructions.IStore)23 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)22 IMul (net.runelite.asm.attributes.code.instructions.IMul)21 Execution (net.runelite.asm.execution.Execution)21 Deobfuscator (net.runelite.deob.Deobfuscator)19 ClassFile (net.runelite.asm.ClassFile)18 Signature (net.runelite.asm.signature.Signature)15 Type (net.runelite.asm.Type)12 Pop (net.runelite.asm.attributes.code.instructions.Pop)12 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)11 Label (net.runelite.asm.attributes.code.Label)10 Field (net.runelite.asm.Field)8