@Test public void testProcess() throws IOException, InjectionException { InputStream in = getClass().getResourceAsStream("Actor.class"); ClassFile cf = ClassUtil.loadClass(in); cf.setName("Actor"); cf.findMethod("bar").setDescriptor(new Signature("(LActor;I)I")); ClassGroup deobfuscated = new ClassGroup(); deobfuscated.addClass(cf); in = getClass().getResourceAsStream("Obfuscated.class"); ClassFile obcf = ClassUtil.loadClass(in); obcf.setName("Obfuscated"); obcf.findMethod("foo").setDescriptor(new Signature("(LObfuscated;I)I")); ClassGroup obfuscated = new ClassGroup(); obfuscated.addClass(obcf); Method method = cf.findMethod("bar"); assert method != null; Inject inject = new Inject(deobfuscated, obfuscated); InjectHookMethod injectHookMethod = new InjectHookMethod(inject); injectHookMethod.process(method); method = obcf.findMethod("foo"); assert method != null; Code code = method.getCode(); List<InvokeStatic> invokeIns = code.getInstructions().getInstructions().stream() .filter(i -> i instanceof InvokeStatic) .map(i -> (InvokeStatic) i) .filter(i -> i.getMethod().getClazz().getName().equals(HOOKS)) .collect(Collectors.toList()); assertTrue(!invokeIns.isEmpty()); assertEquals(2, invokeIns.size()); InvokeStatic invokeStatic = invokeIns.get(0); Signature signature = invokeStatic.getMethod().getType(); assertEquals(3, signature.size()); Type arg = signature.getTypeOfArg(1); assertEquals(RL_API_PACKAGE_BASE.replace('.', '/') + "Actor", arg.getInternalName()); }
public void process(Method method) throws InjectionException { Annotations an = method.getAnnotations(); if (an == null) { return; } Annotation a = an.find(DeobAnnotations.HOOK); if (a == null) { return; } String hookName = a.getElement().getString(); boolean end = a.getElements().size() == 2 && a.getElements().get(1).getValue().equals(true); inject(null, method, hookName, end, true); }
InjectHookMethod { public void process(Method method) throws InjectionException { Annotations an = method.getAnnotations(); if (an == null) { return; } Annotation a = an.find(DeobAnnotations.HOOK); if (a == null) { return; } String hookName = a.getElement().getString(); boolean end = a.getElements().size() == 2 && a.getElements().get(1).getValue().equals(true); inject(null, method, hookName, end, true); } }
InjectHookMethod { public void process(Method method) throws InjectionException { Annotations an = method.getAnnotations(); if (an == null) { return; } Annotation a = an.find(DeobAnnotations.HOOK); if (a == null) { return; } String hookName = a.getElement().getString(); boolean end = a.getElements().size() == 2 && a.getElements().get(1).getValue().equals(true); inject(null, method, hookName, end, true); } InjectHookMethod(Inject inject); }
InjectHookMethod { public void process(Method method) throws InjectionException { Annotations an = method.getAnnotations(); if (an == null) { return; } Annotation a = an.find(DeobAnnotations.HOOK); if (a == null) { return; } String hookName = a.getElement().getString(); boolean end = a.getElements().size() == 2 && a.getElements().get(1).getValue().equals(true); inject(null, method, hookName, end, true); } InjectHookMethod(Inject inject); void process(Method method); void inject(Method hookMethod, Method method, String name, boolean end, boolean useHooks); }
InjectHookMethod { public void process(Method method) throws InjectionException { Annotations an = method.getAnnotations(); if (an == null) { return; } Annotation a = an.find(DeobAnnotations.HOOK); if (a == null) { return; } String hookName = a.getElement().getString(); boolean end = a.getElements().size() == 2 && a.getElements().get(1).getValue().equals(true); inject(null, method, hookName, end, true); } InjectHookMethod(Inject inject); void process(Method method); void inject(Method hookMethod, Method method, String name, boolean end, boolean useHooks); static final String HOOKS; }