Search in sources :

Example 11 with Execution

use of net.runelite.asm.execution.Execution in project runelite by runelite.

the class MultiplyOneDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    Execution e = new Execution(group);
    e.addMethodContextVisitor(i -> visit(i));
    e.populateInitialMethods();
    e.run();
    logger.info("Removed " + count + " 1 multiplications");
}
Also used : Execution(net.runelite.asm.execution.Execution)

Example 12 with Execution

use of net.runelite.asm.execution.Execution in project runelite by runelite.

the class UnreachedCode method run.

@Override
public void run(ClassGroup group) {
    group.buildClassGraph();
    execution = new Execution(group);
    execution.populateInitialMethods();
    execution.run();
    int count = 0;
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            if (m.getCode() == null)
                continue;
            count += removeUnused(m);
        }
    }
    logger.info("Removed {} unused instructions", count);
}
Also used : Execution(net.runelite.asm.execution.Execution) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 13 with Execution

use of net.runelite.asm.execution.Execution in project runelite by runelite.

the class UnusedParameters method removeParameter.

public void removeParameter(ClassGroup group, List<Method> methods, Signature signature, Execution execution, int paramIndex, int lvtIndex) {
    int slots = signature.getTypeOfArg(paramIndex).getSize();
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null) {
                continue;
            }
            for (Instruction i : new ArrayList<>(c.getInstructions().getInstructions())) {
                if (!(i instanceof InvokeInstruction)) {
                    continue;
                }
                InvokeInstruction ii = (InvokeInstruction) i;
                if (!ii.getMethods().stream().anyMatch(me -> methods.contains(me))) {
                    continue;
                }
                // remove parameter from instruction
                ii.removeParameter(paramIndex);
                Collection<InstructionContext> ics = invokes.get(i);
                assert ics != null;
                if (ics != null) {
                    for (InstructionContext ins : ics) {
                        // index from top of stack of parameter. 0 is the last parameter
                        int pops = signature.size() - paramIndex - 1;
                        StackContext sctx = ins.getPops().get(pops);
                        if (sctx.getPushed().getInstruction().getInstructions() == null) {
                            continue;
                        }
                        // remove parameter from stack
                        ins.removeStack(pops);
                    }
                }
            }
        }
    }
    for (Method method : methods) {
        if (method.getCode() != null) // adjust lvt indexes to get rid of idx in the method
        {
            for (Instruction ins : method.getCode().getInstructions().getInstructions()) {
                if (ins instanceof LVTInstruction) {
                    LVTInstruction lins = (LVTInstruction) ins;
                    int i = lins.getVariableIndex();
                    // current unused variable detection just looks for no accesses
                    assert i != lvtIndex;
                    // reassign
                    if (i > lvtIndex) {
                        assert i > 0;
                        assert i >= lvtIndex + slots;
                        Instruction newIns = lins.setVariableIndex(i - slots);
                        assert ins == newIns;
                    }
                }
            }
        }
    }
    for (Method method : methods) {
        method.getDescriptor().remove(paramIndex);
    }
}
Also used : LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Code(net.runelite.asm.attributes.Code) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) StackContext(net.runelite.asm.execution.StackContext) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) Map(java.util.Map) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) VirtualMethods(net.runelite.asm.signature.util.VirtualMethods) ImmutableSet(com.google.common.collect.ImmutableSet) DeobAnnotations(net.runelite.deob.DeobAnnotations) Logger(org.slf4j.Logger) Deob(net.runelite.deob.Deob) Collection(java.util.Collection) Set(java.util.Set) Deobfuscator(net.runelite.deob.Deobfuscator) InstructionContext(net.runelite.asm.execution.InstructionContext) Sets(com.google.common.collect.Sets) Execution(net.runelite.asm.execution.Execution) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Instruction(net.runelite.asm.attributes.code.Instruction) Collections(java.util.Collections) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) InstructionContext(net.runelite.asm.execution.InstructionContext) ClassFile(net.runelite.asm.ClassFile) StackContext(net.runelite.asm.execution.StackContext) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Code(net.runelite.asm.attributes.Code)

Example 14 with Execution

use of net.runelite.asm.execution.Execution in project runelite by runelite.

the class UnusedParameters method run.

@Override
public void run(ClassGroup group) {
    int i;
    int pnum = 1;
    do {
        group.buildClassGraph();
        invokes.clear();
        this.buildUnused(group);
        Execution execution = new Execution(group);
        execution.addExecutionVisitor(ictx -> visit(ictx));
        execution.populateInitialMethods();
        execution.run();
        i = this.processUnused(execution, group);
        count += i;
        break;
    } while (i > 0);
    logger.info("Removed {} unused parameters", count);
}
Also used : Execution(net.runelite.asm.execution.Execution)

Example 15 with Execution

use of net.runelite.asm.execution.Execution in project runelite by runelite.

the class DupDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    Execution e = new Execution(group);
    e.addMethodContextVisitor(m -> visit(m));
    e.populateInitialMethods();
    e.run();
    logger.info("Replaced {} dup instructions", count);
}
Also used : Execution(net.runelite.asm.execution.Execution)

Aggregations

Execution (net.runelite.asm.execution.Execution)44 Instruction (net.runelite.asm.attributes.code.Instruction)25 ClassGroup (net.runelite.asm.ClassGroup)23 Instructions (net.runelite.asm.attributes.code.Instructions)23 Code (net.runelite.asm.attributes.Code)21 Deobfuscator (net.runelite.deob.Deobfuscator)21 LDC (net.runelite.asm.attributes.code.instructions.LDC)19 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)19 IMul (net.runelite.asm.attributes.code.instructions.IMul)18 Test (org.junit.Test)18 IStore (net.runelite.asm.attributes.code.instructions.IStore)17 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)16 InstructionContext (net.runelite.asm.execution.InstructionContext)12 Label (net.runelite.asm.attributes.code.Label)10 Method (net.runelite.asm.Method)8 ClassFile (net.runelite.asm.ClassFile)7 Pop (net.runelite.asm.attributes.code.instructions.Pop)7 StackContext (net.runelite.asm.execution.StackContext)7 Field (net.runelite.asm.Field)5 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)5