本文整理汇总了Java中org.objectweb.asm.util.Printer类的典型用法代码示例。如果您正苦于以下问题:Java Printer类的具体用法?Java Printer怎么用?Java Printer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Printer类属于org.objectweb.asm.util包,在下文中一共展示了Printer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: visitTableSwitchInsn
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
@Override
public final void visitTableSwitchInsn(final int min, final int max,
final Label dflt, final Label... labels) {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "min", "min", "", Integer.toString(min));
attrs.addAttribute("", "max", "max", "", Integer.toString(max));
attrs.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
String o = Printer.OPCODES[Opcodes.TABLESWITCH];
sa.addStart(o, attrs);
for (int i = 0; i < labels.length; i++) {
AttributesImpl att2 = new AttributesImpl();
att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
sa.addElement("label", att2);
}
sa.addEnd(o);
}
示例2: compile
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
/**
* Runs the two-pass compiler to generate a Painless script. (Used by the debugger.)
* @param iface Interface the compiled script should implement
* @param source The source code for the script.
* @param settings The CompilerSettings to be used during the compilation.
* @return The bytes for compilation.
*/
static byte[] compile(Class<?> iface, String name, String source, CompilerSettings settings, Printer debugStream) {
if (source.length() > MAXIMUM_SOURCE_LENGTH) {
throw new IllegalArgumentException("Scripts may be no longer than " + MAXIMUM_SOURCE_LENGTH +
" characters. The passed in script is " + source.length() + " characters. Consider using a" +
" plugin if a script longer than this length is a requirement.");
}
ScriptInterface scriptInterface = new ScriptInterface(iface);
SSource root = Walker.buildPainlessTree(scriptInterface, name, source, settings, debugStream);
root.analyze();
root.write();
return root.getBytes();
}
示例3: SSource
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
public SSource(ScriptInterface scriptInterface, CompilerSettings settings, String name, String source, Printer debugStream,
MainMethodReserved reserved, Location location,
List<SFunction> functions, Globals globals, List<AStatement> statements) {
super(location);
this.scriptInterface = Objects.requireNonNull(scriptInterface);
this.settings = Objects.requireNonNull(settings);
this.name = Objects.requireNonNull(name);
this.source = Objects.requireNonNull(source);
this.debugStream = debugStream;
this.reserved = Objects.requireNonNull(reserved);
// process any synthetic functions generated by walker (because right now, thats still easy)
functions.addAll(globals.getSyntheticMethods().values());
globals.getSyntheticMethods().clear();
this.functions = Collections.unmodifiableList(functions);
this.statements = Collections.unmodifiableList(statements);
this.globals = globals;
}
示例4: 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());
}
}
}
示例5: insToChars
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
private static String insToChars(String name) {
for (int i = 0; i < Printer.OPCODES.length; i++) {
if (name.equalsIgnoreCase(Printer.OPCODES[i])) {
return new String(new char[] { opcodeToChar(i) });
}
}
int[] group = groups.get(name.toLowerCase());
if (group != null) {
StringBuilder bldr = new StringBuilder("(");
for (int i = 0; i < group.length; i++) {
bldr.append(opcodeToChar(group[i]));
if (i != group.length - 1)
bldr.append("|");
}
bldr.append(")");
return bldr.toString();
}
if (name.equalsIgnoreCase("AbstractInsnNode")) {
return ".";
}
throw new IllegalArgumentException(name + " is not an instruction.");
}
示例6: printMethod
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
public static void printMethod(ObfMapping method, byte[] bytes, Printer printer, File toFile) {
try {
if (!toFile.getParentFile().exists())
toFile.getParentFile().mkdirs();
if (!toFile.exists())
toFile.createNewFile();
PrintWriter printWriter = new PrintWriter(toFile);
ClassVisitor cv = new MethodASMifier(method, printer, printWriter);
ClassReader cr = new ClassReader(bytes);
cr.accept(cv, 0);
printWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例7: visitLdcInsn
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
@Override
public void visitLdcInsn(final Object cst) {
buf.setLength(0);
buf.append(tab2).append("LDC ");
if (cst instanceof String) {
Printer.appendString(buf, (String) cst);
} else if(cst instanceof Float) {
buf.append(cst).append("F");
} else if(cst instanceof Double) {
buf.append(cst).append("D");
} else if(cst instanceof Long) {
buf.append(cst).append("L");
} else if (cst instanceof Type) {
buf.append(((Type) cst).getDescriptor()).append(".class");
} else {
buf.append(cst);
}
buf.append('\n');
text.add(buf.toString());
}
示例8: 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());
}
}
示例9: 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());
}
}
}
示例10: checkIntComparisonOpcode
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
private static void checkIntComparisonOpcode(Type comparisonType, int opcode) {
switch (opcode) {
case Opcodes.IFEQ:
case Opcodes.IFNE:
return;
case Opcodes.IFGT:
case Opcodes.IFGE:
case Opcodes.IFLT:
case Opcodes.IFLE:
if (comparisonType.getSort() == Type.ARRAY || comparisonType.getSort() == Type.OBJECT) {
throw new IllegalArgumentException(
"Type: " + comparisonType + " cannot be compared via " + Printer.OPCODES[opcode]);
}
return;
default:
throw new IllegalArgumentException(
"Unsupported opcode for comparison operation: " + opcode);
}
}
示例11: 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';
}
示例12: print
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
protected void print(final Object cst) {
if (cst instanceof String) {
StringBuffer buf = new StringBuffer();
Printer.appendString(buf, (String) cst);
pw.print(buf.toString());
} else if (cst instanceof Float) {
Float f = (Float) cst;
if (f.isNaN() || f.isInfinite()) {
pw.print("0.0"); // TODO Jasmin bug workaround
} else {
pw.print(f);
}
} else if (cst instanceof Double) {
Double d = (Double) cst;
if (d.isNaN() || d.isInfinite()) {
pw.print("0.0"); // TODO Jasmin bug workaround
} else {
pw.print(d);
}
} else {
pw.print(cst);
}
}
示例13: insToChars
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
/**
* Converts an instruction to character(s) used to build the regular
* expression.
* @param name The name of the instruction.
* @return The character(s) which represents this instruction.
* @throws IllegalArgumentException if the name was not found.
*/
private static String insToChars(String name) {
for (int i = 0; i < Printer.OPCODES.length; i++) {
if (name.equalsIgnoreCase(Printer.OPCODES[i])) {
return new String(new char[] { opcodeToChar(i) });
}
}
int[] group = groups.get(name.toLowerCase());
if (group != null) {
StringBuilder bldr = new StringBuilder("(");
for (int i = 0; i < group.length; i++) {
bldr.append(opcodeToChar(group[i]));
if (i != group.length - 1)
bldr.append("|");
}
bldr.append(")");
return bldr.toString();
}
if (name.equalsIgnoreCase("AbstractInsnNode")) {
return ".";
}
throw new IllegalArgumentException(name + " is not an instruction.");
}
示例14: visitTableSwitchInsn
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
@Override
public final void visitTableSwitchInsn(
final int min,
final int max,
final Label dflt,
final Label... labels)
{
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute("", "min", "min", "", Integer.toString(min));
attrs.addAttribute("", "max", "max", "", Integer.toString(max));
attrs.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
String o = Printer.OPCODES[Opcodes.TABLESWITCH];
sa.addStart(o, attrs);
for (int i = 0; i < labels.length; i++) {
AttributesImpl att2 = new AttributesImpl();
att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
sa.addElement("label", att2);
}
sa.addEnd(o);
}
示例15: visitLookupSwitchInsn
import org.objectweb.asm.util.Printer; //导入依赖的package包/类
@Override
public final void visitLookupSwitchInsn(
final Label dflt,
final int[] keys,
final Label[] labels)
{
AttributesImpl att = new AttributesImpl();
att.addAttribute("", "dflt", "dflt", "", getLabel(dflt));
String o = Printer.OPCODES[Opcodes.LOOKUPSWITCH];
sa.addStart(o, att);
for (int i = 0; i < labels.length; i++) {
AttributesImpl att2 = new AttributesImpl();
att2.addAttribute("", "name", "name", "", getLabel(labels[i]));
att2.addAttribute("", "key", "key", "", Integer.toString(keys[i]));
sa.addElement("label", att2);
}
sa.addEnd(o);
}