Skip to content

Commit

Permalink
Make bytecode decompilers more extensible
Browse files Browse the repository at this point in the history
  • Loading branch information
rcx committed Jul 17, 2019
1 parent 9e7f396 commit edac706
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* @author Bibl
*/
public class InstructionPrinter {
private final MethodNodeDecompiler parent;
protected final MethodNodeDecompiler parent;

/**
* The MethodNode to print
**/
protected MethodNode mNode;
private TypeAndName[] args;
protected final MethodNode mNode;
protected final TypeAndName[] args;

protected int[] pattern;
protected boolean match;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

public class MethodNodeDecompiler {
private final BytecodeDecompiler parent;
protected final BytecodeDecompiler parent;
protected final PrefixedStringBuilder sb;
protected final MethodNode mn;
protected final ClassNode cn;
protected boolean printDetailedMetadata = true;

public MethodNodeDecompiler(BytecodeDecompiler parent, PrefixedStringBuilder sb, MethodNode mn, ClassNode cn) {
this.parent = parent;
Expand Down Expand Up @@ -134,31 +135,33 @@ else if (mn.name.equals("<init>"))

InstructionPrinter insnPrinter = getInstructionPrinter(mn, args);

addAttrList(mn.attrs, "attr", sb, insnPrinter);
addAttrList(mn.invisibleAnnotations, "invisAnno", sb, insnPrinter);
addAttrList(mn.invisibleAnnotations, "invisLocalVarAnno", sb, insnPrinter);
addAttrList(mn.invisibleTypeAnnotations, "invisTypeAnno", sb, insnPrinter);
addAttrList(mn.localVariables, "localVar", sb, insnPrinter);
addAttrList(mn.visibleAnnotations, "visAnno", sb, insnPrinter);
addAttrList(mn.visibleLocalVariableAnnotations, "visLocalVarAnno", sb, insnPrinter);
addAttrList(mn.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);

// Exception table
for (Object o : mn.tryCatchBlocks) {
TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
sb.append(" ");
sb.append("TryCatch: L");
sb.append(insnPrinter.resolveLabel(tcbn.start));
sb.append(" to L");
sb.append(insnPrinter.resolveLabel(tcbn.end));
sb.append(" handled by L");
sb.append(insnPrinter.resolveLabel(tcbn.handler));
sb.append(": ");
if (tcbn.type != null)
sb.append(tcbn.type);
else
sb.append("Type is null.");
sb.append(JDA.nl);
if (printDetailedMetadata) {
addAttrList(mn.attrs, "attr", sb, insnPrinter);
addAttrList(mn.invisibleAnnotations, "invisAnno", sb, insnPrinter);
addAttrList(mn.invisibleAnnotations, "invisLocalVarAnno", sb, insnPrinter);
addAttrList(mn.invisibleTypeAnnotations, "invisTypeAnno", sb, insnPrinter);
addAttrList(mn.localVariables, "localVar", sb, insnPrinter);
addAttrList(mn.visibleAnnotations, "visAnno", sb, insnPrinter);
addAttrList(mn.visibleLocalVariableAnnotations, "visLocalVarAnno", sb, insnPrinter);
addAttrList(mn.visibleTypeAnnotations, "visTypeAnno", sb, insnPrinter);

// Exception table
for (Object o : mn.tryCatchBlocks) {
TryCatchBlockNode tcbn = (TryCatchBlockNode) o;
sb.append(" ");
sb.append("TryCatch: L");
sb.append(insnPrinter.resolveLabel(tcbn.start));
sb.append(" to L");
sb.append(insnPrinter.resolveLabel(tcbn.end));
sb.append(" handled by L");
sb.append(insnPrinter.resolveLabel(tcbn.handler));
sb.append(": ");
if (tcbn.type != null)
sb.append(tcbn.type);
else
sb.append("Type is null.");
sb.append(JDA.nl);
}
}

// Instructions
Expand Down Expand Up @@ -269,4 +272,8 @@ boolean createDescriptors() {
boolean appendHandlerComments() {
return parent.getSettings().getEntry("append-handler-comments").getBool();
}

public BytecodeDecompiler getParent() {
return parent;
}
}

0 comments on commit edac706

Please sign in to comment.