当前位置: 首页>>代码示例>>Java>>正文


Java Printer.print方法代码示例

本文整理汇总了Java中org.objectweb.asm.util.Printer.print方法的典型用法代码示例。如果您正苦于以下问题:Java Printer.print方法的具体用法?Java Printer.print怎么用?Java Printer.print使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.util.Printer的用法示例。


在下文中一共展示了Printer.print方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: viewByteCode

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
/**
 * 格式化输出字节码
 * @param bytecode
 */
public static void viewByteCode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);
    final List<MethodNode> mns = cn.methods;
    Printer printer = new Textifier();
    TraceMethodVisitor mp = new TraceMethodVisitor(printer);
    for (MethodNode mn : mns) {
        InsnList inList = mn.instructions;
        System.out.println(mn.name);
        for (int i = 0; i < inList.size(); i++) {
            inList.get(i).accept(mp);
            StringWriter sw = new StringWriter();
            printer.print(new PrintWriter(sw));
            printer.getText().clear();
            System.out.print(sw.toString());
        }
    }
}
 
开发者ID:yutian-tianpl,项目名称:byte-cobweb,代码行数:24,代码来源:Helper.java

示例2: visitEnd

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
@Override
public void visitEnd() {
	super.visitEnd();

	if (!found && errorNoMatch) {
		StringWriter output = new StringWriter();
		PrintWriter writer = new PrintWriter(output);
		writer.append("Cannot find nodes");
		if (methods.size() > 0) {
			writer.append(" for methods ").append(methods.toString());
		}
		writer.println();

		Printer printer = new Textifier();
		TraceMethodVisitor visitor = new TraceMethodVisitor(printer);
		for (AbstractInsnNode node : nodes) {
			node.accept(visitor);
		}

		printer.print(writer);

		throw new IllegalStateException(output.toString());
	}
}
 
开发者ID:SquidDev,项目名称:Patcher,代码行数:25,代码来源:FindingVisitor.java

示例3: viewByteCode

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
public static void viewByteCode(byte[] bytecode) {
    ClassReader cr = new ClassReader(bytecode);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);
    final List<MethodNode> mns = cn.methods;
    Printer printer = new Textifier();
    TraceMethodVisitor mp = new TraceMethodVisitor(printer);
    for (MethodNode mn : mns) {
        InsnList inList = mn.instructions;
        System.out.println(mn.name);
        for (int i = 0; i < inList.size(); i++) {
            inList.get(i).accept(mp);
            StringWriter sw = new StringWriter();
            printer.print(new PrintWriter(sw));
            printer.getText().clear();
            System.out.print(sw.toString());
        }
    }
}
 
开发者ID:brutusin,项目名称:instrumentation,代码行数:20,代码来源:Helper.java

示例4: getMethodInstructionList

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
public static String getMethodInstructionList(final MethodNode methodNode) {
    Preconditions.checkNotNull(methodNode, "methodNode");
    final Printer printer = new NonMaxTextifier();
    final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
    methodNode.accept(traceMethodVisitor);
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    printer.print(printWriter);
    printWriter.flush();
    final String[] lines = PATTERN.split(stringWriter.toString());
    int lineNr = 0;
    for (int i = 0; i < lines.length; i++) {
        if (!lines[i].startsWith("  @")) {
            lines[i] = String.format("%2d %s", lineNr++, lines[i]);
        }
    }
    return "Method '" + methodNode.name + "':\n"
        + NEWLINE.join(lines) + '\n';
}
 
开发者ID:fge,项目名称:grappa,代码行数:20,代码来源:AsmTestUtils.java

示例5: assertTraceDumpEquality

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
public static void assertTraceDumpEquality(
    final MethodNode method, final String traceDump) throws Exception {
    Preconditions.checkNotNull(method, "method");
    final Printer printer = new NonMaxTextifier();
    final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
    // MethodAdapter checkMethodAdapter = new MethodAdapter(traceMethodVisitor);
    final MethodVisitor checkMethodAdapter = new CheckMethodAdapter(traceMethodVisitor);
    method.accept(checkMethodAdapter);
    final StringWriter stringWriter = new StringWriter();
    final PrintWriter printWriter = new PrintWriter(stringWriter);
    printer.print(printWriter);
    printWriter.flush();

    assertEquals(stringWriter.toString(), traceDump);
}
 
开发者ID:fge,项目名称:grappa,代码行数:16,代码来源:AsmTestUtils.java

示例6: toByteCode

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
private static String toByteCode(ClassVisitor cv, Printer p, byte[] bytes) {
    new ClassReader(bytes).accept(cv, ClassReader.EXPAND_FRAMES);

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    p.print(pw);
    pw.flush();
    return sw.toString();
}
 
开发者ID:anba,项目名称:es6draft,代码行数:10,代码来源:Code.java

示例7: emitOuterType

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends TypeEntry> void emitOuterType(T ast) {
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
    this.cw = writer;
    if (VERIFY_EMITTED_BYTECODE) {
        this.cw = new CheckClassAdapter(this.cw);
    }
    AstEmitter<AbstractEmitterContext, T> emitter = (AstEmitter<AbstractEmitterContext, T>) this.set.getAstEmitter(ast.getClass());
    if (emitter == null) {
        throw new IllegalArgumentException("No emitter for ast entry " + ast.getClass().getName());
    }
    emitter.emit(this, ast);
    this.cw.visitEnd();
    byte[] clazz = writer.toByteArray();
    if (DUMP_INSTRUCTIONS_AFTER_WRITE) {
        ClassReader cr = new ClassReader(clazz);
        ClassNode cn = new ClassNode();
        cr.accept(cn, 0);
        List<MethodNode> methods = cn.methods;
        for (MethodNode mn : methods) {
            System.out.println("Method: " + mn.name + mn.desc);
            Printer printer = new Textifier();
            TraceMethodVisitor mp = new TraceMethodVisitor(printer);
            for (Iterator<AbstractInsnNode> it = mn.instructions.iterator(); it.hasNext();) {
                AbstractInsnNode insn = it.next();
                insn.accept(mp);
            }
            StringWriter sw = new StringWriter();
            printer.print(new PrintWriter(sw));
            String s = sw.toString();
            if (s.endsWith("\n")) {
                s = s.substring(0, s.length() - 1);
            }
            System.out.println(s);
            mn.instructions.accept(mp);
        }
    }
    try {
        this.out.write(clazz);
    } catch (IOException e) {
        Throwables.propagate(e);
    }
}
 
开发者ID:Despector,项目名称:Despector,代码行数:44,代码来源:BytecodeEmitterContext.java

示例8: verifyClassIntegrity

import org.objectweb.asm.util.Printer; //导入方法依赖的package包/类
private void verifyClassIntegrity(ClassNode classNode) {
    // Do not COMPUTE_FRAMES. If you COMPUTE_FRAMES and you pop too many items off the stack or do other weird things that mess up the
    // stack map frames, it'll crash on classNode.accept(cw).
    ClassWriter cw = new SimpleClassWriter(ClassWriter.COMPUTE_MAXS/* | ClassWriter.COMPUTE_FRAMES*/, classRepo);
    classNode.accept(cw);
    
    byte[] classData = cw.toByteArray();

    ClassReader cr = new ClassReader(classData);
    classNode = new SimpleClassNode();
    cr.accept(classNode, 0);

    for (MethodNode methodNode : classNode.methods) {
        Analyzer<BasicValue> analyzer = new Analyzer<>(new SimpleVerifier(classRepo));
        try {
            analyzer.analyze(classNode.name, methodNode);
        } catch (AnalyzerException e) {
            // IF WE DID OUR INSTRUMENTATION RIGHT, WE SHOULD NEVER GET AN EXCEPTION HERE!!!!
            StringWriter writer = new StringWriter();
            PrintWriter printWriter = new PrintWriter(writer);
            
            printWriter.append(methodNode.name + " encountered " + e);
            
            Printer printer = new Textifier();
            TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer);
            
            AbstractInsnNode insn = methodNode.instructions.getFirst();
            while (insn != null) {
                if (insn == e.node) {
                    printer.getText().add("----------------- BAD INSTRUCTION HERE -----------------\n");
                }
                insn.accept(traceMethodVisitor);
                insn = insn.getNext();
            }
            printer.print(printWriter);
            printWriter.flush(); // we need this or we'll get incomplete results
            
            throw new IllegalStateException(writer.toString(), e);
        }
    }
}
 
开发者ID:offbynull,项目名称:coroutines,代码行数:42,代码来源:Instrumenter.java


注:本文中的org.objectweb.asm.util.Printer.print方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。