use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class PacketHandlerOrder method insertPacketLength.
private void insertPacketLength(ClassGroup group, PacketTypeFinder ptf) {
PacketLengthFinder pfl = new PacketLengthFinder(group, ptf);
pfl.find();
GetStatic getArray = pfl.getGetArray();
// instruction to store packet length
PutStatic ps = pfl.getStore();
Instructions instructions = ps.getInstructions();
List<Instruction> ins = instructions.getInstructions();
Label getArrayLabel = instructions.createLabelFor(getArray);
Label storeLabel = instructions.createLabelFor(ps);
int idx = ins.indexOf(getArray);
assert idx != -1;
// to go before label, which must exist
--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, getArrayLabel));
// 2 byte length
instructions.addInstruction(idx++, new LDC(instructions, -2));
instructions.addInstruction(idx++, new Goto(instructions, storeLabel));
}
use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class UnreachedCode method removeUnused.
private int removeUnused(Method m) {
Instructions ins = m.getCode().getInstructions();
int count = 0;
List<Instruction> insCopy = new ArrayList<>(ins.getInstructions());
for (int j = 0; j < insCopy.size(); ++j) {
Instruction i = insCopy.get(j);
if (!execution.executed.contains(i)) {
// if this is an exception handler, the exception handler is never used...
for (net.runelite.asm.attributes.code.Exception e : new ArrayList<>(m.getCode().getExceptions().getExceptions())) {
if (e.getStart().next() == i) {
e.setStart(ins.createLabelFor(insCopy.get(j + 1)));
if (e.getStart().next() == e.getEnd().next()) {
m.getCode().getExceptions().remove(e);
continue;
}
}
if (e.getHandler().next() == i) {
m.getCode().getExceptions().remove(e);
}
}
if (i instanceof Label)
continue;
ins.remove(i);
++count;
}
}
return count;
}
use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class DupDeobfuscator method undup2_x1.
private void undup2_x1(InstructionContext ictx) {
assert ictx.getInstruction() instanceof Dup2_X1;
// only support this form
assert ictx.getPops().size() == 2;
// I L -> L I L
Instructions instructions = ictx.getInstruction().getInstructions();
// can't swap a long on the stack, so
int idx = instructions.getInstructions().indexOf(ictx.getInstruction());
assert idx != -1;
// remove dup2_x1
instructions.remove(ictx.getInstruction());
// pop long
instructions.addInstruction(idx++, new Pop2(instructions));
// pop int
instructions.addInstruction(idx++, new Pop(instructions));
// insert copy of long
idx = copy(ictx.getPops().get(0), instructions, idx);
// insert copy of int
idx = copy(ictx.getPops().get(1), instructions, idx);
// insert copy of long
/* idx = */
copy(ictx.getPops().get(0), instructions, idx);
}
use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class DupDeobfuscator method undup_x1.
private void undup_x1(InstructionContext ictx) {
assert ictx.getInstruction() instanceof Dup_X1;
Instructions instructions = ictx.getInstruction().getInstructions();
StackContext duplicated = ictx.getPops().get(0);
// replace dup_x1 with swap
int idx = instructions.replace(ictx.getInstruction(), new Swap(instructions));
// copy imul and insert after idx
copy(duplicated, instructions, idx + 1);
}
use of net.runelite.asm.attributes.code.Instructions in project runelite by runelite.
the class DupDeobfuscator method undup.
private void undup(InstructionContext ictx) {
assert ictx.getInstruction() instanceof Dup;
Instructions instructions = ictx.getInstruction().getInstructions();
StackContext duplicated = ictx.getPops().get(0);
int idx = instructions.getInstructions().indexOf(ictx.getInstruction());
assert idx != -1;
// replace dup with duplicated instructions
instructions.remove(ictx.getInstruction());
// insert copy
copy(duplicated, instructions, idx);
}
Aggregations