Search in sources :

Example 36 with Execution

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

the class MultiplyOneDeobfuscatorTest method testDir.

@Test
public void testDir() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) ins.addInstruction(i);
    Label label = new Label(ins), label2 = new Label(ins);
    LDC one = new LDC(ins, 1);
    Instruction[] body = { new SiPush(ins, (short) 256), new ILoad(ins, 0), new IfEq(ins, label), new LDC(ins, 2), new Goto(ins, label2), label, one, label2, new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) ins.addInstruction(i);
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new MultiplyOneDeobfuscator(false);
    d.run(group);
    Assert.assertTrue(one.getInstructions() != null);
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) IStore(net.runelite.asm.attributes.code.instructions.IStore) Goto(net.runelite.asm.attributes.code.instructions.Goto) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 37 with Execution

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

the class PacketWriteDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    rw = new RWOpcodeFinder(group);
    rw.find();
    Execution e = new Execution(group);
    e.addExecutionVisitor(this::visit);
    e.populateInitialMethods();
    e.run();
    end();
    opcodeReplacer.run(group, writes.values());
    int count = 0;
    int writesCount = 0;
    for (PacketWrite write : writes.values()) {
        if (write.writes.isEmpty()) {
            continue;
        }
        insert(group, write);
        ++count;
        writesCount += write.writes.size();
    }
    logger.info("Converted buffer write methods for {} opcodes ({} writes)", count, writesCount);
}
Also used : Execution(net.runelite.asm.execution.Execution) RWOpcodeFinder(net.runelite.deob.c2s.RWOpcodeFinder)

Example 38 with Execution

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

the class PacketFlushFinder method find.

private void find(Method method) {
    Code code = method.getCode();
    Set<Instruction> checked = new HashSet<>();
    Execution e = new Execution(group);
    e.addMethod(method);
    e.noInvoke = true;
    e.noExceptions = true;
    e.addExecutionVisitor(ic -> {
        Instruction i = ic.getInstruction();
        if (checked.contains(i)) {
            return;
        }
        checked.add(i);
        if (i.getType() != INVOKEVIRTUAL) {
            return;
        }
        InvokeVirtual iv = (InvokeVirtual) i;
        // queueForWrite
        if (!iv.getMethod().getType().equals(new Signature("([BII)V"))) {
            return;
        }
        InstructionContext lengthCtx = ic.getPops().get(0).getPushed();
        if (lengthCtx.getInstruction().getType() != GETFIELD) {
            return;
        }
        queueForWrite.add(ic);
    });
    e.run();
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) HashSet(java.util.HashSet)

Example 39 with Execution

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

the class MultiplicationDeobfuscator method runOnce.

private int runOnce() {
    group.buildClassGraph();
    count = 0;
    Execution e = new Execution(group);
    e.addMethodContextVisitor(m -> visit(m));
    e.populateInitialMethods();
    e.run();
    return count;
}
Also used : Execution(net.runelite.asm.execution.Execution)

Example 40 with Execution

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

the class MultiplyZeroDeobfuscator 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 + " 0 multiplications");
}
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