/// <summary> /// This method deSerializes the record from a byte array. /// </summary> /// <param name="data">The byte array containing the escher record information</param> /// <param name="offset">The starting offset into data</param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns>The number of bytes Read from the byte array.</returns> public override int FillFields(byte[] data, int offset, EscherRecordFactory recordFactory ) { int bytesRemaining = ReadHeader(data, offset); int pos = offset + 8; field_1_blipTypeWin32 = data[pos]; field_2_blipTypeMacOS = data[pos + 1]; field_3_uid = new byte[16]; Array.Copy(data, pos + 2, field_3_uid, 0, 16); field_4_tag = LittleEndian.GetShort(data, pos + 18); field_5_size = LittleEndian.GetInt(data, pos + 20); field_6_ref = LittleEndian.GetInt(data, pos + 24); field_7_offset = LittleEndian.GetInt(data, pos + 28); field_8_usage = data[pos + 32]; field_9_name = data[pos + 33]; field_10_unused2 = data[pos + 34]; field_11_unused3 = data[pos + 35]; bytesRemaining -= 36; int bytesRead = 0; if (bytesRemaining > 0) { field_12_blipRecord = (EscherBlipRecord)recordFactory.CreateRecord(data, pos + 36); bytesRead = field_12_blipRecord.FillFields(data, pos + 36, recordFactory); } pos += 36 + bytesRead; bytesRemaining -= bytesRead; _remainingData = new byte[bytesRemaining]; Array.Copy(data, pos, _remainingData, 0, bytesRemaining); return(bytesRemaining + 8 + 36 + (field_12_blipRecord == null ? 0 : field_12_blipRecord.RecordSize)); }
/** * Constructor used to read a binTable in from a Word document. */ public CHPBinTable(byte[] documentStream, byte[] tableStream, int offset, int size, CharIndexTranslator translator) { PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4); int length = binTable.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = binTable.GetProperty(x); int pageNum = LittleEndian.GetInt(node.Bytes); int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum; CHPFormattedDiskPage cfkp = new CHPFormattedDiskPage(documentStream, pageOffset, translator); int fkpSize = cfkp.Size(); for (int y = 0; y < fkpSize; y++) { CHPX chpx = cfkp.GetCHPX(y); if (chpx != null) { _textRuns.Add(chpx); } } } }
public override int ReadInt() { CheckAvaliable(SIZE_INT); byte[] data = new byte[SIZE_INT]; ReadFully(data, 0, SIZE_INT); return(LittleEndian.GetInt(data)); }
/// <summary> /// This method deSerializes the record from a byte array. /// </summary> /// <param name="data">The byte array containing the escher record information</param> /// <param name="offset">The starting offset into</param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns> /// The number of bytes Read from the byte array. /// </returns> public override int FillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesAfterHeader = ReadHeader(data, offset); int pos = offset + HEADER_SIZE; field_1_UID = new byte[16]; Array.Copy(data, pos, field_1_UID, 0, 16); pos += 16; field_2_cb = LittleEndian.GetInt(data, pos); pos += 4; field_3_rcBounds_x1 = LittleEndian.GetInt(data, pos); pos += 4; field_3_rcBounds_y1 = LittleEndian.GetInt(data, pos); pos += 4; field_3_rcBounds_x2 = LittleEndian.GetInt(data, pos); pos += 4; field_3_rcBounds_y2 = LittleEndian.GetInt(data, pos); pos += 4; field_4_ptSize_w = LittleEndian.GetInt(data, pos); pos += 4; field_4_ptSize_h = LittleEndian.GetInt(data, pos); pos += 4; field_5_cbSave = LittleEndian.GetInt(data, pos); pos += 4; field_6_fCompression = data[pos]; pos++; field_7_fFilter = data[pos]; pos++; raw_pictureData = new byte[field_5_cbSave]; Array.Copy(data, pos, raw_pictureData, 0, field_5_cbSave); // 0 means DEFLATE compression // 0xFE means no compression if (field_6_fCompression == 0) { field_pictureData = InflatePictureData(raw_pictureData); } else { field_pictureData = raw_pictureData; } return(bytesAfterHeader + HEADER_SIZE); }
/// <summary> /// Convert an array of blocks into a Set of integer indices /// </summary> /// <param name="blocks">the array of blocks containing the indices</param> /// <param name="raw_blocks">the list of blocks being managed. Unused /// blocks will be eliminated from the list</param> private void SetEntries(ListManagedBlock[] blocks, BlockList raw_blocks) { int limit = bigBlockSize.GetBATEntriesPerBlock(); for (int block_index = 0; block_index < blocks.Length; block_index++) { byte[] data = blocks[block_index].Data; int offset = 0; for (int k = 0; k < limit; k++) { int entry = LittleEndian.GetInt(data, offset); if (entry == POIFSConstants.UNUSED_BLOCK) { raw_blocks.Zap(_entries.Count); } _entries.Add(entry); offset += LittleEndianConsts.INT_SIZE; } // discard block blocks[block_index] = null; } raw_blocks.BAT = this; }
public Filetime(byte[] data, int offset) { _dwLowDateTime = LittleEndian.GetInt(data, offset + 0 * LittleEndianConsts.INT_SIZE); _dwHighDateTime = LittleEndian.GetInt(data, offset + 1 * LittleEndianConsts.INT_SIZE); }
/// <summary> /// This method deSerializes the record from a byte array. /// </summary> /// <param name="data">The byte array containing the escher record information</param> /// <param name="offset">The starting offset into data</param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns>The number of bytes Read from the byte array.</returns> public override int FillFields(byte[] data, int offset, IEscherRecordFactory recordFactory) { int bytesRemaining = ReadHeader(data, offset); int pos = offset + 8; int size = 0; field_1_shapeIdMax = LittleEndian.GetInt(data, pos + size); size += 4; int field_2_numIdClusters = LittleEndian.GetInt(data, pos + size); size += 4; field_3_numShapesSaved = LittleEndian.GetInt(data, pos + size); size += 4; field_4_drawingsSaved = LittleEndian.GetInt(data, pos + size); size += 4; field_5_fileIdClusters = new FileIdCluster[(bytesRemaining - size) / 8]; // Can't rely on field_2_numIdClusters for (int i = 0; i < field_5_fileIdClusters.Length; i++) { field_5_fileIdClusters[i] = new FileIdCluster(LittleEndian.GetInt(data, pos + size), LittleEndian.GetInt(data, pos + size + 4)); maxDgId = Math.Max(maxDgId, field_5_fileIdClusters[i].DrawingGroupId); size += 8; } bytesRemaining -= size; if (bytesRemaining != 0) { throw new RecordFormatException("Expecting no remaining data but got " + bytesRemaining + " byte(s)."); } return(8 + size + bytesRemaining); }
public void TestWriteRead() { _plexOfCps = new PlexOfCps(4); int last = 0; for (int x = 0; x < 110; x++) { byte[] intHolder = new byte[4]; int span = (int)(110.0f * (new Random((int)DateTime.Now.Ticks).Next(0, 100) / 100.0)); LittleEndian.PutInt(intHolder, 0, span); _plexOfCps.AddProperty(new GenericPropertyNode(last, last + span, intHolder)); last += span; } byte[] output = _plexOfCps.ToByteArray(); _plexOfCps = new PlexOfCps(output, 0, output.Length, 4); int len = _plexOfCps.Length; Assert.AreEqual(len, 110); last = 0; for (int x = 0; x < len; x++) { GenericPropertyNode node = _plexOfCps.GetProperty(x); Assert.AreEqual(node.Start, last); last = node.End; int span = LittleEndian.GetInt(node.Bytes); Assert.AreEqual(node.End - node.Start, span); } }
/// <summary> /// This method deserializes the record from a byte array. /// </summary> /// <param name="data">The byte array containing the escher record information</param> /// <param name="offset">The starting offset into</param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns> /// The number of bytes Read from the byte array. /// </returns> public override int FillFields(byte[] data, int offset, IEscherRecordFactory recordFactory ) { int bytesAfterHeader = ReadHeader(data, offset); int pos = offset + HEADER_SIZE; int size = 0; field_1_secondaryUID = new byte[16]; Array.Copy(data, pos + size, field_1_secondaryUID, 0, 16); size += 16; field_2_cacheOfSize = LittleEndian.GetInt(data, pos + size); size += 4; field_3_boundaryTop = LittleEndian.GetInt(data, pos + size); size += 4; field_4_boundaryLeft = LittleEndian.GetInt(data, pos + size); size += 4; field_5_boundaryWidth = LittleEndian.GetInt(data, pos + size); size += 4; field_6_boundaryHeight = LittleEndian.GetInt(data, pos + size); size += 4; field_7_width = LittleEndian.GetInt(data, pos + size); size += 4; field_8_height = LittleEndian.GetInt(data, pos + size); size += 4; field_9_cacheOfSavedSize = LittleEndian.GetInt(data, pos + size); size += 4; field_10_compressionFlag = data[pos + size]; size++; field_11_filter = data[pos + size]; size++; int bytesRemaining = bytesAfterHeader - size; field_12_data = new byte[bytesRemaining]; Array.Copy(data, pos + size, field_12_data, 0, bytesRemaining); size += bytesRemaining; return(HEADER_SIZE + size); }
public TextSpecInfoRun[] GetTextSpecInfoRuns() { ArrayList lst = new ArrayList(); int pos = 0; int[] bits = { 1, 0, 2 }; while (pos < _data.Length) { TextSpecInfoRun run = new TextSpecInfoRun(); run.len = LittleEndian.GetInt(_data, pos); pos += 4; run.mask = LittleEndian.GetInt(_data, pos); pos += 4; for (int i = 0; i < bits.Length; i++) { if ((run.mask & 1 << bits[i]) != 0) { switch (bits[i]) { case 0: run.spellInfo = LittleEndian.GetShort(_data, pos); pos += 2; break; case 1: run.langId = LittleEndian.GetShort(_data, pos); pos += 2; break; case 2: run.altLangId = LittleEndian.GetShort(_data, pos); pos += 2; break; } } } lst.Add(run); } return((TextSpecInfoRun[])lst.ToArray(typeof(TextSpecInfoRun))); }
public GUID(byte[] data, int offset) { _data1 = LittleEndian.GetInt(data, offset + 0); _data2 = LittleEndian.GetShort(data, offset + 4); _data3 = LittleEndian.GetShort(data, offset + 6); _data4 = LittleEndian.GetLong(data, offset + 8); }
public ComplexFileTable(byte[] documentStream, byte[] tableStream, int offset, int fcMin) { //skips through the prms before we reach the piece table. These contain data //for actual fast saved files List <SprmBuffer> sprmBuffers = new List <SprmBuffer>(); //skips through the prms before we reach the piece table. These contain data //for actual fast saved files while (tableStream[offset] == GRPPRL_TYPE) { offset++; int size = LittleEndian.GetShort(tableStream, offset); offset += LittleEndianConsts.SHORT_SIZE; byte[] bs = LittleEndian.GetByteArray(tableStream, offset, size); offset += size; SprmBuffer sprmBuffer = new SprmBuffer(bs, false, 0); sprmBuffers.Add(sprmBuffer); } this._grpprls = sprmBuffers.ToArray(); if (tableStream[offset] != TEXT_PIECE_TABLE_TYPE) { throw new IOException("The text piece table is corrupted"); } int pieceTableSize = LittleEndian.GetInt(tableStream, ++offset); offset += LittleEndianConsts.INT_SIZE; _tpt = new TextPieceTable(documentStream, tableStream, offset, pieceTableSize, fcMin); }
public PAPBinTable(byte[] documentStream, byte[] tableStream, byte[] dataStream, int offset, int size, CharIndexTranslator charIndexTranslator) { PlexOfCps binTable = new PlexOfCps(tableStream, offset, size, 4); int length = binTable.Length; for (int x = 0; x < length; x++) { GenericPropertyNode node = binTable.GetProperty(x); int pageNum = LittleEndian.GetInt(node.Bytes); int pageOffset = POIFSConstants.SMALLER_BIG_BLOCK_SIZE * pageNum; PAPFormattedDiskPage pfkp = new PAPFormattedDiskPage(documentStream, dataStream, pageOffset, charIndexTranslator); int fkpSize = pfkp.Size(); for (int y = 0; y < fkpSize; y++) { PAPX papx = pfkp.GetPAPX(y); _paragraphs.Add(papx); } } _dataStream = dataStream; }
/// <summary> /// Reads the header. /// </summary> /// <param name="data">The data.</param> /// <param name="offset">The off set.</param> /// <returns></returns> public static DeleteEscherRecordHeader ReadHeader(byte[] data, int offset) { DeleteEscherRecordHeader header = new DeleteEscherRecordHeader(); header.options = LittleEndian.GetShort(data, offset); header.recordId = LittleEndian.GetShort(data, offset + 2); header.remainingBytes = LittleEndian.GetInt(data, offset + 4); return header; }
/// <summary> /// Returns an <c>int</c> representing the Clipboard /// Format /// Will throw an exception if the Thumbnail's Clipboard Format /// Tag is not {@link Thumbnail#CFTAG_WINDOWS CFTAG_WINDOWS}. /// Possible return values are: /// <ul> /// <li>{@link #CF_METAFILEPICT CF_METAFILEPICT}</li> /// <li>{@link #CF_DIB CF_DIB}</li> /// <li>{@link #CF_ENHMETAFILE CF_ENHMETAFILE}</li> /// <li>{@link #CF_BITMAP CF_BITMAP}</li> /// </ul> /// </summary> /// <returns>a flag indicating the Clipboard Format</returns> public long GetClipboardFormat() { if (!(ClipboardFormatTag == CFTAG_WINDOWS)) { throw new HPSFException("Clipboard Format Tag of Thumbnail must " + "be CFTAG_WINDOWS."); } return(LittleEndian.GetInt(this.ThumbnailData, OFFSet_CF)); }
protected void FillFields(byte[] data, int offset) { field_1_lsid = LittleEndian.GetInt(data, 0x0 + offset); field_2_reserved1 = LittleEndian.GetInt(data, 0x4 + offset); field_3_reserved2 = LittleEndian.GetInt(data, 0x8 + offset); field_4_clfolvl = data[0xc + offset]; field_5_ibstFltAutoNum = data[0xd + offset]; field_6_grfhic = data[0xe + offset]; field_7_reserved3 = data[0xf + offset]; }
private GenericPropertyNode GetProperty(int index, byte[] buf, int offset) { int start = LittleEndian.GetInt(buf, offset + GetIntOffset(index)); int end = LittleEndian.GetInt(buf, offset + GetIntOffset(index + 1)); byte[] structure = new byte[_sizeOfStruct]; System.Array.Copy(buf, offset + GetStructOffset(index), structure, 0, _sizeOfStruct); return(new GenericPropertyNode(start, end, structure)); }
protected void FillFields(byte[] data, int offset) { field_1_spid = LittleEndian.GetInt(data, 0x0 + offset); field_2_xaLeft = LittleEndian.GetInt(data, 0x4 + offset); field_3_yaTop = LittleEndian.GetInt(data, 0x8 + offset); field_4_xaRight = LittleEndian.GetInt(data, 0xc + offset); field_5_yaBottom = LittleEndian.GetInt(data, 0x10 + offset); field_6_flags = LittleEndian.GetShort(data, 0x14 + offset); field_7_cTxbx = LittleEndian.GetInt(data, 0x16 + offset); }
public ParagraphHeight(byte[] buf, int offset) { infoField = LittleEndian.GetShort(buf, offset); offset += LittleEndianConsts.SHORT_SIZE; reserved = LittleEndian.GetShort(buf, offset); offset += LittleEndianConsts.SHORT_SIZE; dxaCol = LittleEndian.GetInt(buf, offset); offset += LittleEndianConsts.INT_SIZE; dymLineOrHeight = LittleEndian.GetInt(buf, offset); }
public SectionDescriptor(byte[] buf, int offset) { fn = LittleEndian.GetShort(buf, offset); offset += LittleEndianConsts.SHORT_SIZE; fcSepx = LittleEndian.GetInt(buf, offset); offset += LittleEndianConsts.INT_SIZE; fnMpr = LittleEndian.GetShort(buf, offset); offset += LittleEndianConsts.SHORT_SIZE; fcMpr = LittleEndian.GetInt(buf, offset); }
/// <summary> /// Reads the 8 byte header information and populates the /// <c>options</c> /// and /// <c>recordId</c> /// records. /// </summary> /// <param name="data">the byte array to Read from</param> /// <param name="offset">the offset to start Reading from</param> /// <returns>the number of bytes remaining in this record. This</returns> protected int ReadHeader(byte[] data, int offset) { //EscherRecordHeader header = EscherRecordHeader.ReadHeader(data, offset); //_options = header.Options; //_recordId = header.RecordId; //return header.RemainingBytes; _options = LittleEndian.GetShort(data, offset); _recordId = LittleEndian.GetShort(data, offset + 2); int remainingBytes = LittleEndian.GetInt(data, offset + 4); return remainingBytes; }
public Shape(GenericPropertyNode nodo) { byte[] contenuto = nodo.Bytes; _id = LittleEndian.GetInt(contenuto); _left = LittleEndian.GetInt(contenuto, 4); _top = LittleEndian.GetInt(contenuto, 8); _right = LittleEndian.GetInt(contenuto, 12); _bottom = LittleEndian.GetInt(contenuto, 16); _inDoc = (_left >= 0 && _right >= 0 && _top >= 0 && _bottom >= 0); }
/// <summary> /// This method deSerializes the record from a byte array. /// </summary> /// <param name="data">The byte array containing the escher record information</param> /// <param name="offset">The starting offset into data</param> /// <param name="recordFactory">May be null since this is not a container record.</param> /// <returns>The number of bytes Read from the byte array.</returns> public override int FillFields(byte[] data, int offset, EscherRecordFactory recordFactory) { int bytesRemaining = ReadHeader(data, offset); int pos = offset + 8; int size = 0; field_1_dx1 = LittleEndian.GetInt(data, pos + size); size += 4; field_2_dy1 = LittleEndian.GetInt(data, pos + size); size += 4; field_3_dx2 = LittleEndian.GetInt(data, pos + size); size += 4; field_4_dy2 = LittleEndian.GetInt(data, pos + size); size += 4; return(8 + size); }
public ListFormatOverride(byte[] buf, int offset) { _lsid = LittleEndian.GetInt(buf, offset); offset += LittleEndianConsts.INT_SIZE; _reserved1 = LittleEndian.GetInt(buf, offset); offset += LittleEndianConsts.INT_SIZE; _reserved2 = LittleEndian.GetInt(buf, offset); offset += LittleEndianConsts.INT_SIZE; _clfolvl = buf[offset++]; Array.Copy(buf, offset, _reserved3, 0, _reserved3.Length); _levelOverrides = new ListFormatOverrideLevel[_clfolvl]; }
public FIBLongHandler(byte[] mainStream, int offset) { int longCount = LittleEndian.GetShort(mainStream, offset); offset += LittleEndianConsts.SHORT_SIZE; _longs = new int[longCount]; for (int x = 0; x < longCount; x++) { _longs[x] = LittleEndian.GetInt(mainStream, offset + (x * LittleEndianConsts.INT_SIZE)); } }
/// <summary> /// Initializes this {@link PropertySet} instance from a byte /// array. The method assumes that it has been checked alReady that /// the byte array indeed represents a property Set stream. It does /// no more checks on its own. /// </summary> /// <param name="src">Byte array containing the property Set stream</param> /// <param name="offset">The property Set stream starts at this offset</param> /// <param name="Length">Length of the property Set stream.</param> private void init(byte[] src, int offset, int Length) { /* FIXME (3): Ensure that at most "Length" bytes are Read. */ /* * Read the stream's header fields. */ int o = offset; byteOrder = LittleEndian.GetUShort(src, o); o += LittleEndianConsts.SHORT_SIZE; format = LittleEndian.GetUShort(src, o); o += LittleEndianConsts.SHORT_SIZE; osVersion = (int)LittleEndian.GetUInt(src, o); o += LittleEndianConsts.INT_SIZE; classID = new ClassID(src, o); o += ClassID.LENGTH; int sectionCount = LittleEndian.GetInt(src, o); o += LittleEndianConsts.INT_SIZE; if (sectionCount < 0) { throw new HPSFRuntimeException("Section count " + sectionCount + " is negative."); } /* * Read the sections, which are following the header. They * start with an array of section descriptions. Each one * consists of a format ID telling what the section Contains * and an offset telling how many bytes from the start of the * stream the section begins. */ /* * Most property Sets have only one section. The Document * Summary Information stream has 2. Everything else is a rare * exception and is no longer fostered by Microsoft. */ sections = new ArrayList(sectionCount); /* * Loop over the section descriptor array. Each descriptor * consists of a ClassID and a DWord, and we have To increment * "offset" accordingly. */ for (int i = 0; i < sectionCount; i++) { Section s = new Section(src, o); o += ClassID.Length + LittleEndianConsts.INT_SIZE; sections.Add(s); } }
/// <summary> /// The contract of this method is to deSerialize an escher record including /// it's children. /// </summary> /// <param name="data">The byte array containing the Serialized escher /// records.</param> /// <param name="offset">The offset into the byte array.</param> /// <param name="recordFactory">A factory for creating new escher records</param> /// <returns>The number of bytes written.</returns> public override int FillFields(byte[] data, int offset, IEscherRecordFactory recordFactory) { int bytesRemaining = ReadHeader(data, offset); int pos = offset + 8; int size = 0; field_1_shapeId = LittleEndian.GetInt(data, pos + size); size += 4; field_2_flags = LittleEndian.GetInt(data, pos + size); size += 4; // bytesRemaining -= size; // remainingData = new byte[bytesRemaining]; // Array.Copy( data, pos + size, remainingData, 0, bytesRemaining ); return(RecordSize); }
public Blob(byte[] data, int offset) { int size = LittleEndian.GetInt(data, offset); if (size == 0) { _value = new byte[0]; return; } _value = LittleEndian.GetByteArray(data, offset + LittleEndian.INT_SIZE, size); }
public EscherColorRef(byte[] source, int start, int len) { Debug.Assert(len == 4 || len == 6); int offset = start; if (len == 6) { opid = LittleEndian.GetUShort(source, offset); offset += 2; } colorRef = LittleEndian.GetInt(source, offset); }
/** * Convert from split R, G, B values to an integer RGB value */ public static int JoinRGB(byte[] rgb) { if (rgb.Length != 3) { throw new Exception("joinRGB accepts a byte array of 3 values, but got one of " + rgb.Length + " values!"); } byte[] with_zero = new byte[4]; System.Array.Copy(rgb, 0, with_zero, 0, 3); with_zero[3] = 0; int ret = LittleEndian.GetInt(with_zero, 0); return(ret); }