use of org.objectweb.asm.tree.TryCatchBlockNode in project dex2jar by pxb1988.
the class AsmVerify method printAnalyzerResult.
static void printAnalyzerResult(MethodNode method, Analyzer a, final PrintWriter pw) throws IllegalArgumentException {
Frame[] frames = a.getFrames();
Textifier t = new Textifier();
TraceMethodVisitor mv = new TraceMethodVisitor(t);
String format = "%05d %-" + (method.maxStack + method.maxLocals + 6) + "s|%s";
for (int j = 0; j < method.instructions.size(); ++j) {
method.instructions.get(j).accept(mv);
StringBuffer s = new StringBuffer();
Frame f = frames[j];
if (f == null) {
s.append('?');
} else {
for (int k = 0; k < f.getLocals(); ++k) {
s.append(getShortName(f.getLocal(k).toString()));
}
s.append(" : ");
for (int k = 0; k < f.getStackSize(); ++k) {
s.append(getShortName(f.getStack(k).toString()));
}
}
try {
// mv.text.get(j));
pw.printf(format, j, s, buf.get(t));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
for (TryCatchBlockNode tryCatchBlockNode : method.tryCatchBlocks) {
tryCatchBlockNode.accept(mv);
try {
pw.print(" " + buf.get(t));
} catch (IllegalAccessException e) {
e.printStackTrace();
}
}
pw.println();
pw.flush();
}
use of org.objectweb.asm.tree.TryCatchBlockNode in project bytecode-viewer by Konloch.
the class MethodNodeDecompiler method decompile.
public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb, MethodNode m, ClassNode cn) {
String class_;
if (cn.name.contains("/")) {
class_ = cn.name.substring(cn.name.lastIndexOf("/") + 1);
} else {
class_ = cn.name;
}
String s = getAccessString(m.access);
sb.append(" ");
sb.append(s);
if (s.length() > 0)
sb.append(" ");
if (m.name.equals("<init>")) {
sb.append(class_);
} else if (!m.name.equals("<clinit>")) {
sb.append(m.name);
}
TypeAndName[] args = new TypeAndName[0];
if (!m.name.equals("<clinit>")) {
sb.append("(");
final Type[] argTypes = Type.getArgumentTypes(m.desc);
args = new TypeAndName[argTypes.length];
for (int i = 0; i < argTypes.length; i++) {
final Type type = argTypes[i];
final TypeAndName tan = new TypeAndName();
final String argName = "arg" + i;
tan.name = argName;
tan.type = type;
args[i] = tan;
sb.append(type.getClassName() + " " + argName + (i < argTypes.length - 1 ? ", " : ""));
}
sb.append(")");
}
int amountOfThrows = m.exceptions.size();
if (amountOfThrows > 0) {
sb.append(" throws ");
// exceptions is list<string>
sb.append(m.exceptions.get(0));
for (int i = 1; i < amountOfThrows; i++) {
sb.append(", ");
sb.append(m.exceptions.get(i));
}
}
if (s.contains("abstract")) {
sb.append(" {}");
sb.append(" //");
sb.append(m.desc);
sb.append(nl);
} else {
sb.append(" {");
if (BytecodeViewer.viewer.debugHelpers.isSelected()) {
if (m.name.equals("<clinit>"))
sb.append(" // <clinit>");
else if (m.name.equals("<init>"))
sb.append(" // <init>");
}
sb.append(" //");
sb.append(m.desc);
sb.append(nl);
if (m.signature != null) {
sb.append(" <sig:").append(m.signature).append(">");
}
if (m.annotationDefault != null) {
sb.append(m.annotationDefault);
sb.append("\n");
}
InstructionPrinter insnPrinter = new InstructionPrinter(m, args);
addAttrList(m.attrs, "attr", sb, insnPrinter);
addAttrList(m.invisibleAnnotations, "invisAnno", sb, insnPrinter);
addAttrList(m.invisibleAnnotations, "invisLocalVarAnno", sb, insnPrinter);
addAttrList(m.invisibleTypeAnnotations, "invisTypeAnno", sb, insnPrinter);
addAttrList(m.localVariables, "localVar", sb, insnPrinter);
addAttrList(m.visibleAnnotations, "visAnno", sb, insnPrinter);
addAttrList(m.visibleLocalVariableAnnotations, "visLocalVarAnno", sb, insnPrinter);
addAttrList(m.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);
for (TryCatchBlockNode o : m.tryCatchBlocks) {
sb.append(" ");
sb.append("TryCatch: L");
sb.append(insnPrinter.resolveLabel(o.start));
sb.append(" to L");
sb.append(insnPrinter.resolveLabel(o.end));
sb.append(" handled by L");
sb.append(insnPrinter.resolveLabel(o.handler));
sb.append(": ");
if (o.type != null)
sb.append(o.type);
else
sb.append("Type is null.");
sb.append(nl);
}
for (String insn : insnPrinter.createPrint()) {
sb.append(" ");
sb.append(insn);
sb.append(nl);
}
sb.append(" }" + nl);
}
return sb;
}
Aggregations