use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class HandlerFinder method insertReturn.
private void insertReturn(Instructions ins, Instruction start, Instruction end) {
assert end instanceof Label;
int idx = ins.getInstructions().indexOf(end);
assert idx != -1;
Instruction before = ins.getInstructions().get(idx - 1);
if (// XXX check isTerminal?
before.getType() == InstructionType.RETURN) {
return;
}
// insert return before end
logger.info("Inserting return before {}", end);
Instruction ret = new VReturn(ins);
ins.addInstruction(idx, ret);
Label label = ins.createLabelFor(ret);
// Change jumps which go to the next handler to instead go to return
for (Instruction i : ins.getInstructions()) {
if (i instanceof JumpingInstruction) {
JumpingInstruction j = (JumpingInstruction) i;
if (i == start) {
continue;
}
if (j.getJumps().size() == 1 && j.getJumps().get(0) == end) {
j.setJumps(Collections.singletonList(label));
}
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class PacketLengthFinder method run.
// getstatic class272/field3690 [I
// getstatic Client/packetType I
// iaload
// putstatic Client/packetLength I
private void run(Code code) {
if (code == null) {
return;
}
Instructions instructions = code.getInstructions();
Field type = packetType.getPacketType();
for (int i = 0; i < instructions.getInstructions().size() - 3; ++i) {
Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1), i3 = instructions.getInstructions().get(i + 2), i4 = instructions.getInstructions().get(i + 3);
if (!(i1 instanceof GetStatic)) {
continue;
}
if (!(i2 instanceof GetStatic)) {
continue;
}
GetStatic gs = (GetStatic) i2;
if (gs.getMyField() != type) {
continue;
}
if (!(i3 instanceof IALoad)) {
continue;
}
if (!(i4 instanceof PutStatic)) {
continue;
}
PutStatic ps = (PutStatic) i4;
assert packetLength == null : "packetLength already found";
packetLength = ps.getMyField();
getArray = (GetStatic) i1;
getType = gs;
load = (IALoad) i3;
store = ps;
return;
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class PacketTypeFinder method run.
private void run(Code code) {
if (code == null) {
return;
}
Instructions instructions = code.getInstructions();
for (int i = 0; i < instructions.getInstructions().size() - 1; ++i) {
Instruction i1 = instructions.getInstructions().get(i), i2 = instructions.getInstructions().get(i + 1);
if (i1 instanceof PushConstantInstruction && i2.getType() == InstructionType.PUTSTATIC) {
PushConstantInstruction pci = (PushConstantInstruction) i1;
SetFieldInstruction sfi = (SetFieldInstruction) i2;
Field field = sfi.getMyField();
if (Objects.equal(-1, pci.getConstant()) && field != null) {
Integer count = sets.get(field);
if (count == null) {
sets.put(field, 1);
} else {
sets.put(field, count + 1);
}
}
}
}
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class OpcodeReplacer method run.
public void run(ClassGroup group, Collection<PacketWrite> writes) {
int count = 0;
ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
assert runeliteOpcodes != null : "Opcodes class must exist";
for (PacketWrite wp : writes) {
Instructions ins = wp.getInstructions();
Instruction param = wp.getOpcodeIns();
if (!(param instanceof PushConstantInstruction)) {
continue;
}
final String fieldName = "PACKET_CLIENT_" + wp.getOpcode();
net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(RUNELITE_OPCODES), fieldName, Type.INT);
ins.replace(param, new GetStatic(ins, field));
if (runeliteOpcodes.findField(fieldName) == null) {
Field opField = new Field(runeliteOpcodes, fieldName, Type.INT);
// ACC_FINAL causes javac to inline the fields, which prevents
// the mapper from doing field mapping
opField.setAccessFlags(ACC_PUBLIC | ACC_STATIC);
// setting a non-final static field value
// doesn't work with fernflower
opField.setValue(wp.getOpcode());
runeliteOpcodes.addField(opField);
// add initialization
Method clinit = runeliteOpcodes.findMethod("<clinit>");
assert clinit != null;
Instructions instructions = clinit.getCode().getInstructions();
instructions.addInstruction(0, new LDC(instructions, wp.getOpcode()));
instructions.addInstruction(1, new PutStatic(instructions, opField));
}
++count;
}
logger.info("Injected {} packet writes", count);
}
use of net.runelite.asm.attributes.code.Instruction in project runelite by runelite.
the class UnusedParameters method visit.
private void visit(InstructionContext ictx) {
Instruction i = ictx.getInstruction();
if (!(i instanceof InvokeInstruction)) {
return;
}
invokes.put(i, ictx);
}
Aggregations