use of net.runelite.asm.ClassFile in project runelite by runelite.
the class SimpleModArithTest method test2.
@Test
public void test2() throws IOException {
InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/deob/deobfuscators/arithmetic/TestClass2.class");
Assert.assertNotNull(in);
ClassGroup group = new ClassGroup();
ClassFile cf = ClassUtil.loadClass(in);
group.addClass(cf);
ModArith d1 = new ModArith();
d1.run(group);
d1.runOnce();
Deobfuscator d2 = new MultiplicationDeobfuscator();
d2.run(group);
Encryption e = d1.getEncryption();
Pair pair = e.getField(cf.findField("field2863").getPoolField());
Assert.assertEquals(378529589, (int) pair.getter);
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class MappingDumper method dumpJson.
@Test
public void dumpJson() throws IOException {
ClassGroup group = JarUtil.loadJar(new File(properties.getRsClient()));
Gson gson = new GsonBuilder().setPrettyPrinting().create();
JsonObject jObject = new JsonObject();
JsonArray jFields = new JsonArray();
JsonArray jMethods = new JsonArray();
for (ClassFile cf : group.getClasses()) {
String implName = DeobAnnotations.getImplements(cf);
String className = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
for (Field f : cf.getFields()) {
String exportName = DeobAnnotations.getExportedName(f.getAnnotations());
if (exportName == null) {
continue;
}
String fieldName = DeobAnnotations.getObfuscatedName(f.getAnnotations());
Type obfType = DeobAnnotations.getObfuscatedType(f);
Number getter = DeobAnnotations.getObfuscatedGetter(f);
JsonObject jField = new JsonObject();
jField.addProperty("name", exportName);
jField.addProperty("owner", f.isStatic() ? "" : implName);
jField.addProperty("class", className);
jField.addProperty("field", fieldName);
jField.addProperty("obfSignature", (obfType != null ? obfType.toString() : ""));
jField.addProperty("signature", f.getType().toString());
jField.addProperty("multiplier", (getter != null ? getter : 0));
jField.addProperty("static", f.isStatic());
jFields.add(jField);
}
for (Method m : cf.getMethods()) {
String exportName = DeobAnnotations.getExportedName(m.getAnnotations());
if (exportName == null) {
continue;
}
String methodName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
Signature obfSignature = DeobAnnotations.getObfuscatedSignature(m);
String predicate = DeobAnnotations.getObfuscatedValue(m);
JsonObject jMethod = new JsonObject();
jMethod.addProperty("name", exportName);
jMethod.addProperty("owner", m.isStatic() ? "" : implName);
jMethod.addProperty("class", className);
jMethod.addProperty("field", methodName);
jMethod.addProperty("obfSignature", (obfSignature != null ? obfSignature.toString() : ""));
jMethod.addProperty("signature", m.getDescriptor().toString());
jMethod.addProperty("predicate", (predicate != null ? predicate : ""));
jMethod.addProperty("static", m.isStatic());
jMethods.add(jMethod);
}
}
jObject.addProperty("runelite", "http://github.com/runelite");
jObject.addProperty("run", Instant.now().toString());
jObject.addProperty("gamepack", properties.getRsVersion());
jObject.add("fields", jFields);
jObject.add("methods", jMethods);
System.out.println(gson.toJson(jObject));
}
use of net.runelite.asm.ClassFile 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.ClassFile in project runelite by runelite.
the class UnreachedCodeTest method before.
@Before
public void before() throws IOException {
ClassFile cf = ClassUtil.loadClass(UnreachedCodeTest.class.getResourceAsStream("unreachedcode/UnreachableTest.class"));
Assert.assertNotNull(cf);
group = new ClassGroup();
group.addClass(cf);
}
use of net.runelite.asm.ClassFile in project runelite by runelite.
the class HookImporter method toObType.
private Type toObType(Type t) {
if (t.isPrimitive()) {
return t;
}
if (!t.getInternalName().startsWith("class") && !t.getInternalName().equals("client")) {
return t;
}
ClassFile cf = group.findClass(t.getInternalName());
assert cf != null;
Annotations an = cf.getAnnotations();
String obfuscatedName = an.find(OBFUSCATED_NAME).getElement().getString();
return Type.getType("L" + obfuscatedName + ";", t.getDimensions());
}
Aggregations