Skip to content

Instantly share code, notes, and snippets.

@CalebWhiting
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save CalebWhiting/9249768 to your computer and use it in GitHub Desktop.

Select an option

Save CalebWhiting/9249768 to your computer and use it in GitHub Desktop.
private static ConstantPushInstruction nextPush(Instruction[] instructions, int index, int skip) {
for (; index < instructions.length; index++) {
Instruction i = instructions[index];
if (i.getOpcode() == Constants.BIPUSH || i.getOpcode() == Constants.SIPUSH) {
if (skip == 0) {
return (ConstantPushInstruction) instructions[index];
}
skip--;
}
}
return null;
}
private static boolean nextPushIs(Instruction[] instructions, int index, int skip, int value) {
ConstantPushInstruction push = nextPush(instructions, index, skip);
return push != null && value == push.getValue().intValue();
}
private static int getRevision(JavaClass jc) {
for (Method m : jc.getMethods()) {
if (m.getName().equals("init")) {
InstructionList list = new InstructionList(m.getCode().getCode());
Instruction[] instructions = list.getInstructions();
for (int i = 0; i < instructions.length; i++) {
if (nextPushIs(instructions, i, 0, 765) && nextPushIs(instructions, i, 1, 503)) {
return nextPush(instructions, i, 2).getValue().intValue();
}
}
}
}
return -1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment