use of net.runelite.asm.Type in project runelite by runelite.
the class MappingDumper method dump.
@Test
public void dump() throws IOException {
ClassGroup group = JarUtil.loadJar(new File(properties.getRsClient()));
final String GAP = "%-40s";
int classes = 0, methods = 0, fields = 0;
StringBuilder mBuilder = new StringBuilder();
StringBuilder sBuilder = new StringBuilder();
StringBuilder tmp;
for (ClassFile cf : group.getClasses()) {
String implName = DeobAnnotations.getImplements(cf);
String className = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
if (implName != null) {
mBuilder.append("\n").append(implName).append(" -> ").append(className).append("\n");
++classes;
}
for (Field f : cf.getFields()) {
String exportName = DeobAnnotations.getExportedName(f.getAnnotations());
if (exportName == null) {
continue;
}
++fields;
String fieldName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
Type type = f.getType();
Number getter = DeobAnnotations.getObfuscatedGetter(f);
String fieldType = typeToString(type);
if (f.isStatic()) {
tmp = sBuilder;
} else {
tmp = mBuilder;
}
tmp.append("\t").append(String.format(GAP, fieldType)).append(String.format(GAP, exportName)).append(className).append(".").append(fieldName);
if (getter != null) {
tmp.append(" * ").append(getter).append("\n");
} else {
tmp.append("\n");
}
}
for (Method m : cf.getMethods()) {
String exportName = DeobAnnotations.getExportedName(m.getAnnotations());
if (exportName == null) {
continue;
}
methods++;
String methodName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
Signature signature = DeobAnnotations.getObfuscatedSignature(m);
String garbageValue = DeobAnnotations.getObfuscatedValue(m);
if (signature == null) {
signature = m.getDescriptor();
}
String returnType = typeToString(m.getDescriptor().getReturnValue());
String[] paramTypes = new String[signature.size()];
for (int i = 0; i < paramTypes.length; i++) {
paramTypes[i] = typeToString(signature.getTypeOfArg(i));
}
if (m.isStatic()) {
tmp = sBuilder;
} else {
tmp = mBuilder;
}
tmp.append("\t").append(String.format(GAP, returnType)).append(String.format(GAP, exportName)).append(className).append(".").append(methodName);
tmp.append("(");
for (int i = 0; i < paramTypes.length; i++) {
tmp.append(paramTypes[i]);
if (i == paramTypes.length - 1) {
if (garbageValue != null) {
tmp.append(" = ").append(garbageValue);
}
} else {
tmp.append(", ");
}
}
tmp.append(")\n");
}
}
System.out.println("RuneLite http://github.com/runelite");
System.out.println("Run " + Instant.now());
System.out.println("Classes: " + classes + ", methods: " + methods + ", fields: " + fields);
System.out.println("Gamepack " + properties.getRsVersion());
System.out.println(mBuilder.toString());
System.out.println("Static ->");
System.out.println(sBuilder.toString());
}
use of net.runelite.asm.Type 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.Type 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.Type in project runelite by runelite.
the class ConstructorMapper method toOtherSignature.
private Signature toOtherSignature(Signature s) {
Signature.Builder builder = new Signature.Builder().setReturnType(toOtherType(s.getReturnValue()));
for (Type t : s.getArguments()) {
Type other = toOtherType(t);
if (other == null) {
return null;
}
builder.addArgument(other);
}
return builder.build();
}
use of net.runelite.asm.Type in project runelite by runelite.
the class ConstructorMapper method toOtherType.
private Type toOtherType(Type type) {
if (type.isPrimitive()) {
return type;
}
ClassFile cf = source.findClass(type.getInternalName());
if (cf == null) {
return type;
}
ClassFile other = (ClassFile) mapping.get(cf);
if (other == null) {
logger.debug("Unable to map other type due to no class mapping for {}", cf);
return null;
}
return new Type("L" + other.getName() + ";");
}
Aggregations