Esempio n. 1
0
        private static String getRecordName(int sid)
        {
            Type recordClass = RecordFactory.GetRecordClass(sid);

            if (recordClass == null)
            {
                return(null);
            }
            return(recordClass.Name);
        }
Esempio n. 2
0
            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;
            }
        /**
         * Clone the current record, via a call to serialise
         *  it, and another to Create a new record from the
         *  bytes.
         * May only be used for classes which don't have
         *  internal counts / ids in them. For those which
         *  do, a full record-aware serialise is needed, which
         *  allocates new ids / counts as needed.
         */
        public override Record CloneViaReserialise()
        {
            // Do it via a re-serialise
            // It's a cheat, but it works...
            byte[]            b    = this.Serialize();
            RecordInputStream rinp = new RecordInputStream(
                new System.IO.MemoryStream(b)
                );

            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]);
        }
Esempio n. 4
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]);
            }
        }
Esempio n. 5
0
        /**
         * @return the next available record, or <code>null</code> if
         * this pass didn't return a record that's
         * suitable for returning (eg was a continue record).
         */
        private Record ReadNextRecord()
        {
            Record record = RecordFactory.CreateSingleRecord(_recStream);

            _lastRecordWasEOFLevelZero = false;

            if (record is BOFRecord)
            {
                _bofDepth++;
                return(record);
            }

            if (record is EOFRecord)
            {
                _bofDepth--;
                if (_bofDepth < 1)
                {
                    _lastRecordWasEOFLevelZero = true;
                }

                return(record);
            }

            if (record is DBCellRecord)
            {
                // Not needed by POI.  Regenerated from scratch by POI when spreadsheet is written
                return(null);
            }

            if (record is RKRecord)
            {
                return(RecordFactory.ConvertToNumberRecord((RKRecord)record));
            }

            if (record is MulRKRecord)
            {
                Record[] records = RecordFactory.ConvertRKRecords((MulRKRecord)record);

                _unreadRecordBuffer = records;
                _unreadRecordIndex  = 1;
                return(records[0]);
            }

            if (record.Sid == DrawingGroupRecord.sid &&
                _lastRecord is DrawingGroupRecord)
            {
                DrawingGroupRecord lastDGRecord = (DrawingGroupRecord)_lastRecord;
                lastDGRecord.Join((AbstractEscherHolderRecord)record);
                return(null);
            }
            if (record.Sid == ContinueRecord.sid)
            {
                ContinueRecord contRec = (ContinueRecord)record;

                if (_lastRecord is ObjRecord || _lastRecord is TextObjectRecord)
                {
                    // Drawing records have a very strange continue behaviour.
                    //There can actually be OBJ records mixed between the continues.
                    _lastDrawingRecord.ProcessContinueRecord(contRec.Data);
                    //we must remember the position of the continue record.
                    //in the serialization procedure the original structure of records must be preserved
                    if (_shouldIncludeContinueRecords)
                    {
                        return(record);
                    }
                    return(null);
                }
                if (_lastRecord is DrawingGroupRecord)
                {
                    ((DrawingGroupRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                    return(null);
                }
                if (_lastRecord is DrawingRecord)
                {
                    ((DrawingRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                    return(null);
                }
                if (_lastRecord is CrtMlFrtRecord)
                {
                    return(record);
                }
                if (_lastRecord is UnknownRecord)
                {
                    //Gracefully handle records that we don't know about,
                    //that happen to be continued
                    return(record);
                }
                if (_lastRecord is EOFRecord)
                {
                    // This is really odd, but excel still sometimes
                    //  outPuts a file like this all the same
                    return(record);
                }
                //if (_lastRecord is StringRecord)
                //{
                //    ((StringRecord)_lastRecord).ProcessContinueRecord(contRec.Data);
                //    return null;
                //}
                throw new RecordFormatException("Unhandled Continue Record");
            }
            _lastRecord = record;
            if (record is DrawingRecord)
            {
                _lastDrawingRecord = (DrawingRecord)record;
            }
            return(record);
        }
            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;
                    // Fetch the next record, and see if it indicates whether
                    //  the document is encrypted or not
                    if (rs.HasNextRecord)
                    {
                        rs.NextRecord();
                        rec      = RecordFactory.CreateSingleRecord(rs);
                        recSize += rec.RecordSize;
                        outputRecs.Add(rec);
                        // Encrypted is normally BOF then FILEPASS
                        // May sometimes be BOF, WRITEPROTECT, FILEPASS
                        if (rec is WriteProtectRecord && rs.HasNextRecord)
                        {
                            rs.NextRecord();
                            rec      = RecordFactory.CreateSingleRecord(rs);
                            recSize += rec.RecordSize;
                            outputRecs.Add(rec);
                        }
                        // If it's a FILEPASS, track it specifically but
                        //  don't include it in the main stream
                        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;
            }