Search in sources :

Example 76 with Instruction

use of net.runelite.asm.attributes.code.Instruction 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 77 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class RenameUniqueTest method checkCode.

private void checkCode(Code code) {
    if (code == null)
        return;
    for (Instruction i : code.getInstructions().getInstructions()) {
        if (!(i instanceof InvokeInstruction))
            continue;
        InvokeInstruction ii = (InvokeInstruction) i;
        Assert.assertTrue(ii.getMethod().getName().length() > Deob.OBFUSCATED_NAME_MAX_LEN || ii.getMethod().getClazz().getName().length() > Deob.OBFUSCATED_NAME_MAX_LEN);
    }
}
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)

Example 78 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class PacketWriteDeobfuscator method isEnd.

private boolean isEnd(InstructionContext ctx) {
    // conditions where packet write ends:
    // any invoke that isn't to the packet buffer
    // any variable assignment
    // any field assignment
    // any conditional jump
    // any return
    Instruction i = ctx.getInstruction();
    if (i instanceof InvokeInstruction) {
        InvokeInstruction ii = (InvokeInstruction) i;
        Method method = ii.getMethod();
        if (!method.getClazz().equals(rw.getSecretBuffer().getPoolClass()) && !method.getClazz().equals(rw.getBuffer().getPoolClass())) {
            return true;
        }
    }
    if (i instanceof LVTInstruction) {
        LVTInstruction lvt = (LVTInstruction) i;
        if (lvt.store()) {
            return true;
        }
    }
    if (i instanceof SetFieldInstruction) {
        return true;
    }
    if (i instanceof If || i instanceof If0) {
        return true;
    }
    if (i instanceof ReturnInstruction) {
        return true;
    }
    return false;
}
Also used : InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) If0(net.runelite.asm.attributes.code.instructions.If0) Method(net.runelite.asm.pool.Method) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) If(net.runelite.asm.attributes.code.instructions.If)

Example 79 with Instruction

use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.

the class PacketWriteDeobfuscator method insert.

private void insert(ClassGroup group, PacketWrite write) {
    Instructions instructions = write.putOpcode.getInstruction().getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    InstructionContext firstWrite = write.writes.get(0);
    InstructionContext lastWrite = write.writes.get(write.writes.size() - 1);
    int idx = ins.indexOf(lastWrite.getInstruction());
    assert idx != -1;
    // past write
    ++idx;
    Label afterWrites = instructions.createLabelFor(ins.get(idx));
    // pops arg, getfield
    InstructionContext beforeFirstWrite = firstWrite.getPops().get(1).getPushed();
    Label putOpcode = instructions.createLabelFor(beforeFirstWrite.getInstruction(), true);
    idx = ins.indexOf(beforeFirstWrite.getInstruction());
    assert idx != -1;
    --idx;
    net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
    instructions.addInstruction(idx++, new GetStatic(instructions, field));
    instructions.addInstruction(idx++, new IfEq(instructions, putOpcode));
    Instruction before = ins.get(idx);
    for (InstructionContext ctx : write.writes) {
        insert(instructions, ctx, before);
    }
    idx = ins.indexOf(before);
    instructions.addInstruction(idx++, new Goto(instructions, afterWrites));
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Goto(net.runelite.asm.attributes.code.instructions.Goto) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Example 80 with Instruction

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

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)109 Instructions (net.runelite.asm.attributes.code.Instructions)69 Code (net.runelite.asm.attributes.Code)48 LDC (net.runelite.asm.attributes.code.instructions.LDC)39 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)32 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)32 ClassGroup (net.runelite.asm.ClassGroup)31 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)29 IMul (net.runelite.asm.attributes.code.instructions.IMul)28 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)28 Test (org.junit.Test)27 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)25 Method (net.runelite.asm.Method)24 IStore (net.runelite.asm.attributes.code.instructions.IStore)24 Execution (net.runelite.asm.execution.Execution)23 Deobfuscator (net.runelite.deob.Deobfuscator)22 Label (net.runelite.asm.attributes.code.Label)19 ArrayList (java.util.ArrayList)17 InstructionContext (net.runelite.asm.execution.InstructionContext)17 Field (net.runelite.asm.Field)16