Commit d98c357c authored by Lubomir Bulej's avatar Lubomir Bulej

Transformer, OnPlaceTransformer: cleaned up white space before merging subsequent changes.

parent ec428b4d
......@@ -10,19 +10,19 @@ import ch.usi.dag.disl.exception.DiSLException;
public class Transformer implements ClassFileTransformer {
private static DiSL __disl;
private static DiSL __disl;
static {
try {
// don't use dynamic bypass
static {
try {
// don't use dynamic bypass
__disl = new DiSL (false);
} catch (final DiSLException e) {
throw new RuntimeException (e);
}
}
}
//
//
@Override
public byte [] transform (
......@@ -33,36 +33,36 @@ public class Transformer implements ClassFileTransformer {
) throws IllegalClassFormatException {
byte [] instrumentedClass = null;
try {
try {
instrumentedClass = __disl.instrument (classfileBuffer);
if (instrumentedClass != null) {
/*
// print class
ClassReader cr = new ClassReader(instrumentedClass);
TraceClassVisitor tcv = new TraceClassVisitor(new PrintWriter(System.out));
cr.accept(tcv, 0);
/**/
/*
// print class
ClassReader cr = new ClassReader(instrumentedClass);
TraceClassVisitor tcv = new TraceClassVisitor(new PrintWriter(System.out));
cr.accept(tcv, 0);
/**/
/*
// check class
ClassReader cr2 = new ClassReader(instrumentedClass);
ClassWriter cw = new ClassWriter(cr2, ClassWriter.COMPUTE_MAXS);
cr2.accept(new CheckClassAdapter(cw), 0);
/**/
/*
// check class
ClassReader cr2 = new ClassReader(instrumentedClass);
ClassWriter cw = new ClassWriter(cr2, ClassWriter.COMPUTE_MAXS);
cr2.accept(new CheckClassAdapter(cw), 0);
/**/
/*
// output class
try {
File f = new File("ModifiedClass.class");
FileOutputStream fos = new FileOutputStream(f);
fos.write(instrumentedClass);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
/**/
}
/*
// output class
try {
File f = new File("ModifiedClass.class");
FileOutputStream fos = new FileOutputStream(f);
fos.write(instrumentedClass);
fos.flush();
fos.close();
} catch (Exception e) {
e.printStackTrace();
}
/**/
}
} catch (final Throwable e) {
e.printStackTrace ();
......
package ch.usi.dag.disl.testtools.onplace;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;
import ch.usi.dag.disl.DiSL;
public class OnPlaceTransformer {
public static void main(String[] args) throws Exception {
// INSTRUCTIONS: Under Eclipse call me with these jvm params (example)
// -Ddisltest.transform=bin/ch/usi/dag/disl/test/bodymarker/TargetClass.class
// -Ddisl.classes=bin/ch/usi/dag/disl/test/bodymarker/DiSLClass.class
// do not use dynamic bypass
DiSL disl = new DiSL(false);
String classToTransform = null;
if(args.length == 1) {
classToTransform = args[0];
}
if(classToTransform == null) {
classToTransform = System.getProperty("disltest.transform");
}
if(classToTransform == null) {
System.err.println("No class to transform...");
System.exit(1);
}
// get code as bytes
byte[] origCode = loadAsBytes(classToTransform);
// check class first
ClassReader cr = new ClassReader(origCode);
cr.accept(new CheckClassAdapter(
new TraceClassVisitor(new PrintWriter(System.out))), 0);
// instrument class
byte[] instrCode = disl.instrument(origCode);
if(instrCode != null) {
FileOutputStream fos = new FileOutputStream("ModifiedClass.class");
fos.write(instrCode);
fos.close();
}
}
// thx: http://www.java2s.com/Tutorial/Java/0180__File/Loadfiletobytearray.htm
public final static byte[] loadAsBytes(String file) throws IOException {
FileInputStream fin = new FileInputStream(file);
return loadAsBytes(fin);
}
public final static byte[] loadAsBytes(InputStream is) throws IOException {
byte readBuf[] = new byte[512 * 1024];
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readCnt = is.read(readBuf);
while (0 < readCnt) {
bout.write(readBuf, 0, readCnt);
readCnt = is.read(readBuf);
}
is.close();
return bout.toByteArray();
}
}
package ch.usi.dag.disl.testtools.onplace;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.util.CheckClassAdapter;
import org.objectweb.asm.util.TraceClassVisitor;
import ch.usi.dag.disl.DiSL;
public class OnPlaceTransformer {
public static void main(String[] args) throws Exception {
// INSTRUCTIONS: Under Eclipse call me with these jvm params (example)
// -Ddisltest.transform=bin/ch/usi/dag/disl/test/bodymarker/TargetClass.class
// -Ddisl.classes=bin/ch/usi/dag/disl/test/bodymarker/DiSLClass.class
// do not use dynamic bypass
DiSL disl = new DiSL(false);
String classToTransform = null;
if(args.length == 1) {
classToTransform = args[0];
}
if(classToTransform == null) {
classToTransform = System.getProperty("disltest.transform");
}
if(classToTransform == null) {
System.err.println("No class to transform...");
System.exit(1);
}
// get code as bytes
byte[] origCode = loadAsBytes(classToTransform);
// check class first
ClassReader cr = new ClassReader(origCode);
cr.accept(new CheckClassAdapter(
new TraceClassVisitor(new PrintWriter(System.out))), 0);
// instrument class
byte[] instrCode = disl.instrument(origCode);
if(instrCode != null) {
FileOutputStream fos = new FileOutputStream("ModifiedClass.class");
fos.write(instrCode);
fos.close();
}
}
// thx: http://www.java2s.com/Tutorial/Java/0180__File/Loadfiletobytearray.htm
public final static byte[] loadAsBytes(String file) throws IOException {
FileInputStream fin = new FileInputStream(file);
return loadAsBytes(fin);
}
public final static byte[] loadAsBytes(InputStream is) throws IOException {
byte readBuf[] = new byte[512 * 1024];
ByteArrayOutputStream bout = new ByteArrayOutputStream();
int readCnt = is.read(readBuf);
while (0 < readCnt) {
bout.write(readBuf, 0, readCnt);
readCnt = is.read(readBuf);
}
is.close();
return bout.toByteArray();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment