use of net.runelite.asm.attributes.code.Instructions 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.Instructions in project runelite by runelite.
the class IfICmpEqTest method testIsSame.
@Test
public void testIsSame() {
Instructions ins = mock(Instructions.class);
Frame frame = mock(Frame.class);
Stack stack = new Stack(42);
Variables variables = new Variables(42);
when(frame.getStack()).thenReturn(stack);
when(frame.getVariables()).thenReturn(variables);
IfICmpEq ifeq = new IfICmpEq(ins, InstructionType.IF_ICMPEQ);
InstructionContext ifeqCtx = new InstructionContext(ifeq, frame);
ifeqCtx.pop(new StackContext(getConstantCtx(ins, 1), INT, new Value(1)));
ifeqCtx.pop(new StackContext(getConstantCtx(ins, 1), INT, new Value(1)));
IfNe ifne = new IfNe(ins, InstructionType.IFNE);
InstructionContext ifneCtx = new InstructionContext(ifne, frame);
ifneCtx.pop(new StackContext(getConstantCtx(ins, 42), INT, new Value(42)));
assertTrue(ifeq.isSame(ifeqCtx, ifneCtx));
}
use of net.runelite.asm.attributes.code.Instructions 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;
}
use of net.runelite.asm.attributes.code.Instructions 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.Instructions 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);
}
}
}
}
}
Aggregations