use of net.runelite.asm.signature.Signature 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.signature.Signature in project runelite by runelite.
the class ReflectionTransformer method transformFindClass.
// invokestatic java/lang/Class/forName(Ljava/lang/String;)Ljava/lang/Class;
// to
// invokestatic net/runelite/rs/Reflection/findClass(Ljava/lang/String;)Ljava/lang/Class;
private void transformFindClass(Instruction i) {
if (!(i instanceof InvokeStatic)) {
return;
}
InvokeStatic is = (InvokeStatic) i;
if (is.getMethod().getClazz().getName().equals("java/lang/Class") && is.getMethod().getName().equals("forName")) {
is.setMethod(new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "findClass", new Signature("(Ljava/lang/String;)Ljava/lang/Class;")));
logger.info("Transformed Class.forName call");
}
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class ReflectionTransformer method transformMethodName.
// invokevirtual java/lang/reflect/Method/getName()Ljava/lang/String;
// to
// invokestatic net/runelite/rs/Reflection/getMethodName(Ljava/lang/reflect/Method;)Ljava/lang/String;
private void transformMethodName(Instructions instructions, Instruction i) {
if (!(i instanceof InvokeVirtual)) {
return;
}
InvokeVirtual iv = (InvokeVirtual) i;
if (iv.getMethod().getClazz().getName().equals("java/lang/reflect/Method") && iv.getMethod().getName().equals("getName")) {
InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "getMethodName", new Signature("(Ljava/lang/reflect/Method;)Ljava/lang/String;")));
instructions.replace(iv, is);
logger.info("Transformed Method.getName call");
}
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class ReflectionTransformer method transformGetInt.
// invokevirtual java/lang/reflect/Field/getInt(Ljava/lang/Object;)I
private void transformGetInt(Instructions instructions, Instruction i) {
if (!(i instanceof InvokeVirtual)) {
return;
}
InvokeVirtual iv = (InvokeVirtual) i;
if (iv.getMethod().getClazz().getName().equals("java/lang/reflect/Field") && iv.getMethod().getName().equals("getInt")) {
InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "getInt", new Signature("(Ljava/lang/reflect/Field;Ljava/lang/Object;)I")));
instructions.replace(iv, is);
logger.info("Transformed Field.getInt call");
}
}
use of net.runelite.asm.signature.Signature in project runelite by runelite.
the class ReflectionTransformer method transformGetDeclaredField.
// invokevirtual java/lang/Class/getDeclaredField(Ljava/lang/String;)Ljava/lang/reflect/Field;
// to
// invokestatic net/runelite/rs/Reflection/findField
private void transformGetDeclaredField(Instructions instructions, Instruction i) {
if (!(i instanceof InvokeVirtual)) {
return;
}
InvokeVirtual iv = (InvokeVirtual) i;
if (iv.getMethod().getClazz().getName().equals("java/lang/Class") && iv.getMethod().getName().equals("getDeclaredField")) {
InvokeStatic is = new InvokeStatic(instructions, new net.runelite.asm.pool.Method(new net.runelite.asm.pool.Class("net/runelite/rs/Reflection"), "findField", new Signature("(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/reflect/Field;")));
instructions.replace(iv, is);
logger.info("Transformed Class.getDeclaredField call");
}
}
Aggregations