public void TestFillFields()
        {
            String TestData =
                    "0F 02 " + // options
                    "11 F1 " + // record id
                    "00 00 00 00";      // remaining bytes

            UnknownEscherRecord r = new UnknownEscherRecord();
            EscherRecordFactory factory = new DefaultEscherRecordFactory();
            r.FillFields(HexRead.ReadFromString(TestData), factory);

            Assert.AreEqual(0x020F, r.Options);
            Assert.AreEqual(unchecked((short)0xF111), r.RecordId);
            Assert.IsTrue(r.IsContainerRecord);
            Assert.AreEqual(8, r.RecordSize);
            Assert.AreEqual(0, r.ChildRecords.Count);
            Assert.AreEqual(0, r.Data.Length);

            TestData =
                    "00 02 " + // options
                    "11 F1 " + // record id
                    "04 00 00 00 " + // remaining bytes
                    "01 02 03 04";

            r = new UnknownEscherRecord();
            r.FillFields(HexRead.ReadFromString(TestData), factory);

            Assert.AreEqual(0x0200, r.Options);
            Assert.AreEqual(unchecked((short)0xF111), r.RecordId);
            Assert.AreEqual(12, r.RecordSize);
            Assert.IsFalse(r.IsContainerRecord);
            Assert.AreEqual(0, r.ChildRecords.Count);
            Assert.AreEqual(4, r.Data.Length);
            Assert.AreEqual(1, r.Data[0]);
            Assert.AreEqual(2, r.Data[1]);
            Assert.AreEqual(3, r.Data[2]);
            Assert.AreEqual(4, r.Data[3]);

            TestData =
                    "0F 02 " + // options
                    "11 F1 " + // record id
                    "08 00 00 00 " + // remaining bytes
                    "00 02 " + // options
                    "FF FF " + // record id
                    "00 00 00 00";      // remaining bytes

            r = new UnknownEscherRecord();
            r.FillFields(HexRead.ReadFromString(TestData), factory);

            Assert.AreEqual(0x020F, r.Options);
            Assert.AreEqual(unchecked((short)0xF111), r.RecordId);
            Assert.AreEqual(8, r.RecordSize);
            Assert.IsTrue(r.IsContainerRecord);
            Assert.AreEqual(1, r.ChildRecords.Count);
            Assert.AreEqual(unchecked((short)0xFFFF), r.GetChild(0).RecordId);

        }
Exemple #2
0
 /// <summary>
 /// Decodes the escher stream from a byte array and dumps the results to
 /// a print stream.
 /// </summary>
 /// <param name="data">The data array containing the escher records.</param>
 /// <param name="offset">The starting offset within the data array.</param>
 /// <param name="size">The number of bytes to Read.</param>
 public void Dump(byte[] data, int offset, int size)
 {
     IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
     int pos = offset;
     while (pos < offset + size)
     {
         EscherRecord r = recordFactory.CreateRecord(data, pos);
         int bytesRead = r.FillFields(data, pos, recordFactory);
         Console.WriteLine(r.ToString());
         pos += bytesRead;
     }
 }
 private void FillEscherRecords(byte[] data, int offset, int size)
 {
     IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
     int pos = offset;
     while (pos < offset + size)
     {
         EscherRecord r = recordFactory.CreateRecord(data, pos);
         escherRecords.Add(r);
         int bytesRead = r.FillFields(data, pos, recordFactory);
         pos += bytesRead + 1; // There Is an empty byte between each top-level record in a Word doc
     }
 }
Exemple #4
0
        /// <summary>
        /// Decodes the escher stream from a byte array and dumps the results to
        /// a print stream.
        /// </summary>
        /// <param name="data">The data array containing the escher records.</param>
        /// <param name="offset">The starting offset within the data array.</param>
        /// <param name="size">The number of bytes to Read.</param>
        public void Dump(byte[] data, int offset, int size)
        {
            IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
            int pos = offset;

            while (pos < offset + size)
            {
                EscherRecord r         = recordFactory.CreateRecord(data, pos);
                int          bytesRead = r.FillFields(data, pos, recordFactory);
                Console.WriteLine(r.ToString());
                pos += bytesRead;
            }
        }
Exemple #5
0
        private EscherBlipRecord GetBitmapRecord(int bitmapIndex)
        {
            List<EscherContainerRecord> bContainers = _escherRecordHolder
                    .GetBStoreContainers();
            if (bContainers == null || bContainers.Count != 1)
                return null;

            EscherContainerRecord bContainer = bContainers[0];
            IList bitmapRecords = bContainer.ChildRecords;

            if (bitmapRecords.Count < bitmapIndex)
                return null;

            EscherRecord imageRecord = (EscherRecord)bitmapRecords[bitmapIndex - 1];

            if (imageRecord is EscherBlipRecord)
            {
                return (EscherBlipRecord)imageRecord;
            }

            if (imageRecord is EscherBSERecord)
            {
                EscherBSERecord bseRecord = (EscherBSERecord)imageRecord;

                EscherBlipRecord blip = bseRecord.BlipRecord;
                if (blip != null)
                {
                    return blip;
                }

                if (bseRecord.Offset > 0)
                {
                    /*
                     * Blip stored in delay stream, which in a word doc, is the main
                     * stream
                     */
                    EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                    EscherRecord record = recordFactory.CreateRecord(_mainStream,
                            bseRecord.Offset);

                    if (record is EscherBlipRecord)
                    {
                        record.FillFields(_mainStream, bseRecord.Offset,
                                recordFactory);
                        return (EscherBlipRecord)record;
                    }
                }
            }

            return null;
        }
        public void TestFillFields()
        {
            IEscherRecordFactory f = new DefaultEscherRecordFactory();
            byte[] data = HexRead.ReadFromString("0F 02 11 F1 00 00 00 00");
            EscherRecord r = f.CreateRecord(data, 0);
            r.FillFields(data, 0, f);
            Assert.IsTrue(r is EscherContainerRecord);
            Assert.AreEqual((short)0x020F, r.Options);
            Assert.AreEqual(unchecked((short)0xF111), r.RecordId);

            data = HexRead.ReadFromString("0F 02 11 F1 08 00 00 00" +
                    " 02 00 22 F2 00 00 00 00");
            r = f.CreateRecord(data, 0);
            r.FillFields(data, 0, f);
            EscherRecord c = r.GetChild(0);
            Assert.IsFalse(c is EscherContainerRecord);
            Assert.AreEqual(unchecked((short)0x0002), c.Options);
            Assert.AreEqual(unchecked((short)0xF222), c.RecordId);
        }
 private void ConvertToEscherRecords(int offset, int size, byte[] data)
 {
     escherRecords.Clear();
     IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
     int pos = offset;
     while (pos < offset + size)
     {
         EscherRecord r = recordFactory.CreateRecord(data, pos);
         int bytesRead = r.FillFields(data, pos, recordFactory);
         escherRecords.Add(r);
         pos += bytesRead;
     }
 }
Exemple #8
0
        public void TestIncompleteData()
        {
            //EscherDgContainer and EscherSpgrContainer length exceeds the actual length of the data
            String hex =
                    " 0F 00 02 F0 30 03 00 00 10 00 08 F0 08 00 00 " +
                    " 00 07 00 00 00 B2 04 00 00 0F 00 03 F0 18 03 00 " +
                    " 00 0F 00 04 F0 28 00 00 00 01 00 09 F0 10 00 00 " +
                    " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 " +
                    " 00 02 00 0A F0 08 00 00 00 00 04 00 00 05 00 00 " +
                    " 00 0F 00 04 F0 74 00 00 00 92 0C 0A F0 08 00 00 " +
                    " 00 AD 04 00 00 00 0A 00 00 63 00 0B F0 3A 00 00 " +
                    " 00 7F 00 04 01 E5 01 BF 00 08 00 08 00 81 01 4E " +
                    " 00 00 08 BF 01 10 00 10 00 80 C3 16 00 00 00 BF " +
                    " 03 00 00 02 00 44 00 69 00 61 00 67 00 72 00 61 " +
                    " 00 6D 00 6D 00 20 00 32 00 00 00 00 00 10 F0 12 " +
                    " 00 00 00 00 00 05 00 00 00 01 00 00 00 0B 00 00 " +
                    " 00 0F 00 66 00 00 00 11 F0 00 00 00 00 ";
            byte[] buffer = HexRead.ReadFromString(hex);

            List<EscherRecord> records = new List<EscherRecord>();
            IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
            int pos = 0;
            while (pos < buffer.Length)
            {
                EscherRecord r = recordFactory.CreateRecord(buffer, pos);
                int bytesRead = r.FillFields(buffer, pos, recordFactory);
                records.Add(r);
                pos += bytesRead;
            }
            Assert.AreEqual(buffer.Length, pos, "data was not fully Read");

            // serialize to byte array
            MemoryStream out1 = new MemoryStream();
            try
            {
                foreach (EscherRecord r in records)
                {
                    byte[] data = r.Serialize();
                    out1.Write(data, 0, data.Length);
                }
            }
            catch (IOException e)
            {
                throw new RuntimeException(e);
            }
            Assert.AreEqual(HexDump.ToHex(buffer, 10), HexDump.ToHex(out1.ToArray(), 10));
        }
Exemple #9
0
        /**
           * Performs a recursive search for pictures in the given list of escher records.
           *
           * @param escherRecords the escher records.
           * @param pictures the list to populate with the pictures.
           */
        private void SearchForPictures(IList escherRecords, List<Picture> pictures)
        {
            foreach (EscherRecord escherRecord in escherRecords)
            {
                if (escherRecord is EscherBSERecord)
                {
                    EscherBSERecord bse = (EscherBSERecord)escherRecord;
                    EscherBlipRecord blip = bse.BlipRecord;
                    if (blip != null)
                    {
                        pictures.Add(new Picture(blip.PictureData));
                    }
                    else if (bse.Offset > 0)
                    {
                        // Blip stored in delay stream, which in a word doc, is the main stream
                        EscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                        EscherRecord record = recordFactory.CreateRecord(_mainStream, bse.Offset);

                        if (record is EscherBlipRecord)
                        {
                            record.FillFields(_mainStream, bse.Offset, recordFactory);
                            blip = (EscherBlipRecord)record;
                            pictures.Add(new Picture(blip.PictureData));
                        }
                    }
                }

                // Recursive call.
                SearchForPictures(escherRecord.ChildRecords, pictures);
            }
        }
        /**
           * Performs a recursive search for pictures in the given list of escher records.
           *
           * @param escherRecords the escher records.
           * @param pictures the list to populate with the pictures.
           */
        private void SearchForPictures(IList escherRecords, List<Picture> pictures)
        {
            foreach (EscherRecord escherRecord in escherRecords)
            {
                if (escherRecord is EscherBSERecord)
                {
                    EscherBSERecord bse = (EscherBSERecord)escherRecord;
                    EscherBlipRecord blip = bse.BlipRecord;
                    if (blip != null)
                    {
                        pictures.Add(new Picture(blip.PictureData));
                    }
                    else if (bse.Offset > 0)
                    {
                        try
                        {
                            // Blip stored in delay stream, which in a word doc, is the main stream
                            IEscherRecordFactory recordFactory = new DefaultEscherRecordFactory();
                            EscherRecord record = recordFactory.CreateRecord(_mainStream, bse.Offset);

                            if (record is EscherBlipRecord)
                            {
                                record.FillFields(_mainStream, bse.Offset, recordFactory);
                                blip = (EscherBlipRecord)record;
                                pictures.Add(new Picture(blip.PictureData));
                            }

                        }
                        catch (Exception exc)
                        {
                            logger.Log(
                                    POILogger.WARN,
                                    "Unable to load picture from BLIB record at offset #",
                                    bse.Offset, exc);
                        }
                    }
                }

                // Recursive call.
                SearchForPictures(escherRecord.ChildRecords, pictures);
            }
        }