/** * Parses an unsigned integers from a byte array. * * @param bytes The byte array containing the unsigned integer. * @return The unsigned integer represented by the given bytes. */ @SuppressWarnings("unused") public static long parseUnsignedInt(byte[] bytes) { return parseUnsignedInt(bytes, 0, bytes.length); }
/** * Reads the length for arrays, sets and dictionaries. * * @param objInfo Object information byte. * @param offset Offset in the byte array at which the object is located. * @return An array with the length two. First entry is the length, second entry the offset at which the content starts. */ private int[] readLengthAndOffset(int objInfo, int offset) { int lengthValue = objInfo; int offsetValue = 1; if (objInfo == 0xF) { int int_type = this.bytes[offset + 1]; int intType = (int_type & 0xF0) >> 4; if (intType != 0x1) { System.err.println("BinaryPropertyListParser: Length integer has an unexpected type" + intType + ". Attempting to parse anyway..."); } int intInfo = int_type & 0x0F; int intLength = (int) Math.pow(2, intInfo); offsetValue = 2 + intLength; if (intLength < 3) { lengthValue = (int) parseUnsignedInt(this.bytes, offset + 2, offset + 2 + intLength); } else { lengthValue = new BigInteger(copyOfRange(this.bytes, offset + 2, offset + 2 + intLength)).intValue(); } } return new int[]{lengthValue, offsetValue}; }
int offsetSize = (int) parseUnsignedInt(trailer, 6, 7); this.objectRefSize = (int) parseUnsignedInt(trailer, 7, 8); int numObjects = (int) parseUnsignedInt(trailer, 8, 16); int topObject = (int) parseUnsignedInt(trailer, 16, 24); int offsetTableOffset = (int) parseUnsignedInt(trailer, 24, 32); this.offsetTable[i] = (int) parseUnsignedInt(this.bytes, offsetTableOffset + i * offsetSize, offsetTableOffset + (i + 1) * offsetSize);
int objRef = (int) parseUnsignedInt(this.bytes, offset + arrayOffset + i * this.objectRefSize, offset + arrayOffset + (i + 1) * this.objectRefSize); array.setValue(i, this.parseObject(objRef)); int objRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + i * this.objectRefSize, offset + contentOffset + (i + 1) * this.objectRefSize); set.addObject(this.parseObject(objRef)); int objRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + i * this.objectRefSize, offset + contentOffset + (i + 1) * this.objectRefSize); set.addObject(this.parseObject(objRef)); int keyRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + i * this.objectRefSize, offset + contentOffset + (i + 1) * this.objectRefSize); int valRef = (int) parseUnsignedInt(this.bytes, offset + contentOffset + (length * this.objectRefSize) + i * this.objectRefSize, offset + contentOffset + (length * this.objectRefSize) + (i + 1) * this.objectRefSize); NSObject key = this.parseObject(keyRef); NSObject val = this.parseObject(valRef);