From 2d93438f62398928b5dc35ef5dfe6b54d759cbcd Mon Sep 17 00:00:00 2001 From: Vilmos Nagy Date: Sun, 26 Jul 2015 21:49:04 +0200 Subject: [PATCH] Prints invokeDynamic. See #66 --- .../bytecode/InstructionPrinter.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java b/src/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java index f7a3c797..f66a0776 100644 --- a/src/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java +++ b/src/the/bytecode/club/bytecodeviewer/decompilers/bytecode/InstructionPrinter.java @@ -19,6 +19,7 @@ import org.objectweb.asm.tree.FrameNode; import org.objectweb.asm.tree.IincInsnNode; import org.objectweb.asm.tree.InsnNode; import org.objectweb.asm.tree.IntInsnNode; +import org.objectweb.asm.tree.InvokeDynamicInsnNode; import org.objectweb.asm.tree.JumpInsnNode; import org.objectweb.asm.tree.LabelNode; import org.objectweb.asm.tree.LdcInsnNode; @@ -128,6 +129,8 @@ public class InstructionPrinter { line = printTableSwitchInsnNode((TableSwitchInsnNode) ain); } else if (ain instanceof LookupSwitchInsnNode) { line = printLookupSwitchInsnNode((LookupSwitchInsnNode) ain); + } else if (ain instanceof InvokeDynamicInsnNode) { + line = printInvokeDynamicInsNode((InvokeDynamicInsnNode) ain); } else { line += "UNADDED OPCODE: " + nameOpcode(ain.opcode()) + " " + ain.toString(); @@ -281,6 +284,29 @@ public class InstructionPrinter { return line; } + protected String printInvokeDynamicInsNode(InvokeDynamicInsnNode idin) { + StringBuilder sb = new StringBuilder(); + sb.append(nameOpcode(idin.opcode()) + " " + idin.name + "("); + + String desc = idin.desc; + String partedDesc = idin.desc.substring(2); + try { + if(Type.getType(partedDesc) != null) + desc = Type.getType(partedDesc).getClassName(); + + if (desc == null || desc.equals("null")) + desc = idin.desc; + } catch(java.lang.ArrayIndexOutOfBoundsException e) { + + } + + sb.append(desc); + + sb.append(");"); + + return sb.toString(); + } + protected String nameOpcode(int opcode) { return " " + OpcodeInfo.OPCODES.get(opcode).toLowerCase(); }