Search in sources :

Example 51 with Code

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

the class ExprArgOrderTest method test.

@Test
public void test() {
    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);
    }
    Instruction[] body = { // 2
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    ExprArgOrder exprArgOrder = new ExprArgOrder();
    exprArgOrder.run(group);
    List<Instruction> instructions = ins.getInstructions();
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 52 with Code

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

the class LvtTest method testReuseIndex.

@Test
public void testReuseIndex() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    Instruction[] body = { // var0 = null
    new AConstNull(ins), new AStore(ins, 0), // this forces a reindex to varn
    new LDC(ins, 0), new IStore(ins, 0), // var2 = null
    new AConstNull(ins), new AStore(ins, 2), // this forces a reindex to varn+1
    new LDC(ins, 0), new IStore(ins, 2), // var0 = 0L
    new LDC(ins, 0L), new LStore(ins, 0), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Lvt lvt = new Lvt();
    lvt.run(group);
    AStore astore1 = (AStore) body[1];
    IStore istore1 = (IStore) body[3];
    AStore astore2 = (AStore) body[5];
    IStore istore2 = (IStore) body[7];
    LStore lstore1 = (LStore) body[9];
    int astore1Idx = astore1.getVariableIndex();
    int istore1Idx = istore1.getVariableIndex();
    int astore2Idx = astore2.getVariableIndex();
    int istore2Idx = istore2.getVariableIndex();
    int lstore1Idx = lstore1.getVariableIndex();
    logger.debug("{} -> {}", astore1, astore1.getVariableIndex());
    logger.debug("{} -> {}", istore1, istore1.getVariableIndex());
    logger.debug("{} -> {}", astore2, astore2.getVariableIndex());
    logger.debug("{} -> {}", istore2, istore2.getVariableIndex());
    logger.debug("{} -> {}", lstore1, lstore1.getVariableIndex());
    Assert.assertNotEquals(astore1Idx, istore1Idx);
    Assert.assertNotEquals(astore2Idx, istore2Idx);
    // assert that the lstore doesn't overwrite an existing index
    Assert.assertNotEquals(lstore1Idx + 1, astore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, astore2Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore2Idx);
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) Instructions(net.runelite.asm.attributes.code.Instructions) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) LStore(net.runelite.asm.attributes.code.instructions.LStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) AStore(net.runelite.asm.attributes.code.instructions.AStore) ClassGroup(net.runelite.asm.ClassGroup) Test(org.junit.Test)

Example 53 with Code

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

the class MaxMemoryTransformer method transform.

private void transform(Method m) {
    Code code = m.getCode();
    if (code == null) {
        return;
    }
    Instructions ins = code.getInstructions();
    for (Instruction i : ins.getInstructions()) {
        if (i instanceof InvokeVirtual) {
            /*
					invokestatic          java/lang/Runtime/getRuntime()Ljava/lang/Runtime;
					invokevirtual         java/lang/Runtime/maxMemory()J
					ldc2_w                1048576
					ldiv
					l2i
				 */
            if (((InvokeVirtual) i).getMethod().getName().equals("maxMemory")) {
                insert(ins, ins.getInstructions().indexOf(i));
                done = true;
                break;
            }
        }
    }
}
Also used : InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 54 with Code

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

the class BufferFinder method find.

public void find() {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (findModPow(code)) {
                buffer = cf;
                // packetBuffer extends this
                packetBuffer = group.getClasses().stream().filter(cl -> cl.getParent() == cf).findAny().get();
                logger.info("Identified buffer {}, packetBuffer {}", buffer, packetBuffer);
            }
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Logger(org.slf4j.Logger) Method(net.runelite.asm.Method) Instructions(net.runelite.asm.attributes.code.Instructions) LoggerFactory(org.slf4j.LoggerFactory) Code(net.runelite.asm.attributes.Code) Instruction(net.runelite.asm.attributes.code.Instruction) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) ClassGroup(net.runelite.asm.ClassGroup) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

Example 55 with Code

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

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