use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class ModArith method findConstants.
// find associated constants with each field
private void findConstants(MethodContext mctx) {
for (InstructionContext ctx : mctx.getInstructionContexts()) {
if (ctx.getInstruction() instanceof FieldInstruction) {
FieldInstruction fi = (FieldInstruction) ctx.getInstruction();
if (fi.getMyField() == null) {
continue;
}
if ((!fi.getField().getType().equals(Type.INT) && !fi.getField().getType().equals(Type.LONG)) || fi.getField().getType().isArray()) {
continue;
}
FieldInfo fieldInfo = getFieldInfo(fi.getMyField());
List<InstructionContext> l = getInsInExpr(ctx, new HashSet(), false);
// check if this contains another field
boolean other = false;
boolean getter = false, setter = false;
for (InstructionContext i : l) {
if (i.getInstruction() instanceof FieldInstruction) {
FieldInstruction fi2 = (FieldInstruction) i.getInstruction();
Field myField = fi2.getMyField();
if (myField != null && myField != fi.getMyField()) {
Type t = myField.getType();
if (t.equals(fi.getMyField().getType())) {
other = true;
}
} else if (myField != null && myField == fi.getMyField()) {
if (fi2 instanceof SetFieldInstruction) {
setter = true;
} else {
getter = true;
}
}
}
}
// check if this is a constant assignment
boolean constant = false;
if (fi instanceof SetFieldInstruction) {
// value being set
InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
if (pushedsfi.getInstruction() instanceof LDC) {
constant = true;
}
}
for (InstructionContext i : l) {
if (i.getInstruction() instanceof LDC) {
PushConstantInstruction w = (PushConstantInstruction) i.getInstruction();
if (w.getConstant() instanceof Integer || w.getConstant() instanceof Long) {
AssociatedConstant n = new AssociatedConstant();
n.value = (Number) w.getConstant();
n.other = other;
n.constant = constant;
n.getter = getter;
n.setter = setter;
fieldInfo.constants.add(n);
}
}
}
}
}
}
use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.
the class MixinInjector method setOwnersToTargetClass.
private void setOwnersToTargetClass(ClassFile mixinCf, ClassFile cf, Method method, Map<net.runelite.asm.pool.Field, Field> shadowFields, Map<net.runelite.asm.pool.Method, CopiedMethod> copiedMethods) throws InjectionException {
ListIterator<Instruction> iterator = method.getCode().getInstructions().getInstructions().listIterator();
while (iterator.hasNext()) {
Instruction i = iterator.next();
if (i instanceof InvokeInstruction) {
InvokeInstruction ii = (InvokeInstruction) i;
CopiedMethod copiedMethod = copiedMethods.get(ii.getMethod());
if (copiedMethod != null) {
ii.setMethod(copiedMethod.obMethod.getPoolMethod());
// Pass through garbage value if the method has one
if (copiedMethod.hasGarbageValue) {
int garbageIndex = copiedMethod.obMethod.isStatic() ? copiedMethod.obMethod.getDescriptor().size() - 1 : copiedMethod.obMethod.getDescriptor().size();
iterator.previous();
iterator.add(new ILoad(method.getCode().getInstructions(), garbageIndex));
iterator.next();
}
} else if (ii.getMethod().getClazz().getName().equals(mixinCf.getName())) {
ii.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class(cf.getName()), ii.getMethod().getName(), ii.getMethod().getType()));
}
} else if (i instanceof FieldInstruction) {
FieldInstruction fi = (FieldInstruction) i;
Field shadowed = shadowFields.get(fi.getField());
if (shadowed != null) {
fi.setField(shadowed.getPoolField());
} else if (fi.getField().getClazz().getName().equals(mixinCf.getName())) {
fi.setField(new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(cf.getName()), fi.getField().getName(), fi.getField().getType()));
}
} else if (i instanceof PushConstantInstruction) {
PushConstantInstruction pi = (PushConstantInstruction) i;
if (mixinCf.getPoolClass().equals(pi.getConstant())) {
pi.setConstant(cf.getPoolClass());
}
}
verify(mixinCf, i);
}
}
Aggregations