/** Checks if the constraints of operands of the said instruction(s) are satisfied. */ public void visitLOOKUPSWITCH(LOOKUPSWITCH o){ int[] matchs = o.getMatchs(); int max = Integer.MIN_VALUE; for (int i=0; i<matchs.length; i++){ if (matchs[i] == max && i != 0){ constraintViolated(o, "Match '"+matchs[i]+"' occurs more than once."); } if (matchs[i] < max){ constraintViolated(o, "Lookup table must be sorted but isn't."); } else{ max = matchs[i]; } } }
private byte[] getCodeBytes(Method m, int start, int end) { byte[] code = m.getCode().getCode(); byte[] bytes = new byte[end - start]; System.arraycopy(code, start, bytes, 0, end - start); try { ByteSequence sequence = new ByteSequence(code); while ((sequence.available() > 0) && (sequence.getIndex() < start)) { Instruction.readInstruction(sequence); } int pos; while (sequence.available() > 0 && ((pos = sequence.getIndex()) < end)) { Instruction ins = Instruction.readInstruction(sequence); if ((ins instanceof BranchInstruction) && !(ins instanceof TABLESWITCH) && !(ins instanceof LOOKUPSWITCH)) { BranchInstruction bi = (BranchInstruction) ins; int offset = bi.getIndex(); int target = offset + pos; if (target >= end) { // or target < start ?? byte hiByte = (byte) ((target >> 8) & 0x000000FF); byte loByte = (byte) (target & 0x000000FF); bytes[pos + bi.getLength() - 2 - start] = hiByte; bytes[pos + bi.getLength() - 1 - start] = loByte; } } } } catch (IOException ioe) { } return bytes; }