本文整理汇总了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());
}
}
}
示例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());
}
}
示例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());
}
}
}
示例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';
}
示例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);
}
示例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();
}
示例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);
}
}
示例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);
}
}
}