Last active
August 29, 2015 13:56
-
-
Save CalebWhiting/9249768 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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