當前位置: 首頁>>代碼示例>>Java>>正文


Java TraceClassVisitor類代碼示例

本文整理匯總了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);
  }
}
 
開發者ID:skhalifa,項目名稱:QDrill,代碼行數:25,代碼來源:ReplaceMethodInvoke.java

示例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();
}
 
開發者ID:jooby-project,項目名稱:jooby,代碼行數:26,代碼來源:BytecodeRouteParser.java

示例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;
}
 
開發者ID:kroepke,項目名稱:luna,代碼行數:17,代碼來源:ASMBytecodeEmitter.java

示例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);
    }
}
 
開發者ID:4Space,項目名稱:4Space-5,代碼行數:18,代碼來源:ASMHelper.java

示例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;
}
 
開發者ID:mjanicek,項目名稱:rembulan,代碼行數:17,代碼來源:ASMBytecodeEmitter.java

示例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();
	
}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:18,代碼來源:InterfaceTest.java

示例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();

}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:19,代碼來源:ExceptionTest.java

示例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();

}
 
開發者ID:flankerhqd,項目名稱:JAADAS,代碼行數:19,代碼來源:AnnotatedAnnotationTest.java

示例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();
    }
}
 
開發者ID:purpleposeidon,項目名稱:Factorization,代碼行數:17,代碼來源:ASMTransformer.java

示例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);
  }
}
 
開發者ID:axbaretto,項目名稱:drill,代碼行數:25,代碼來源:ReplaceMethodInvoke.java

示例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;
}
 
開發者ID:JozefCeluch,項目名稱:thesis-disassembler,代碼行數:17,代碼來源:Disassembler.java

示例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());
    }

}
 
開發者ID:typetools,項目名稱:annotation-tools,代碼行數:22,代碼來源:StackMapTableAttributeTest.java

示例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();
}
 
開發者ID:jakobehmsen,項目名稱:astava,代碼行數:27,代碼來源:ClassGenerator.java

示例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);
	}
}
 
開發者ID:SquidDev,項目名稱:Patcher,代碼行數:18,代碼來源:RewriteClassLoader.java

示例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();
}
 
開發者ID:EvoSuite,項目名稱:evosuite,代碼行數:18,代碼來源:BytecodeInstrumentation.java


注:本文中的org.objectweb.asm.util.TraceClassVisitor類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。