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());
}
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);
}
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;
}
}
}
}
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);
}
}
}
}
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();
}
Aggregations