Skip to content

Commit

Permalink
Better support of invokedynamic instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
rcx committed May 30, 2018
1 parent fc9603d commit ed7126d
Showing 1 changed file with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package club.bytecode.the.jda.decompilers.bytecode;

import club.bytecode.the.jda.api.ExceptionUI;
import org.apache.commons.lang3.StringEscapeUtils;
import org.objectweb.asm.Type;
import org.objectweb.asm.tree.*;
import club.bytecode.the.jda.api.ExceptionUI;

import java.io.BufferedWriter;
import java.io.File;
Expand Down Expand Up @@ -283,7 +283,9 @@ protected String printLookupSwitchInsnNode(LookupSwitchInsnNode lin) {

protected String printInvokeDynamicInsNode(InvokeDynamicInsnNode idin) {
StringBuilder sb = new StringBuilder();
sb.append(nameOpcode(idin.opcode())).append(" ").append(idin.bsm.getName()).append("(");
final String bsmName = idin.bsm.getName();
final boolean isMetafactory = bsmName.equals("metafactory");
sb.append(nameOpcode(idin.opcode())).append(" ").append(bsmName).append("<");

String desc = idin.desc;
String partedDesc = idin.desc.substring(2);
Expand All @@ -298,8 +300,32 @@ protected String printInvokeDynamicInsNode(InvokeDynamicInsnNode idin) {
}

sb.append(desc);
sb.append(">(\n");
Object[] bsmArgs = idin.bsmArgs;
for (int i = 0; i < bsmArgs.length; i++) {
Object arg = bsmArgs[i];
sb.append(" ");
sb.append(arg);
if (i < bsmArgs.length - 1) {
sb.append(", ");
}
if (isMetafactory) {
switch(i) {
case 0:
sb.append(" // caller");
break;
case 1:
sb.append(" // invokedName");
break;
case 2:
sb.append(" // invokedType");
break;
}
}
sb.append("\n");
}

sb.append(");");
sb.append(" );");

return sb.toString();
}
Expand Down Expand Up @@ -334,4 +360,4 @@ public static void saveTo(File file, InstructionPrinter printer) {
new ExceptionUI(e);
}
}
}
}

0 comments on commit ed7126d

Please sign in to comment.