use of net.runelite.osb.inject.MethodHook in project runelite by runelite.
the class HookImporter method importHooks.
@Test
@Ignore
public void importHooks() {
int classes = 0, fields = 0, methods = 0, callbacks = 0;
for (String deobfuscatedClassName : hooks.keySet()) {
ClassHook ch = hooks.get(deobfuscatedClassName);
ClassFile cf = this.findClassWithObfuscatedName(ch.getClazz());
assert cf != null;
String implementsName = getAnnotation(cf.getAnnotations(), IMPLEMENTS);
if (implementsName.isEmpty()) {
cf.getAnnotations().addAnnotation(IMPLEMENTS, "value", deobfuscatedClassName);
++classes;
}
for (String deobfuscatedFieldName : ch.getFields().keySet()) {
FieldHook fh = ch.getFields().get(deobfuscatedFieldName);
String[] s = fh.getField().split("\\.");
Field f;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
f = this.findFieldWithObfuscatedName(cf2, s[1]);
} else if (s.length == 1) {
f = this.findFieldWithObfuscatedName(cf, fh.getField());
} else {
throw new RuntimeException();
}
assert f != null;
String exportedName = getAnnotation(f.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
f.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedFieldName);
++fields;
}
}
for (String deobfuscatedMethodName : ch.getMethods().keySet()) {
MethodHook mh = ch.getMethods().get(deobfuscatedMethodName);
String[] s = mh.getMethod().split("\\.");
Method m;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
m = this.findMethodWithObfuscatedName(cf2, s[1], mh.getClientDesc());
} else if (s.length == 1) {
m = this.findMethodWithObfuscatedName(cf, mh.getMethod(), mh.getClientDesc());
} else {
throw new RuntimeException();
}
assert m != null;
String exportedName = getAnnotation(m.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
++methods;
}
}
for (String deobfuscatedMethodName : ch.getCallbacks().keySet()) {
MethodHook mh = ch.getCallbacks().get(deobfuscatedMethodName);
String[] s = mh.getMethod().split("\\.");
Method m;
if (s.length == 2) {
ClassFile cf2 = this.findClassWithObfuscatedName(s[0]);
assert cf2 != null;
m = this.findMethodWithObfuscatedName(cf2, s[1], mh.getClientDesc());
} else if (s.length == 1) {
m = this.findMethodWithObfuscatedName(cf, mh.getMethod(), mh.getClientDesc());
} else {
throw new RuntimeException();
}
assert m != null;
String exportedName = getAnnotation(m.getAnnotations(), EXPORT);
if (exportedName.isEmpty()) {
m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
++callbacks;
}
}
}
System.out.println("Imported " + classes + " classes, " + fields + " fields, " + methods + " methods, " + callbacks + " callbacks");
}
Aggregations