本文整理汇总了Java中org.objectweb.asm.util.TraceClassVisitor类的典型用法代码示例。如果您正苦于以下问题:Java TraceClassVisitor类的具体用法?Java TraceClassVisitor怎么用?Java TraceClassVisitor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TraceClassVisitor类属于org.objectweb.asm.util包,在下文中一共展示了TraceClassVisitor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
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);
cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);
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(c, new LocalPStoreProvider(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);
}
}
示例2: loadClass
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
private ClassNode loadClass(String name) {
return Try.apply(() -> {
String cname = name.replace("/", ".");
ClassNode node = cache.get(cname);
if (node == null) {
String rname = cname.replace(".", "/") + ".class";
try (InputStream in = loader.getResourceAsStream(rname)) {
if (in == null) {
throw new FileNotFoundException(rname + " using " + loader);
}
ClassReader reader = new ClassReader(ByteStreams.toByteArray(in));
node = new ClassNode();
reader.accept(node, 0);
cache.put(cname, node);
if (log.isDebugEnabled()) {
log.info("Source: {}; Class: {}", node.sourceFile, node.name);
reader.accept(
new TraceClassVisitor(null, new ASMifier(), new PrintWriter(writer(log, name))),
0);
}
}
}
return node;
}).get();
}
示例3: classNodeToBytes
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
private byte[] classNodeToBytes(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
byte[] bytes = writer.toByteArray();
// verify bytecode
if (verifyAndPrint) {
ClassReader reader = new ClassReader(bytes);
ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.out));
ClassVisitor checker = new CheckClassAdapter(tracer, true);
reader.accept(checker, 0);
}
return bytes;
}
示例4: dump
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
public static void dump(Acceptor acceptor, File file, boolean filterImportant, boolean sortLocals) {
try {
if(!file.getParentFile().exists())
file.getParentFile().mkdirs();
if(!file.exists())
file.createNewFile();
PrintWriter pout = new PrintWriter(file);
ClassVisitor cv = new TraceClassVisitor(pout);
if(filterImportant) cv = new ImportantInsnVisitor(cv);
if(sortLocals) cv = new LocalVariablesSorterVisitor(cv);
acceptor.accept(cv);
pout.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例5: classNodeToBytes
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
private byte[] classNodeToBytes(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
byte[] bytes = writer.toByteArray();
// verify bytecode
if (verifyAndPrint) {
ClassReader reader = new ClassReader(bytes);
ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.out));
ClassVisitor checker = new CheckClassAdapter(tracer, true);
reader.accept(checker, 0);
}
return bytes;
}
示例6: generate
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
@Override
protected void generate(TraceClassVisitor visitor) {
visitor.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT + Opcodes.ACC_INTERFACE,
"soot/asm/backend/targets/Comparable", null, "java/lang/Object",
new String[] { "soot/asm/backend/targets/Measurable" });
visitor.visitSource("Comparable.java", null);
visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "LESS", "I",
null, new Integer(-1)).visitEnd();
visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "EQUAL", "I",
null, new Integer(0)).visitEnd();
visitor.visitField(Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL + Opcodes.ACC_STATIC, "GREATER", "I",
null, new Integer(1)).visitEnd();
visitor.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_ABSTRACT, "compareTo",
"(Ljava/lang/Object;)I", null, null).visitEnd();
visitor.visitEnd();
}
示例7: generate
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
@Override
protected void generate(TraceClassVisitor cw) {
MethodVisitor mv;
cw.visit(V1_4, ACC_PUBLIC + ACC_ABSTRACT + ACC_INTERFACE,
"soot/asm/backend/targets/ExceptionMethods", null,
"java/lang/Object", null);
cw.visitSource("ExceptionMethods.java", null);
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "foo", "()V", null, new String[] { "java/lang/NullPointerException" });
mv.visitEnd();
}
cw.visitEnd();
}
示例8: generate
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
@Override
protected void generate(TraceClassVisitor cw) {
MethodVisitor mv;
cw.visit(V1_5, ACC_PUBLIC + ACC_ANNOTATION + ACC_ABSTRACT + ACC_INTERFACE,
"soot/asm/backend/targets/MyAnnotatedAnnotation", null,
"java/lang/Object", new String[] { "java/lang/annotation/Annotation" }); //TODO V1_1 seems wrong here
cw.visitSource("MyAnnotatedAnnotation.java", null);
{
mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "value",
"()Lsoot/asm/backend/targets/MyTestAnnotation;", null, null);
mv.visitEnd();
}
cw.visitEnd();
}
示例9: dumpASM
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
static void dumpASM(byte[] basicClass) {
ClassReader cr = new ClassReader(basicClass);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
File f = new File("/tmp/ASM/" + cn.name.replace("/", "_"));
try {
FileOutputStream os = new FileOutputStream(f);
cr.accept(new TraceClassVisitor(new PrintWriter(os)), 0);
os.close();
} catch (Throwable e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例10: main
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
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);
cr.accept(v2, ClassReader.EXPAND_FRAMES );//| ClassReader.SKIP_DEBUG);
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);
}
}
示例11: disassembleClass
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
private ClassBlock disassembleClass(ClassReader classReader, Block parent) throws UnsupportedVersionException {
Writer bytecodeStringWriter = new StringWriter();
ClassVisitor classVisitor = new TraceClassVisitor(new PrintWriter(bytecodeStringWriter));
classReader.accept(classVisitor, ClassReader.EXPAND_FRAMES);
ClassNode classNode = new ClassNode();
classReader.accept(classNode, ClassReader. EXPAND_FRAMES);
if (classNode.version < 51 || classNode.version > 52) {
throw new UnsupportedVersionException("Class files of version " + classNode.version + " are not supported");
}
ClassBlock classBlock = new ClassBlock(classNode, parent);
classBlock.setBytecode(bytecodeStringWriter.toString());
classBlock.disassemble();
return classBlock;
}
示例12: test
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
public void test() throws Exception {
Attribute[] attributes = new Attribute[] { new ASMStackMapTableAttribute() };
ClassWriter cw = new ClassWriter(false);
ClassReader cr1 = new ClassReader(is);
cr1.accept(cw, attributes, true);
ClassReader cr2 = new ClassReader(cw.toByteArray());
if (!Arrays.equals(cr1.b, cr2.b)) {
StringWriter sw1 = new StringWriter();
StringWriter sw2 = new StringWriter();
ClassVisitor cv1 = new TraceClassVisitor(new PrintWriter(sw1));
ClassVisitor cv2 = new TraceClassVisitor(new PrintWriter(sw2));
cr1.accept(cv1, attributes, true);
cr2.accept(cv2, attributes, true);
assertEquals("different data", sw1.toString(), sw2.toString());
}
}
示例13: toBytes
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
public byte[] toBytes() {
ClassNode classNode = new ClassNode(Opcodes.ASM5);
populate(classNode);
classNode.accept(new TraceClassVisitor(new PrintWriter(Debug.getPrintStream(Debug.LEVEL_HIGH))));
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
classNode.accept(classWriter);
boolean hasASMMethodNodes = classDom.getMethods().stream().map(x -> new StatementDomVisitor.Return<MethodNode>() {
@Override
public void visitASM(MethodNode methodNode) {
setResult(methodNode);
}
}.returnFrom(x.getBody())).anyMatch(x -> x != null);
try {
org.objectweb.asm.util.CheckClassAdapter.verify(new ClassReader(classWriter.toByteArray()), true, new PrintWriter(Debug.getPrintStream(Debug.LEVEL_HIGH)));
} catch(Exception e) {
if(!hasASMMethodNodes)
throw e;
}
return classWriter.toByteArray();
}
示例14: validateClass
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
public void validateClass(ClassReader reader) {
StringWriter writer = new StringWriter();
PrintWriter printWriter = new PrintWriter(writer);
Exception error = null;
try {
CheckClassAdapter.verify(reader, this, false, printWriter);
} catch (Exception e) {
error = e;
}
String contents = writer.toString();
if (error != null || contents.length() > 0) {
reader.accept(new TraceClassVisitor(printWriter), 0);
throw new RuntimeException("Generation error\nDump for " + reader.getClassName() + "\n" + writer.toString(), error);
}
}
示例15: handleCarving
import org.objectweb.asm.util.TraceClassVisitor; //导入依赖的package包/类
private byte[] handleCarving(String className, ClassWriter writer) {
ClassReader cr = new ClassReader(writer.toByteArray());
ClassNode cn2 = new ClassNode();
cr.accept(cn2, ClassReader.EXPAND_FRAMES);
this.testCarvingInstrumenter.transformClassNode(cn2, className);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn2.accept(cw);
if (logger.isDebugEnabled()) {
final StringWriter sw = new StringWriter();
cn2.accept(new TraceClassVisitor(new PrintWriter(sw)));
logger.debug("test carving instrumentation result:\n{}", sw);
}
return cw.toByteArray();
}