public StreamEncryptionInfo(RecordInputStream rs, List <Record> outputRecs)
            {
                Record rec;

                rs.NextRecord();
                int recSize = 4 + rs.Remaining;

                rec = RecordFactory.CreateSingleRecord(rs);
                outputRecs.Add(rec);
                FilePassRecord fpr = null;

                if (rec is BOFRecord)
                {
                    _hasBOFRecord = true;
                    if (rs.HasNextRecord)
                    {
                        rs.NextRecord();
                        rec      = RecordFactory.CreateSingleRecord(rs);
                        recSize += rec.RecordSize;
                        outputRecs.Add(rec);
                        if (rec is FilePassRecord)
                        {
                            fpr = (FilePassRecord)rec;
                            outputRecs.RemoveAt(outputRecs.Count - 1);
                            // TODO - add fpr not Added to outPutRecs
                            rec = outputRecs[0];
                        }
                        else
                        {
                            // workbook not encrypted (typical case)
                            if (rec is EOFRecord)
                            {
                                // A workbook stream is never empty, so crash instead
                                // of trying to keep track of nesting level
                                throw new InvalidOperationException("Nothing between BOF and EOF");
                            }
                        }
                    }
                }
                else
                {
                    // Invalid in a normal workbook stream.
                    // However, some test cases work on sub-sections of
                    // the workbook stream that do not begin with BOF
                    _hasBOFRecord = false;
                }
                _InitialRecordsSize = recSize;
                _filePassRec        = fpr;
                _lastRecord         = rec;
            }
 private static RecordInputStream ConvertToInputStream(DrawingRecord r)
 {
     byte[] data = r.Serialize();
     using (MemoryStream ms = new MemoryStream(data))
     {
         RecordInputStream rinp = new RecordInputStream(ms);
         rinp.NextRecord();
         return(rinp);
     }
 }
Exemple #3
0
        public Record CloneViaReserialise()
        {
            // Do it via a re-serialization
            // It's a cheat, but it works...
            byte[] b = Serialize();
            using (MemoryStream ms = new MemoryStream(b))
            {
                RecordInputStream rinp = new RecordInputStream(ms);
                rinp.NextRecord();

                Record[] r = RecordFactory.CreateRecord(rinp);
                if (r.Length != 1)
                {
                    throw new InvalidOperationException("Re-serialised a record to clone it, but got " + r.Length + " records back!");
                }
                return(r[0]);
            }
        }
        /**
         * Returns the next (complete) record from the
         * stream, or null if there are no more.
         */
        public Record NextRecord()
        {
            Record r;

            r = GetNextUnreadRecord();
            if (r != null)
            {
                // found an unread record
                return(r);
            }
            while (true)
            {
                if (!_recStream.HasNextRecord)
                {
                    // recStream is exhausted;
                    return(null);
                }

                // step underlying RecordInputStream to the next record
                _recStream.NextRecord();

                if (_lastRecordWasEOFLevelZero)
                {
                    // Potential place for ending the workbook stream
                    // Check that the next record is not BOFRecord(0x0809)
                    // Normally the input stream Contains only zero pAdding after the last EOFRecord,
                    // but bug 46987 and 48068 suggests that the padding may be garbage.
                    // This code relies on the pAdding bytes not starting with BOFRecord.sid
                    if (_recStream.Sid != BOFRecord.sid)
                    {
                        return(null);
                    }
                    // else - another sheet substream starting here
                }

                r = ReadNextRecord();
                if (r == null)
                {
                    // some record types may get skipped (e.g. DBCellRecord and ContinueRecord)
                    continue;
                }
                return(r);
            }
        }
Exemple #5
0
        /**
         * Constructs a EOFRecord record and Sets its fields appropriately.
         * @param in the RecordInputstream to Read the record from
         */

        public ExtSSTRecord(RecordInputStream in1)
        {
            field_1_strings_per_bucket = in1.ReadShort();

            int nInfos = in1.Remaining / InfoSubRecord.ENCODED_SIZE;
            List <InfoSubRecord> lst = new List <InfoSubRecord>(nInfos);

            while (in1.Available() > 0)
            {
                InfoSubRecord info = new InfoSubRecord(in1);
                lst.Add(info);

                if (in1.Available() == 0 && in1.HasNextRecord && in1.GetNextSid() == ContinueRecord.sid)
                {
                    in1.NextRecord();
                }
            }
            _sstInfos = lst.ToArray();
        }