Add support for framenodes

This commit is contained in:
ItzSomebody 2018-01-30 12:40:22 -08:00
parent 34991f9b7e
commit f936af84da

AI 샘플 코드 생성 중입니다

Loading...
3 changed files with 52 additions and 16 deletions

View File

@ -39,13 +39,13 @@ public class ClassNodeDecompiler extends Decompiler {
public String decompileClassNode(ClassNode cn, byte[] b) {
return decompile(new PrefixedStringBuilder(),
new ArrayList<String>(), cn).toString();
new ArrayList<>(), cn).toString();
}
protected static PrefixedStringBuilder decompile(
PrefixedStringBuilder sb, ArrayList<String> decompiledClasses,
ClassNode cn) {
ArrayList<String> unableToDecompile = new ArrayList<String>();
ArrayList<String> unableToDecompile = new ArrayList<>();
decompiledClasses.add(cn.name);
sb.append(getAccessString(cn.access));
sb.append(" ");
@ -59,9 +59,6 @@ public class ClassNodeDecompiler extends Decompiler {
if (amountOfInterfaces > 0) {
sb.append(" implements ");
sb.append(cn.interfaces.get(0));
if (amountOfInterfaces > 1) {
// sb.append(",");
}
for (int i = 1; i < amountOfInterfaces; i++) {
sb.append(", ");
sb.append(cn.interfaces.get(i));
@ -69,7 +66,7 @@ public class ClassNodeDecompiler extends Decompiler {
}
sb.append(" {");
sb.append(BytecodeViewer.nl);
for (FieldNode fn : (List<FieldNode>) cn.fields) {
for (FieldNode fn : cn.fields) {
sb.append(BytecodeViewer.nl);
sb.append(" ");
FieldNodeDecompiler.decompile(sb, fn);
@ -77,7 +74,7 @@ public class ClassNodeDecompiler extends Decompiler {
if (cn.fields.size() > 0) {
sb.append(BytecodeViewer.nl);
}
for (MethodNode mn : (List<MethodNode>) cn.methods) {
for (MethodNode mn : cn.methods) {
sb.append(BytecodeViewer.nl);
MethodNodeDecompiler.decompile(sb, mn, cn);
}

View File

@ -31,6 +31,7 @@ import org.objectweb.asm.tree.TableSwitchInsnNode;
import org.objectweb.asm.tree.TypeInsnNode;
import org.objectweb.asm.tree.VarInsnNode;
import org.objectweb.asm.tree.analysis.Frame;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import eu.bibl.banalysis.asm.desc.OpcodeInfo;
@ -61,12 +62,12 @@ public class InstructionPrinter {
/**
* The MethodNode to print
**/
protected MethodNode mNode;
private MethodNode mNode;
private TypeAndName[] args;
protected int[] pattern;
protected boolean match;
protected InstructionSearcher searcher;
private InstructionSearcher searcher;
protected List<AbstractInsnNode> matchedInsns;
protected Map<LabelNode, Integer> labels;
@ -140,7 +141,7 @@ public class InstructionPrinter {
} else if (ain instanceof TypeInsnNode) {
line = printTypeInsnNode((TypeInsnNode) ain);
} else if (ain instanceof FrameNode) {
line = "";
line = printFrameNode((FrameNode) ain);
} else if (ain instanceof IincInsnNode) {
line = printIincInsnNode((IincInsnNode) ain);
} else if (ain instanceof TableSwitchInsnNode) {
@ -200,8 +201,8 @@ public class InstructionPrinter {
protected String printMethodInsnNode(MethodInsnNode min, ListIterator<?> it) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(min.opcode()) + " " + min.owner + " "
+ min.name + "(");
sb.append(nameOpcode(min.opcode()) + " " + min.owner + "."
+ min.name);
String desc = min.desc;
try {
@ -216,8 +217,6 @@ public class InstructionPrinter {
sb.append(desc);
sb.append(");");
return sb.toString();
}
@ -325,6 +324,47 @@ public class InstructionPrinter {
return sb.toString();
}
private String printFrameNode(FrameNode frame) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(frame.opcode()) + " ");
sb.append("(Locals: ");
if (frame.local != null
&& frame.local.size() > 0) {
sb.append(frame.local.size());
sb.append(" ");
sb.append(frame.local.get(0).toString());
if (frame.local.size() > 1) {
for (int i = 1; i < frame.local.size(); i++) {
sb.append(", ");
sb.append(frame.local.get(i).toString());
}
}
} else {
sb.append("0, null");
}
sb.append(") ");
sb.append("(Stack: ");
if (frame.stack != null
&& frame.stack.size() > 0) {
sb.append(frame.stack.size());
sb.append(" ");
sb.append(frame.stack.get(0).toString());
if (frame.stack.size() > 1) {
for (int i = 1; i < frame.stack.size(); i++) {
sb.append(", ");
sb.append(frame.stack.get(i).toString());
}
}
} else {
sb.append("0, null");
}
sb.append(")");
return sb.toString();
}
protected String nameOpcode(int opcode) {
return " " + OpcodeInfo.OPCODES.get(opcode).toLowerCase();
}

View File

@ -40,11 +40,10 @@ import the.bytecode.club.bytecodeviewer.decompilers.bytecode.TypeAndName;
public class MethodNodeDecompiler {
@SuppressWarnings("unused")
public static PrefixedStringBuilder decompile(PrefixedStringBuilder sb,
MethodNode m, ClassNode cn) {
String package_ = null;
String class_ = null;
String class_;
if (cn.name.contains("/")) {
package_ = cn.name.substring(0, cn.name.lastIndexOf("/"));
class_ = cn.name.substring(cn.name.lastIndexOf("/") + 1);