use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method canRemove.
private boolean canRemove(MethodContext mctx, Instructions ins, Instruction i) {
Set<InstructionContext> ctxs = new HashSet<>(mctx.getInstructonContexts(i));
if (!alwaysPoppedBySameInstruction(ctxs, i) || !alwaysPopsFromSameInstructions(ctxs, i)) {
return false;
}
if (i instanceof InvokeInstruction) {
// func1() + func2() vs func2() + func1() is not the same thing
return false;
}
int idx = ins.getInstructions().indexOf(i);
if (idx == -1) {
return false;
}
for (InstructionContext ictx : ctxs) {
for (StackContext sctx : ictx.getPops()) {
Instruction pushed = sctx.getPushed().getInstruction();
int idx2 = ins.getInstructions().indexOf(pushed);
if (idx2 == -1) {
return false;
}
assert idx > idx2;
// instructions, we can't move them
for (int j = idx2; j <= idx; ++j) {
Instruction i2 = ins.getInstructions().get(j);
if (i2 instanceof LVTInstruction) {
if (((LVTInstruction) i2).store()) {
return false;
}
}
if (i2 instanceof IInc) {
return false;
}
}
if (!canRemove(mctx, ins, pushed)) {
return false;
}
}
}
return true;
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class ExprArgOrder method insert.
private void insert(Instructions ins, InstructionContext ic, Instruction before) {
Instruction i = ic.getInstruction();
assert i.getInstructions() == null;
int idx = ins.getInstructions().indexOf(before);
assert idx != -1;
i.setInstructions(ins);
ins.addInstruction(idx, i);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class Mapping method merge.
public void merge(Mapping other) {
assert object == other.object;
count += other.count;
for (Instruction i : other.ins) {
addInstruction(i);
}
wasExecuted |= other.wasExecuted;
weight = Math.max(weight, other.weight);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class StaticInitializerIndexer method index.
public void index() {
for (ClassFile cf : group.getClasses()) {
Method method = cf.findMethod("<clinit>");
if (method == null) {
continue;
}
Instructions instructions = method.getCode().getInstructions();
for (Instruction i : instructions.getInstructions()) {
if (i.getType() != InstructionType.PUTSTATIC) {
continue;
}
PutStatic putstatic = (PutStatic) i;
if (!putstatic.getField().getClazz().equals(cf.getPoolClass()) || putstatic.getMyField() == null) {
continue;
}
fields.add(putstatic.getMyField());
}
}
logger.debug("Indexed {} statically initialized fields", fields.size());
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class HandlerFinder method findHandlers.
private List<PacketHandler> findHandlers(Method process, Field packetOpcode) {
List<PacketHandler> handlers = new ArrayList<>();
Instructions ins = process.getCode().getInstructions();
for (int j = 0; j < ins.getInstructions().size(); ++j) {
Instruction i = ins.getInstructions().get(j);
if (i.getType() != InstructionType.GETSTATIC) {
continue;
}
GetStatic gs = (GetStatic) i;
if (gs.getMyField() != packetOpcode) {
continue;
}
Instruction push = ins.getInstructions().get(j + 1);
if (!(push instanceof PushConstantInstruction)) {
continue;
}
PushConstantInstruction pci = (PushConstantInstruction) push;
if (!(pci.getConstant() instanceof Number)) {
continue;
}
int opcode = ((Number) pci.getConstant()).intValue();
if (opcode == -1) {
continue;
}
Instruction jump = ins.getInstructions().get(j + 2);
if (jump.getType() != InstructionType.IF_ICMPEQ && jump.getType() != InstructionType.IF_ICMPNE) {
continue;
}
Instruction start, end;
if (jump.getType() == InstructionType.IF_ICMPEQ) {
// this seems to not ever happen
start = ((If) jump).getJumps().get(0);
// end = ins.getInstructions().get(j + 3);
end = null;
} else {
start = ins.getInstructions().get(j + 3);
end = ((If) jump).getJumps().get(0);
}
PacketHandler handler = new PacketHandler(process, jump, start, push, opcode);
handlers.add(handler);
if (end != null) {
// Anything else which jumps to here instead needs to return.
insertReturn(ins, jump, end);
}
logger.info("Found packet handler {} opcode {}", handler, handler.getOpcode());
}
return handlers;
}
Aggregations