Search in sources :

Example 1 with ClassHook

use of net.runelite.osb.inject.ClassHook 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");
}
Also used : MethodHook(net.runelite.osb.inject.MethodHook) Field(net.runelite.asm.Field) ClassHook(net.runelite.osb.inject.ClassHook) ClassFile(net.runelite.asm.ClassFile) FieldHook(net.runelite.osb.inject.FieldHook) Method(net.runelite.asm.Method) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ClassFile (net.runelite.asm.ClassFile)1 Field (net.runelite.asm.Field)1 Method (net.runelite.asm.Method)1 ClassHook (net.runelite.osb.inject.ClassHook)1 FieldHook (net.runelite.osb.inject.FieldHook)1 MethodHook (net.runelite.osb.inject.MethodHook)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1