use of net.runelite.asm.Field in project runelite by runelite.
the class ModArith method guess.
private void guess() {
for (ClassFile cf : group.getClasses()) {
for (Field f : cf.getFields()) {
FieldInfo fieldInfo = getFieldInfo(f);
// all constants in instructions associated with the field
Collection<AssociatedConstant> col = fieldInfo.constants;
if (col.isEmpty()) {
continue;
}
Type type = f.getType();
assert type.equals(Type.INT) || type.equals(Type.LONG);
Class typeOfField = type.equals(Type.INT) ? Integer.class : Long.class;
// filter collect constants of the correct type
Collection<AssociatedConstant> col2 = col.stream().filter(i -> i.value.getClass() == typeOfField).collect(Collectors.toList());
// filer out ones that have another field in the expression
List<Number> noOther = col2.stream().filter(i -> !i.other && !i.constant).map(i -> i.value).distinct().collect(Collectors.toList());
List<Number> other = col2.stream().filter(i -> i.other || i.constant).map(i -> i.value).collect(Collectors.toList());
other.addAll(noOther);
other = ImmutableSet.copyOf(other).asList();
// guess with constants not associated with other fields
Pair p = this.guess(f, noOther);
if (p == null) {
// fall back to all constants
p = this.guess(f, other);
}
// check that this guess doesn't increase constants
if (p != null && !fieldInfo.guessDecreasesConstants(p)) {
continue;
}
if (p != null) {
pairs.add(p);
}
}
}
}
use of net.runelite.asm.Field 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.Field in project runelite by runelite.
the class AnnotationIntegrityChecker method checkAnnotationCounts.
private void checkAnnotationCounts() {
for (ClassFile cf : two.getClasses()) {
for (Field f : cf.getFields()) {
int num = this.getNumberOfExports(f.getAnnotations());
if (num > 1) {
logger.warn("Field {} has more than 1 export", f);
++errors;
}
}
for (Method m : cf.getMethods()) {
int num = this.getNumberOfExports(m.getAnnotations());
if (num > 1) {
logger.warn("Method {} has more than 1 export", m);
++errors;
}
}
}
}
use of net.runelite.asm.Field in project runelite by runelite.
the class AnnotationIntegrityChecker method run.
public void run() {
for (ClassFile cf : one.getClasses()) {
ClassFile other = (ClassFile) mapping.get(cf);
List<Field> exf1 = getExportedFields(cf);
List<Method> exm1 = getExportedMethods(cf);
for (Field f1 : exf1) {
boolean isImported = isImported(cf, f1.getName(), f1.isStatic());
Field f2;
if (other == null) {
if (!f1.isStatic() && isImported) {
++errors;
logger.error("No other class for {} which contains imported field {}", cf, f1);
}
continue;
}
if (f1.isStatic()) {
f2 = findExportedFieldStatic(two, DeobAnnotations.getExportedName(f1.getAnnotations()));
} else {
f2 = findExportedField(other, DeobAnnotations.getExportedName(f1.getAnnotations()));
}
if (f2 == null) {
if (isImported) {
logger.error("Missing IMPORTED field on {} named {}", other, DeobAnnotations.getExportedName(f1.getAnnotations()));
++errors;
} else {
logger.warn("Missing exported field on {} named {}", other, DeobAnnotations.getExportedName(f1.getAnnotations()));
++warnings;
}
}
}
for (Method m1 : exm1) {
boolean isImported = isImported(cf, m1.getName(), m1.isStatic());
Method m2;
if (other == null) {
if (!m1.isStatic() && isImported) {
++errors;
logger.error("No other class for {} which contains imported method {}", cf, m1);
}
continue;
}
if (m1.isStatic()) {
m2 = findExportedMethodStatic(two, DeobAnnotations.getExportedName(m1.getAnnotations()));
} else {
m2 = findExportedMethod(other, DeobAnnotations.getExportedName(m1.getAnnotations()));
}
if (m2 == null) {
if (isImported) {
logger.error("Missing IMPORTED method on {} named {} ({})", other, DeobAnnotations.getExportedName(m1.getAnnotations()), m1);
++errors;
} else {
logger.warn("Missing exported method on {} named {} ({})", other, DeobAnnotations.getExportedName(m1.getAnnotations()), m1);
++warnings;
}
}
}
}
checkAnnotationCounts();
}
use of net.runelite.asm.Field 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;
}
}
Aggregations