use of org.objectweb.asm.util.TraceClassVisitor in project drill by axbaretto.
the class AsmUtil method logClass.
/**
* Write a class to the log.
*
* <p>
* Writes at level TRACE.
*
* @param logger
* the logger to write to
* @param logTag
* a tag to print to the log
* @param classNode
* the class
*/
public static void logClass(final Logger logger, final String logTag, final ClassNode classNode) {
if (logger.isTraceEnabled()) {
logger.trace(logTag);
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final TraceClassVisitor traceClassVisitor = new TraceClassVisitor(printWriter);
classNode.accept(traceClassVisitor);
logger.trace(stringWriter.toString());
}
}
use of org.objectweb.asm.util.TraceClassVisitor in project drill by axbaretto.
the class ReplaceMethodInvoke method main.
// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ReplaceMethodInvoke.class);
public static void main(String[] args) throws Exception {
final String k2 = "org/apache/drill/Pickle.class";
final URL url = Resources.getResource(k2);
final byte[] clazz = Resources.toByteArray(url);
final ClassReader cr = new ClassReader(clazz);
final ClassWriter cw = writer();
final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
// | ClassReader.SKIP_DEBUG);
cr.accept(v2, ClassReader.EXPAND_FRAMES);
final byte[] output = cw.toByteArray();
Files.write(output, new File("/src/scratch/bytes/S.class"));
check(output);
final DrillConfig c = DrillConfig.forClient();
final SystemOptionManager m = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c), new LocalPersistentStoreProvider(c), c);
m.init();
try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
clz.getMethod("x").invoke(null);
}
}
use of org.objectweb.asm.util.TraceClassVisitor in project cdap by caskdata.
the class Debugs method debugByteCode.
public static void debugByteCode(ClassDefinition classDefinition, PrintWriter writer) {
ClassReader reader = new ClassReader(classDefinition.getBytecode());
reader.accept(new CheckClassAdapter(new TraceClassVisitor(writer)), 0);
File file = new File("/tmp/" + classDefinition.getInternalName() + ".class");
file.getParentFile().mkdirs();
writer.println(file);
writer.flush();
try {
ByteStreams.write(classDefinition.getBytecode(), Files.newOutputStreamSupplier(file));
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.objectweb.asm.util.TraceClassVisitor in project phosphor by gmu-swe.
the class TaintLoadCoercer method main.
public static void main(String[] args) throws Throwable {
Configuration.IMPLICIT_TRACKING = true;
Configuration.MULTI_TAINTING = true;
// Configuration.IMPLICIT_LIGHT_TRACKING = true;
// Configuration.ARRAY_LENGTH_TRACKING = true;
Configuration.ARRAY_INDEX_TRACKING = true;
// Configuration.ANNOTATE_LOOPS = true;
// Instrumenter.instrumentClass("asdf", new FileInputStream("z.class"), false);
ClassReader cr = new ClassReader(new FileInputStream("z.class"));
// ClassReader cr = new ClassReader(new FileInputStream("target/classes/VarInLoop.class"));
final String className = cr.getClassName();
PrintWriter pw = new PrintWriter("z.txt");
TraceClassVisitor tcv = new TraceClassVisitor(null, new PhosphorTextifier(), pw);
ClassWriter cw1 = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {
@Override
protected String getCommonSuperClass(String arg0, String arg1) {
try {
return super.getCommonSuperClass(arg0, arg1);
} catch (Throwable t) {
return "java/lang/Object";
}
}
};
cr.accept(new ClassVisitor(Opcodes.ASM5, cw1) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv = new JSRInlinerAdapter(mv, access, name, desc, signature, exceptions);
return mv;
}
}, ClassReader.EXPAND_FRAMES);
cr = new ClassReader(cw1.toByteArray());
ClassVisitor cv = new ClassVisitor(Opcodes.ASM5, tcv) {
String className;
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
this.className = name;
}
HashSet<FieldNode> fields = new HashSet<FieldNode>();
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
fields.add(new FieldNode(access, name, desc, signature, value));
return super.visitField(access, name, desc, signature, value);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// TODO Auto-generated method stub
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv = new MethodVisitor(Opcodes.ASM5, mv) {
@Override
public void visitInsn(int opcode) {
super.visitInsn(opcode);
}
};
// mv = new SpecialOpcodeRemovingMV(mv,false,className,false);
// NeverNullArgAnalyzerAdapter analyzer = new NeverNullArgAnalyzerAdapter(className, access, className, desc, mv);
mv = new TaintLoadCoercer(className, access, name, desc, signature, exceptions, mv, true);
// LocalVariableManager lvs = new LocalVariableManager(access, desc, mv, analyzer, mv, false);
// mv = lvs;
PrimitiveArrayAnalyzer paa = new PrimitiveArrayAnalyzer(className, access, name, desc, signature, exceptions, mv);
NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(className, access, name, desc, paa);
paa.setAnalyzer(an);
// ((PrimitiveArrayAnalyzer) mv).setAnalyzer(an);
mv = an;
return mv;
}
};
cr.accept(cv, ClassReader.EXPAND_FRAMES);
pw.flush();
}
use of org.objectweb.asm.util.TraceClassVisitor in project phosphor by gmu-swe.
the class DebugPrinter method main.
public static void main(String[] args) throws Exception {
// Configuration.IMPLICIT_TRACKING = true;
File clazz = new File(args[0]);
final ClassReader cr1 = new ClassReader(new FileInputStream(clazz));
PrintWriter pw = new PrintWriter(new FileWriter("z.txt"));
ClassWriter cw1 = new ClassWriter(ClassWriter.COMPUTE_FRAMES) {
@Override
protected String getCommonSuperClass(String type1, String type2) {
try {
return super.getCommonSuperClass(type1, type2);
} catch (Exception ex) {
// System.err.println("err btwn " + type1 + " " +type2);
return "java/lang/Unknown";
}
}
};
cr1.accept(new ClassVisitor(Opcodes.ASM4, cw1) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// TODO Auto-generated method stub
return new JSRInlinerAdapter(super.visitMethod(access, name, desc, signature, exceptions), access, name, desc, signature, exceptions);
}
}, ClassReader.EXPAND_FRAMES);
final ClassReader cr = new ClassReader(cw1.toByteArray());
TraceClassVisitor tcv = new TraceClassVisitor(new ClassVisitor(Opcodes.ASM5, new ClassWriter(0)) {
String className;
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
super.visit(version, access, name, signature, superName, interfaces);
this.className = name;
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
// TODO Auto-generated method stub
MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions);
mv = new PrimitiveArrayAnalyzer(cr.getClassName(), access, name, desc, signature, exceptions, mv);
NeverNullArgAnalyzerAdapter an = new NeverNullArgAnalyzerAdapter(cr.getClassName(), access, name, desc, mv);
((PrimitiveArrayAnalyzer) mv).setAnalyzer(an);
mv = an;
return mv;
}
}, pw);
cr.accept(tcv, ClassReader.EXPAND_FRAMES);
pw.flush();
}
Aggregations