public void PrivateHeaderBlock(byte[] data) { _data = data; long signature = LittleEndian.GetLong(_data, _signature_offset); if (signature != _signature) { byte[] OOXML_FILE_HEADER = POIFSConstants.OOXML_FILE_HEADER; if (_data[0] == OOXML_FILE_HEADER[0] && _data[1] == OOXML_FILE_HEADER[1] && _data[2] == OOXML_FILE_HEADER[2] && _data[3] == OOXML_FILE_HEADER[3]) { throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)"); } if ((signature & unchecked((long)0xFF8FFFFFFFFFFFFFL)) == 0x0010000200040009L) { throw new ArgumentException("The supplied data appears to be in BIFF2 format. " + "POI only supports BIFF8 format"); } throw new IOException("Invalid header signature; read " + LongToHex(signature) + ", expected " + LongToHex(_signature)); } if (_data[30] == 12) { bigBlockSize = POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS; } else if (_data[30] == 9) { bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; } else { throw new IOException("Unsupported blocksize (2^" + _data[30] + "). Expected 2^9 or 2^12."); } // Setup the fields to read and write the counts and starts _bat_count = new IntegerField(HeaderBlockConstants._bat_count_offset, _data).Value; _property_start = new IntegerField(HeaderBlockConstants._property_start_offset, _data).Value; _sbat_start = new IntegerField(HeaderBlockConstants._sbat_start_offset, _data).Value; _sbat_count = new IntegerField(HeaderBlockConstants._sbat_block_count_offset, _data).Value; _xbat_start = new IntegerField(HeaderBlockConstants._xbat_start_offset, _data).Value; _xbat_count = new IntegerField(HeaderBlockConstants._xbat_count_offset, _data).Value; }
/// <summary> /// Create a single instance initialized with default values /// </summary> protected BATBlock() { _data = new byte[POIFSConstants.BIG_BLOCK_SIZE]; for (int i = 0; i < this._data.Length; i++) { this._data[i] = _default_value; } _fields = new IntegerField[_entries_per_block]; int offset = 0; for (int j = 0; j < _entries_per_block; j++) { _fields[j] = new IntegerField(offset); offset += LittleEndianConsts.INT_SIZE; } }
/// <summary> /// Initializes a new instance of the <see cref="Property"/> class. /// </summary> protected Property() { _raw_data = new byte[POIFSConstants.PROPERTY_SIZE]; for (int i = 0; i < this._raw_data.Length; i++) { this._raw_data[i] = _default_fill; } _name_size = new ShortField(_name_size_offset); _property_type = new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET); _node_color = new ByteField(_node_color_offset); _previous_property = new IntegerField(_previous_property_offset, _NO_INDEX, _raw_data); _next_property = new IntegerField(_next_property_offset, _NO_INDEX, _raw_data); _child_property = new IntegerField(_child_property_offset, _NO_INDEX, _raw_data); _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset); _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data); _seconds_1 = new IntegerField(_seconds_1_offset, 0, _raw_data); _days_1 = new IntegerField(_days_1_offset, 0, _raw_data); _seconds_2 = new IntegerField(_seconds_2_offset, 0, _raw_data); _days_2 = new IntegerField(_days_2_offset, 0, _raw_data); _start_block = new IntegerField(_start_block_offset); _size = new IntegerField(_size_offset, 0, _raw_data); _index = _NO_INDEX; this.Name=""; this.NextChild=null; this.PreviousChild=null; }
/// <summary> /// create a new HeaderBlockReader from an Stream /// </summary> /// <param name="stream">the source Stream</param> public HeaderBlockReader(Stream stream) { stream.Position = 0; this._data = ReadFirst512(stream); // verify signature long signature = LittleEndian.GetLong(_data, HeaderBlockConstants._signature_offset); if (signature != HeaderBlockConstants._signature) { // Is it one of the usual suspects? byte[] OOXML_FILE_HEADER = POIFSConstants.OOXML_FILE_HEADER; if (_data[0] == OOXML_FILE_HEADER[0] && _data[1] == OOXML_FILE_HEADER[1] && _data[2] == OOXML_FILE_HEADER[2] && _data[3] == OOXML_FILE_HEADER[3]) { throw new OfficeXmlFileException("The supplied data appears to be in the Office 2007+ XML. POI only supports OLE2 Office documents"); } if ((signature & unchecked((long)0xFF8FFFFFFFFFFFFFL)) == 0x0010000200040009L) { // BIFF2 raw stream starts with BOF (sid=0x0009, size=0x0004, data=0x00t0) throw new ArgumentException("The supplied data appears to be in BIFF2 format. " + "POI only supports BIFF8 format"); } // Give a generic error throw new IOException("Invalid header signature; Read " + LongToHex(signature) + ", expected " + LongToHex(HeaderBlockConstants._signature)); } // Figure out our block size if (_data[30] == 12) { this.bigBlockSize = POIFSConstants.LARGER_BIG_BLOCK_SIZE_DETAILS; } else if (_data[30] == 9) { this.bigBlockSize = POIFSConstants.SMALLER_BIG_BLOCK_SIZE_DETAILS; } else { throw new IOException("Unsupported blocksize (2^" + _data[30] + "). Expected 2^9 or 2^12."); } // Setup the fields to read and write the counts and starts _bat_count = new IntegerField(HeaderBlockConstants._bat_count_offset, _data).Value; _property_start = new IntegerField(HeaderBlockConstants._property_start_offset, _data).Value; _sbat_start = new IntegerField(HeaderBlockConstants._sbat_start_offset, _data).Value; _sbat_count = new IntegerField(HeaderBlockConstants._sbat_block_count_offset, _data).Value; _xbat_start = new IntegerField(HeaderBlockConstants._xbat_start_offset, _data).Value; _xbat_count = new IntegerField(HeaderBlockConstants._xbat_count_offset, _data).Value; // Fetch the rest of the block if needed if (bigBlockSize.GetBigBlockSize() != 512) { int rest = bigBlockSize.GetBigBlockSize() - 512; byte[] tmp = new byte[rest]; IOUtils.ReadFully(stream, tmp); } }
/// <summary> /// Constructor from byte data /// </summary> /// <param name="index">index number</param> /// <param name="array">byte data</param> /// <param name="offset">offset into byte data</param> protected Property(int index, byte [] array, int offset) { _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; System.Array.Copy(array, offset, _raw_data, 0, POIFSConstants.PROPERTY_SIZE); _name_size = new ShortField(_name_size_offset, _raw_data); _property_type = new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data); _node_color = new ByteField(_node_color_offset, _raw_data); _previous_property = new IntegerField(_previous_property_offset, _raw_data); _next_property = new IntegerField(_next_property_offset, _raw_data); _child_property = new IntegerField(_child_property_offset, _raw_data); _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset); _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data); _seconds_1 = new IntegerField(_seconds_1_offset, _raw_data); _days_1 = new IntegerField(_days_1_offset, _raw_data); _seconds_2 = new IntegerField(_seconds_2_offset, _raw_data); _days_2 = new IntegerField(_days_2_offset, _raw_data); _start_block = new IntegerField(_start_block_offset, _raw_data); _size = new IntegerField(_size_offset, _raw_data); _index = index; int name_length = (_name_size.Value / LittleEndianConsts.SHORT_SIZE) - 1; if (name_length < 1) { _name = ""; } else { char[] char_array = new char[ name_length ]; int name_offset = 0; for (int j = 0; j < name_length; j++) { char_array[ j ] = ( char ) new ShortField(name_offset, _raw_data).Value; name_offset += LittleEndianConsts.SHORT_SIZE; } _name = new String(char_array, 0, name_length); } _next_child = null; _previous_child = null; }