Skip to content

Instantly share code, notes, and snippets.

@Maldivia
Created January 15, 2021 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Maldivia/358104d2dbfaa185c4c15978d045daa9 to your computer and use it in GitHub Desktop.
Save Maldivia/358104d2dbfaa185c4c15978d045daa9 to your computer and use it in GitHub Desktop.
Verify Error Parser
package com.test.verifyerror;
public enum Opcodes {
NOP(0, 0),
ACONST_NULL(1, 0),
ICONST_M1(2, 0),
ICONST_0(3, 0),
ICONST_1(-1, 0),
ICONST_2(-1, 0),
ICONST_3(-1, 0),
ICONST_4(-1, 0),
ICONST_5(-1, 0),
LCONST_0(-1, 0),
LCONST_1(-1, 0),
FCONST_0(-1, 0),
FCONST_1(-1, 0),
FCONST_2(-1, 0),
DCONST_0(-1, 0),
DCONST_1(-1, 0),
BIPUSH(-1, 1),
SIPUSH(-1, 2),
LDC(-1, 1),
LDC_W(-1, 2),
LDC2_W(-1, 2),
ILOAD(-1, 1),
LLOAD(-1, 1),
FLOAD(-1, 1),
DLOAD(-1, 1),
ALOAD(-1, 1),
ILOAD_0(-1, 0),
ILOAD_1(-1, 0),
ILOAD_2(-1, 0),
ILOAD_3(-1, 0),
LLOAD_0(-1, 0),
LLOAD_1(-1, 0),
LLOAD_2(-1, 0),
LLOAD_3(-1, 0),
FLOAD_0(-1, 0),
FLOAD_1(-1, 0),
FLOAD_2(-1, 0),
FLOAD_3(-1, 0),
DLOAD_0(-1, 0),
DLOAD_1(-1, 0),
DLOAD_2(-1, 0),
DLOAD_3(-1, 0),
ALOAD_0(-1, 0),
ALOAD_1(-1, 0),
ALOAD_2(-1, 0),
ALOAD_3(-1, 0),
IALOAD(-1, 0),
LALOAD(-1, 0),
FALOAD(-1, 0),
DALOAD(-1, 0),
AALOAD(-1, 0),
BALOAD(-1, 0),
CALOAD(-1, 0),
SALOAD(-1, 0),
ISTORE(-1, 1),
LSTORE(-1, 1),
FSTORE(-1, 1),
DSTORE(-1, 1),
ASTORE(-1, 1),
ISTORE_0(-1, 0),
ISTORE_1(-1, 0),
ISTORE_2(-1, 0),
ISTORE_3(-1, 0),
LSTORE_0(-1, 0),
LSTORE_1(-1, 0),
LSTORE_2(-1, 0),
LSTORE_3(-1, 0),
FSTORE_0(-1, 0),
FSTORE_1(-1, 0),
FSTORE_2(-1, 0),
FSTORE_3(-1, 0),
DSTORE_0(-1, 0),
DSTORE_1(-1, 0),
DSTORE_2(-1, 0),
DSTORE_3(-1, 0),
ASTORE_0(-1, 0),
ASTORE_1(-1, 0),
ASTORE_2(-1, 0),
ASTORE_3(-1, 0),
IASTORE(-1, 0),
LASTORE(-1, 0),
FASTORE(-1, 0),
DASTORE(-1, 0),
AASTORE(-1, 0),
BASTORE(-1, 0),
CASTORE(-1, 0),
SASTORE(-1, 0),
POP(-1, 0),
POP2(-1, 0),
DUP(-1, 0),
DUP_X1(-1, 0),
DUP_X2(-1, 0),
DUP2(-1, 0),
DUP2_X1(-1, 0),
DUP2_X2(0X5E, 0),
SWAP(-1, 0),
IADD(-1, 0),
LADD(-1, 0),
FADD(-1, 0),
DADD(-1, 0),
ISUB(-1, 0),
LSUB(-1, 0),
FSUB(-1, 0),
DSUB(-1, 0),
IMUL(-1, 0),
LMUL(-1, 0),
FMUL(-1, 0),
DMUL(-1, 0),
IDIV(-1, 0),
LDIV(-1, 0),
FDIV(-1, 0),
DDIV(-1, 0),
IREM(-1, 0),
LREM(-1, 0),
FREM(-1, 0),
DREM(-1, 0),
INEG(-1, 0),
LNEG(-1, 0),
FNEG(-1, 0),
DNEG(-1, 0),
ISHL(-1, 0),
LSHL(-1, 0),
ISHR(-1, 0),
LSHR(-1, 0),
IUSHR(-1, 0),
LUSHR(-1, 0),
IAND(-1, 0),
LAND(-1, 0),
IOR(-1, 0),
LOR(-1, 0),
IXOR(-1, 0),
LXOR(-1, 0),
IINC(-1, 2),
I2L(-1, 0),
I2F(-1, 0),
I2D(-1, 0),
L2I(-1, 0),
L2F(-1, 0),
L2D(-1, 0),
F2I(-1, 0),
F2L(-1, 0),
F2D(-1, 0),
D2I(-1, 0),
D2L(-1, 0),
D2F(-1, 0),
I2B(-1, 0),
I2C(-1, 0),
I2S(-1, 0),
LCMP(-1, 0),
FCMPL(-1, 0),
FCMPG(-1, 0),
DCMPL(-1, 0),
DCMPG(-1, 0),
IFEQ(-1, 2),
IFNE(-1, 2),
IFLT(-1, 2),
IFGE(-1, 2),
IFGT(-1, 2),
IFLE(-1, 2),
IF_ICMPEQ(-1, 2),
IF_ICMPNE(-1, 2),
IF_ICMPLT(-1, 2),
IF_ICMPGE(-1, 2),
IF_ICMPGT(-1, 2),
IF_ICMPLE(-1, 2),
IF_ACMPEQ(-1, 2),
IF_ACMPNE(-1, 2),
GOTO(-1, 2),
JSR(-1, 2),
RET(-1, 1),
TABLESWITCH(-1, -1),
LOOKUPSWITCH(-1, -1),
IRETURN(0XAC, 0),
LRETURN(-1, 0),
FRETURN(-1, 0),
DRETURN(-1, 0),
ARETURN(-1, 0),
RETURN(-1, 0),
GETSTATIC(-1, 2),
PUTSTATIC(-1, 2),
GETFIELD(-1, 2),
PUTFIELD(-1, 2),
INVOKEVIRTUAL(-1, 2),
INVOKESPECIAL(-1, 2),
INVOKESTATIC(-1, 2),
INVOKEINTERFACE(-1, 4),
INVOKEDYNAMIC(-1, 4),
NEW(-1, 2),
NEWARRAY(-1, 1),
ANEWARRAY(-1, 2),
ARRAYLENGTH(-1, 0),
ATHROW(-1, 0),
CHECKCAST(-1, 2),
INSTANCEOF(-1, 2),
MONITORENTER(-1, 0),
MONITOREXIT(-1, 0),
WIDE(-1, -2),
MULTIANEWARRAY(-1, 3),
IFNULL(-1, 2),
IFNONNULL(-1, 2),
GOTO_W(-1, 4),
JSR_W(-1, 4),
BREAKPOINT(0XCA, 0);
private final int argCount;
private Opcodes(int opcode, int args) {
if (opcode != -1 && ordinal() != opcode)
System.out.println("Error " + name());
argCount = args;
}
public int getArgCount() {
return argCount;
}
public static Opcodes valueOf(int opcode) {
return values()[opcode];
}
}
package com.test.verifyerror;
import java.nio.IntBuffer;
import java.util.Arrays;
public class VerifyErrorParser {
public static void main(String[] args) {
String [] lines = (" Bytecode:\n" +
" 0000000: 2ab6 10bc 9901 68b8 0f51 b902 fc01 0099\n" +
" 0000010: 001c b80f 51bb 016f 5913 0737 b701 732b\n" +
" 0000020: b604 34b6 0182 b901 8502 002a b610 bd4d\n" +
" 0000030: 2a04 bd03 f659 03b2 043c 53b6 1170 bb13\n" +
" 0000040: 0d59 b713 0e4e bb07 3c59 b707 3e3a 04bb\n" +
" 0000050: 11af 59b7 11b0 3a05 2bb6 1313 c700 2a19\n" +
" 0000060: 04b2 1318 03bd 0323 b813 23b9 03b0 0200\n" +
" 0000070: 5719 05b6 11c1 1904 b904 8502 0057 2d19\n" +
" 0000080: 05b6 1324 2db0 bb13 2659 b713 273a 06bb\n" +
" 0000090: 0753 59b7 0755 3a07 1907 b607 562b b613\n" +
" 00000a0: 13b8 132c b903 b002 0057 2ab6 1113 2cb6\n" +
" 00000b0: 0273 b803 492b b613 2db9 11c7 0300 3a08\n" +
" 00000c0: 1908 c700 34bb 016f 5913 0761 b701 732b\n" +
" 00000d0: b613 2db6 017c 1307 63b6 017c b601 823a\n" +
" 00000e0: 09bb 10b5 5919 09b2 0765 1909 b80f 51b8\n" +
" 00000f0: 0651 b712 8ebf 1907 1908 b607 6819 062a\n" +
" 0000100: b80f a9b6 132e 1906 2ab6 10c1 b613 2f19\n" +
" 0000110: 0619 07b6 1330 1906 2cb6 1331 1906 2ab6\n" +
" 0000120: 1113 b613 3419 0619 07b6 1335 1906 b613\n" +
" 0000130: 36b6 1339 9900 0c2d 1906 b613 36b6 1324\n" +
" 0000140: 2ab8 0fa9 1907 b607 5603 b906 fa02 0013\n" +
" 0000150: 077f b810 9bc0 077f b607 8104 b611 d03a\n" +
" 0000160: 092d 1909 b811 ccb6 133a 2db0 130d a8b4\n" +
" 0000170: 10dd 9a00 1b2a b810 e359 2aa5 0033 59c1\n" +
" 0000180: 0da8 9900 2cc0 0da8 2bb6 133e b013 0da8\n" +
" 0000190: b810 eb10 1b2a 2b13 133f 1313 1013 130d\n" +
" 00001a0: b810 f459 b810 f79a 0007 c013 0db0 57a7\n" +
" 00001b0: fe58 ").split("\n");
int[] ints = Arrays.stream(lines)
.map(s -> s.replaceAll(".*:", ""))
.map(s -> s.replace(" ", ""))
.filter(s -> !s.isEmpty())
.map(s -> s.split("(?<=\\G.{2})"))
.flatMap(Arrays::stream)
.mapToInt(s -> Integer.valueOf(s, 16))
.toArray();
IntBuffer buffer = IntBuffer.wrap(ints);
while (buffer.hasRemaining()) {
int position = buffer.position();
Opcodes opcode = Opcodes.valueOf(buffer.get());
boolean wide = false;
if (opcode == Opcodes.WIDE) {
wide = true;
opcode = Opcodes.valueOf(buffer.get());
}
int argCount = opcode.getArgCount();
if (argCount == -1) {
break;
}
if (wide)
argCount *= 2;
StringBuilder sb = new StringBuilder();
if (argCount == 0)
sb.append(String.format("%4d: %s ", position, opcode.name()));
else
sb.append(String.format("%4d: %-15s ", position, opcode.name()));
if ((argCount == 2 || argCount == 4) && (opcode.name().startsWith("IF") || opcode.name().startsWith("GOTO"))) {
if (argCount == 2) {
short s = (short)((buffer.get() << 8) | buffer.get());
sb.append(String.format("@%d", position + s));
}
else {
int i = (buffer.get() << 24) | (buffer.get() << 16) | (buffer.get() << 8) | (buffer.get());
sb.append(String.format("@%d", position + i));
}
}
else if (argCount > 0) {
sb.append('#');
for (int i = 0; i < argCount; i++) {
sb.append(String.format("%02x", buffer.get()));
}
}
System.out.println(sb.toString());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment