private void completeClass(WovenClass wovenClass) { // System.out.println("Woven: "+wovenClass); ClassReader cr = new ClassReader(wovenClass.getBytes()); LabelAnalyzer labelAnalyzer = new LabelAnalyzer(); cr.accept(labelAnalyzer, 0); Map<String, Label> tag2Label = labelAnalyzer.getTag2Label(); /* for (Entry<String, Label> entry : tag2Label.entrySet()) { System.out.println(entry.getKey() + "=" + entry.getValue() + "(" + entry.getValue().info + ")"); }*/ ClassWriter cw = new ClassWriter(cr, 0); ClassAdapter ca = new JumpTransformer(cw, wovenClass.getClassName().replace(".", "/"), tag2Label); cr.accept(ca, 0); wovenClass.setBytes(cw.toByteArray()); }
public void test() throws Exception { ClassReader cr = new ClassReader(is); ClassWriter cw = new ClassWriter(true, true); cr.accept(new ClassAdapter(cw) { public MethodVisitor visitMethod( int access, String name, String desc, String signature, String[] exceptions) { return new LocalVariablesSorter(access, desc, super.visitMethod(access, name, desc, signature, exceptions)); } }, false); byte[] b = cw.toByteArray(); try { LOADER.defineClass(n, b); } catch (ClassFormatError cfe) { fail(cfe.getMessage()); } catch (Throwable ignored) { } }
byte[] nullAdaptClass(final InputStream is, final String name) throws Exception { ClassReader cr = new ClassReader(is); ClassWriter cw = new ClassWriter(compute); ClassAdapter ca = new ClassAdapter(cw); cr.accept(ca, skipDebug); return cw.toByteArray(); }
byte[] counterAdaptClass(final InputStream is, final String name) throws Exception { ClassReader cr = new ClassReader(is); ClassWriter cw = new ClassWriter(false); ClassAdapter ca = new CounterClassAdapter(cw); cr.accept(ca, false); return cw.toByteArray(); }