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