use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class BufferMethodInjector method inject.
private void inject(ClassFile bufferClass, Method method) {
assert method.getExceptions().getExceptions().isEmpty();
Method newMethod = new Method(bufferClass, method.getName(), method.getDescriptor());
Code code = new Code(newMethod);
newMethod.setCode(code);
method.getCode().getInstructions().getInstructions().stream().forEach(i -> {
if (!(i instanceof Label)) {
i = i.clone();
}
if (i instanceof FieldInstruction) {
FieldInstruction fi = (FieldInstruction) i;
if (fi.getField().getName().equals("offset")) {
fi.setField(bp.getOffset().getPoolField());
} else if (fi.getField().getName().equals("payload")) {
fi.setField(bp.getBuffer().getPoolField());
} else if (fi.getField().getName().equals("runeliteLengthOffset")) {
fi.setField(bufferClass.findField("runeliteLengthOffset").getPoolField());
}
}
i.setInstructions(code.getInstructions());
code.getInstructions().addInstruction(i);
});
code.getExceptions().getExceptions().addAll(method.getCode().getExceptions().getExceptions());
bufferClass.addMethod(newMethod);
}
use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class FieldInliner method findFieldIns.
private void findFieldIns() {
for (ClassFile cf : group.getClasses()) {
for (Method m : cf.getMethods()) {
Code code = m.getCode();
if (code == null)
continue;
for (Instruction i : code.getInstructions().getInstructions()) {
if (!(i instanceof FieldInstruction))
continue;
FieldInstruction sf = (FieldInstruction) i;
if (sf.getMyField() == null)
continue;
fieldInstructions.put(sf.getMyField(), sf);
}
}
}
}
use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class FieldInliner method inlineUse.
public int inlineUse() {
int count = 0;
for (Field f : fields) {
// replace getfield with constant push
List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
Object value = f.getValue();
for (FieldInstruction fin : fins) {
// remove fin, add push constant
Instruction i = (Instruction) fin;
Instruction pushIns = new LDC(i.getInstructions(), value);
List<Instruction> instructions = i.getInstructions().getInstructions();
int idx = instructions.indexOf(i);
assert idx != -1;
i.getInstructions().remove(i);
instructions.add(idx, pushIns);
++count;
}
f.getClassFile().removeField(f);
}
return count;
}
use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class FieldInliner method makeConstantValues.
private void makeConstantValues() {
for (ClassFile cf : group.getClasses()) {
for (Field f : cf.getFields()) {
if (!f.isStatic() || !f.getType().equals(Type.STRING))
continue;
Object constantValue = f.getValue();
if (constantValue != null)
continue;
List<FieldInstruction> sfis = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof SetFieldInstruction).collect(Collectors.toList());
if (sfis.size() != 1)
continue;
SetFieldInstruction sfi = (SetFieldInstruction) sfis.get(0);
Instruction ins = (Instruction) sfi;
Method mOfSet = ins.getInstructions().getCode().getMethod();
if (!mOfSet.getName().equals("<clinit>"))
continue;
// get prev instruction and change to a constant value
Instructions instructions = mOfSet.getCode().getInstructions();
int idx = instructions.getInstructions().indexOf(ins);
assert idx != -1;
Instruction prev = instructions.getInstructions().get(idx - 1);
if (!(prev instanceof PushConstantInstruction))
continue;
PushConstantInstruction pci = (PushConstantInstruction) prev;
constantValue = pci.getConstant();
f.setValue(constantValue);
fields.add(f);
boolean b = instructions.getInstructions().remove(prev);
assert b;
b = instructions.getInstructions().remove(ins);
assert b;
}
}
}
use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class CodeVisitor method visitFieldInsn.
@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
FieldInstruction i = (FieldInstruction) createInstructionFromOpcode(opcode);
Field field = new Field(new net.runelite.asm.pool.Class(owner), name, new Type(desc));
i.setField(field);
}
Aggregations