public static void main(String[] args) throws Exception { if (args.length != 2) { System.err.println("Usage: java net.java.btrace.runtime.ClassRenamer <class> <new-class-name>"); System.exit(1); } args[0] = args[0].replace('.', '/'); args[1] = args[1].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[1] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassRenamer(args[1], writer)); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.CatchInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new CatchInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.MethodEntryInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new MethodEntryInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.ArrayAllocInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new ArrayAllocInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.TypeCheckInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new TypeCheckInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.ThrowInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new ThrowInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.ErrorReturnInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new ErrorReturnInstrumentor(mv, null, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.MethodReturnInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new MethodReturnInstrumentor(mv, null, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); }
public static void main(final String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java net.java.btrace.runtime.LineNumberInstrumentor <class>"); System.exit(1); } args[0] = args[0].replace('.', '/'); FileInputStream fis = new FileInputStream(args[0] + ".class"); ClassReader reader = new ClassReader(new BufferedInputStream(fis)); FileOutputStream fos = new FileOutputStream(args[0] + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ClassVisitor(Opcodes.ASM4, writer) { public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); return new LineNumberInstrumentor(mv, args[0], args[0], access, name, desc); } }); fos.write(writer.toByteArray()); } }
private static byte[] removeMethods(byte[] buf) { ClassWriter writer = InstrumentUtils.newClassWriter(buf); ClassReader reader = new ClassReader(buf); InstrumentUtils.accept(reader, new MethodRemover(writer)); return writer.toByteArray(); }
private static byte[] removeMethods(byte[] buf) { ClassWriter writer = InstrumentUtils.newClassWriter(buf); ClassReader reader = new ClassReader(buf); InstrumentUtils.accept(reader, new MethodRemover(writer)); return writer.toByteArray(); }
private byte[] instrument(Class clazz, String cname, byte[] target) { byte[] instrumentedCode; try { ClassWriter writer = InstrumentUtils.newClassWriter(target); ClassReader reader = new ClassReader(target); Instrumentor i = new Instrumentor(clazz, className, btraceCode, onMethods, writer); InstrumentUtils.accept(reader, i); if (!i.hasMatch()) { BTraceLogger.debugPrint("*WARNING* No method was matched for class " + cname); // NOI18N } else { instrumentedClasses.add(cname.replace('/', '.')); } instrumentedCode = writer.toByteArray(); } catch (Throwable th) { BTraceLogger.debugPrint(th); return null; } BTraceLogger.dumpClass(cname, instrumentedCode); return instrumentedCode; }
private static byte[] injectExtensionContext(byte[] target) { try { ClassWriter writer = InstrumentUtils.newClassWriter(target); ClassReader reader = new ClassReader(target); ExtensionRuntimeProcessor injector = new ExtensionRuntimeProcessor(writer); InstrumentUtils.accept(reader, injector); return injector.isApplied() ? writer.toByteArray() : null; } catch (Throwable th) { BTraceLogger.debugPrint(th); return null; } }
private byte[] instrument(Class clazz, String cname, byte[] target) { byte[] instrumentedCode; try { ClassWriter writer = InstrumentUtils.newClassWriter(target); ClassReader reader = new ClassReader(target); Instrumentor i = new Instrumentor(clazz, className, btraceCode, onMethods, writer); InstrumentUtils.accept(reader, i); if (!i.hasMatch()) { BTraceLogger.debugPrint("*WARNING* No method was matched for class " + cname); // NOI18N } else { instrumentedClasses.add(cname.replace('/', '.')); } instrumentedCode = writer.toByteArray(); } catch (Throwable th) { BTraceLogger.debugPrint(th); return null; } BTraceLogger.dumpClass(cname, instrumentedCode); return instrumentedCode; }
private static byte[] injectExtensionContext(byte[] target) { try { ClassWriter writer = InstrumentUtils.newClassWriter(target); ClassReader reader = new ClassReader(target); ExtensionRuntimeProcessor injector = new ExtensionRuntimeProcessor(writer); InstrumentUtils.accept(reader, injector); return injector.isApplied() ? writer.toByteArray() : null; } catch (Throwable th) { BTraceLogger.debugPrint(th); return null; } }
protected void transform(String traceName) throws IOException { Trace btrace = loadTrace(traceName); ClassReader reader = new ClassReader(originalBC); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new Instrumentor(null, btrace.className, btrace.content, btrace.onMethods, writer)); transformedBC = writer.toByteArray(); System.err.println("==== " + traceName); }
@Override protected void transform(String traceName) throws IOException { ClassReader reader = new ClassReader(originalBC); ClassWriter writer = InstrumentUtils.newClassWriter(); InstrumentUtils.accept(reader, new ExtensionRuntimeProcessor(writer)); transformedBC = writer.toByteArray(); }
@Override public byte[] transform(ClassLoader loader, final String cname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { if (!hasSubclassChecks || classBeingRedefined != null || isBTraceClass(cname) || isSensitiveClass(cname)) { return null; } if (!skipRetransforms) { BTraceLogger.debugPrint("injecting <clinit> for " + cname); // NOI18N ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); ClinitInjector injector = new ClinitInjector(cw, className, cname); InstrumentUtils.accept(cr, injector); if (injector.isTransformed()) { byte[] instrumentedCode = cw.toByteArray(); BTraceLogger.dumpClass(cname + "_clinit", instrumentedCode); // NOI18N return instrumentedCode; } } else { BTraceLogger.debugPrint("client " + className + ": skipping transform for " + cname); // NOI18N } return null; } };
@Override public byte[] transform(ClassLoader loader, final String cname, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { if (!hasSubclassChecks || classBeingRedefined != null || isBTraceClass(cname) || isSensitiveClass(cname)) { return null; } if (!skipRetransforms) { BTraceLogger.debugPrint("injecting <clinit> for " + cname); // NOI18N ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES); ClinitInjector injector = new ClinitInjector(cw, className, cname); InstrumentUtils.accept(cr, injector); if (injector.isTransformed()) { byte[] instrumentedCode = cw.toByteArray(); BTraceLogger.dumpClass(cname + "_clinit", instrumentedCode); // NOI18N return instrumentedCode; } } else { BTraceLogger.debugPrint("client " + className + ": skipping transform for " + cname); // NOI18N } return null; } };
protected Trace loadTrace(String name) throws IOException { byte[] btrace = loadFile("traces/" + name + ".class"); ClassWriter writer = InstrumentUtils.newClassWriter(); Verifier verifier = new Verifier(new Preprocessor(writer)); InstrumentUtils.accept(new ClassReader(btrace), verifier); return new Trace(writer.toByteArray(), verifier.getOnMethods(), verifier.getClassName()); }