Beispiel #1
0
        public void Test_VISIT_STORAGE()
        {
            String FILENAME = "testVisiting.xls";

            // Remove...
            if (File.Exists(FILENAME))
            {
                File.Delete(FILENAME);
            }

            //Create...

            CompoundFile ncf = new CompoundFile();

            CFStorage l1 = ncf.RootStorage.AddStorage("Storage Level 1");

            l1.AddStream("l1ns1");
            l1.AddStream("l1ns2");
            l1.AddStream("l1ns3");

            CFStorage l2 = l1.AddStorage("Storage Level 2");

            l2.AddStream("l2ns1");
            l2.AddStream("l2ns2");

            ncf.Save(FILENAME);
            ncf.Close();


            // Read...

            CompoundFile cf = new CompoundFile(FILENAME);

            FileStream output = new FileStream("reportVisit.txt", FileMode.Create);
            TextWriter sw     = new StreamWriter(output);

            Console.SetOut(sw);

            Action <CFItem> va = delegate(CFItem target)
            {
                sw.WriteLine(target.Name);
            };

            cf.RootStorage.VisitEntries(va, true);

            cf.Close();
            sw.Close();
        }
Beispiel #2
0
        private void SingleWriteReadMatching(int size)
        {
            String filename = "INCREMENTAL_SIZE_MULTIPLE_WRITE_AND_READ_CFS.cfs";

            if (File.Exists(filename))
            {
                File.Delete(filename);
            }

            CompoundFile cf = new CompoundFile();
            CFStorage    st = cf.RootStorage.AddStorage("MyStorage");
            CFStream     sm = st.AddStream("MyStream");

            byte[] b = Helpers.GetBuffer(size);

            sm.SetData(b);
            cf.Save(filename);
            cf.Close();

            CompoundFile cf2 = new CompoundFile(filename);
            CFStorage    st2 = cf2.RootStorage.GetStorage("MyStorage");
            CFStream     sm2 = st2.GetStream("MyStream");

            Assert.IsNotNull(sm2);
            Assert.IsTrue(sm2.Size == size);
            Assert.IsTrue(Helpers.CompareBuffer(sm2.GetData(), b));

            cf2.Close();
        }
Beispiel #3
0
        public void Test_WRITE_READ_CFS_VERSION_4_STREAM()
        {
            String filename = "WRITE_COMMIT_READ_CFS_V4.cfs";

            CompoundFile cf = new CompoundFile(CFSVersion.Ver_4,
                                               CFSConfiguration.SectorRecycle | CFSConfiguration.EraseFreeSectors);

            CFStorage st = cf.RootStorage.AddStorage("MyStorage");
            CFStream  sm = st.AddStream("MyStream");

            byte[] b = Helpers.GetBuffer(227);
            sm.SetData(b);

            cf.Save(filename);
            cf.Close();

            CompoundFile cf2 = new CompoundFile(filename);
            CFStorage    st2 = cf2.RootStorage.GetStorage("MyStorage");
            CFStream     sm2 = st2.GetStream("MyStream");

            Assert.IsNotNull(sm2);
            Assert.IsTrue(sm2.Size == b.Length);

            cf2.Close();
        }
Beispiel #4
0
        /// <summary>
        /// Returns the complete tree with all the <see cref="CFStorage"/> and <see cref="CFStream"/> children
        /// </summary>
        /// <param name="rootStorage"></param>
        /// <param name="storage"></param>
        private static void GetStorageChain(CFStorage rootStorage, CFStorage storage)
        {
            Logger.WriteToLog("Copying storage to compound file");

            void Entries(CFItem item)
            {
                if (item.IsStorage)
                {
                    var newRootStorage = rootStorage.AddStorage(item.Name);
                    GetStorageChain(newRootStorage, item as CFStorage);
                }
                else if (item.IsStream)
                {
                    var childStream = item as CFStream;
                    if (childStream == null)
                    {
                        return;
                    }
                    var stream = rootStorage.AddStream(item.Name);
                    var bytes  = childStream.GetData();
                    stream.SetData(bytes);
                }
            }

            storage.VisitEntries(Entries, false);
        }
Beispiel #5
0
        public void Test_WRITE_AND_READ_CFS_VERSION_4()
        {
            String filename = "WRITE_AND_READ_CFS_V4.cfs";

            CompoundFile cf = new CompoundFile(CFSVersion.Ver_4,
                                               CFSConfiguration.EraseFreeSectors | CFSConfiguration.SectorRecycle);

            CFStorage st = cf.RootStorage.AddStorage("MyStorage");
            CFStream  sm = st.AddStream("MyStream");

            byte[] b = new byte[220];
            sm.SetData(b);

            cf.Save(filename);
            cf.Close();

            CompoundFile cf2 = new CompoundFile(filename);
            CFStorage    st2 = cf2.RootStorage.GetStorage("MyStorage");
            CFStream     sm2 = st2.GetStream("MyStream");

            Assert.IsNotNull(sm2);
            Assert.IsTrue(sm2.Size == 220);

            cf2.Close();
        }
Beispiel #6
0
        public void Test_WRITE_AND_READ_CFS()
        {
            String filename = "WRITE_AND_READ_CFS.cfs";

            CompoundFile cf = new CompoundFile();

            CFStorage st = cf.RootStorage.AddStorage("MyStorage");
            CFStream  sm = st.AddStream("MyStream");

            byte[] b = Helpers.GetBuffer(220, 0x0A);
            sm.SetData(b);

            cf.Save(filename);
            cf.Close();

            CompoundFile cf2 = new CompoundFile(filename);
            CFStorage    st2 = cf2.RootStorage.GetStorage("MyStorage");
            CFStream     sm2 = st2.GetStream("MyStream");

            cf2.Close();

            Assert.IsNotNull(sm2);
            Assert.IsTrue(sm2.Size == 220);


            if (File.Exists(filename))
            {
                File.Delete(filename);
            }
        }
Beispiel #7
0
        public void Test_FIX_BUG_GH_14_GH15()
        {
            String filename       = "MyFile.dat";
            String storageName    = "MyStorage";
            String streamName     = "MyStream";
            int    BUFFER_SIZE    = 800 * Mb;
            int    iterationCount = 1;
            int    streamCount    = 3;

            CompoundFile compoundFileInit = new CompoundFile(CFSVersion.Ver_4, CFSConfiguration.Default);

            compoundFileInit.Save(filename);
            compoundFileInit.Close();

            CompoundFile compoundFile = new CompoundFile(filename, CFSUpdateMode.Update, CFSConfiguration.Default);
            CFStorage    st           = compoundFile.RootStorage.AddStorage(storageName);
            byte         b            = 0X0A;

            byte[] buffer = new byte[BUFFER_SIZE];
            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
#if NETCOREAPP
                Array.Fill(buffer, b);
#else
                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = b;
                }
#endif
                CFStream sm = st.AddStream(streamName + streamId);
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    sm.Append(buffer);
                    compoundFile.Commit();
                }
                b++;
            }
            compoundFile.Close();
            buffer = null;

            compoundFile = new CompoundFile(filename, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
            byte[] testBuffer = new byte[100];
            byte   t          = 0x0A;

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, BUFFER_SIZE / 2, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, BUFFER_SIZE - 101, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, 0, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                t++;
            }

            compoundFile.Close();
        }
Beispiel #8
0
        /// <summary>
        ///     Creates this object and sets all it's properties
        /// </summary>
        internal Message()
        {
            CompoundFile = new CompoundFile();

            // In the preceding figure, the "__nameid_version1.0" named property mapping storage contains the 
            // three streams  used to provide a mapping from property ID to property name 
            // ("__substg1.0_00020102", "__substg1.0_00030102", and "__substg1.0_00040102") and various other 
            // streams that provide a mapping from property names to property IDs.
            _nameIdStorage = CompoundFile.RootStorage.TryGetStorage(PropertyTags.NameIdStorage) ??
                             CompoundFile.RootStorage.AddStorage(PropertyTags.NameIdStorage);

            var entryStream = _nameIdStorage.AddStream(PropertyTags.EntryStream);
            entryStream.SetData(new byte[0]);
            var stringStream = _nameIdStorage.AddStream(PropertyTags.StringStream);
            stringStream.SetData(new byte[0]);
            var guidStream = _nameIdStorage.AddStream(PropertyTags.GuidStream);
            guidStream.SetData(new byte[0]);
        }
Beispiel #9
0
        /// <summary>
        ///     Creates this object and reads all the <see cref="EntryStreamItem" /> objects from
        ///     the given <paramref name="storage"/>
        /// </summary>
        /// <param name="storage">The <see cref="CFStorage"/> that containts the <see cref="PropertyTags.EntryStream"/></param>
        internal EntryStream(CFStorage storage)
        {
            var stream = storage.TryGetStream(PropertyTags.EntryStream) ?? storage.AddStream(PropertyTags.EntryStream);

            using (var memoryStream = new MemoryStream(stream.GetData()))
                using (var binaryReader = new BinaryReader(memoryStream))
                    while (!binaryReader.Eos())
                    {
                        var entryStreamItem = new EntryStreamItem(binaryReader);
                        Add(entryStreamItem);
                    }
        }
Beispiel #10
0
        internal void Write(CFStorage storage, string streamName)
        {
            var stream = storage.TryGetStream(streamName) ?? storage.AddStream(streamName);

            using (var memoryStream = new MemoryStream())
                using (var binaryWriter = new BinaryWriter(memoryStream))
                {
                    foreach (var entryStreamItem in this)
                    {
                        entryStreamItem.Write(binaryWriter);
                    }

                    stream.SetData(memoryStream.ToArray());
                }
        }
        public void Test_FIX_BUG_GH_14()
        {
            String filename       = "MyFile.dat";
            String storageName    = "MyStorage";
            String streamName     = "MyStream";
            int    BUFFER_SIZE    = 800 * Mb;
            int    iterationCount = 3;
            int    streamCount    = 3;

            CompoundFile compoundFileInit = new CompoundFile(CFSVersion.Ver_4, CFSConfiguration.Default);

            compoundFileInit.Save(filename);
            compoundFileInit.Close();

            CompoundFile compoundFile = new CompoundFile(filename, CFSUpdateMode.Update, CFSConfiguration.Default);
            CFStorage    st           = compoundFile.RootStorage.AddStorage(storageName);
            byte         b            = 0X0A;

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                CFStream sm = st.AddStream(streamName + streamId);
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    sm.Append(Helpers.GetBuffer(BUFFER_SIZE, b));
                    compoundFile.Commit();
                }

                b++;
            }
            compoundFile.Close();

            compoundFile = new CompoundFile(filename, CFSUpdateMode.ReadOnly, CFSConfiguration.Default);
            byte[] testBuffer = new byte[100];
            byte   t          = 0x0A;

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, BUFFER_SIZE / 2, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, BUFFER_SIZE - 101, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + streamId).Read(testBuffer, 0, 100);
                Assert.IsTrue(testBuffer.All(g => g == t));
                t++;
            }

            compoundFile.Close();
        }
Beispiel #12
0
 private void CopyStorage(CFStorage source, CFStorage dest)
 {
     source.VisitEntries(i =>
     {
         if (i.IsStorage)
         {
             CopyStorage((CFStorage)i, dest.AddStorage(i.Name));
         }
         else if (i.IsStream)
         {
             var newStream  = dest.AddStream(i.Name);
             var currStream = (CFStream)i;
             newStream.SetData(currStream.GetData());
         }
     }, false);
 }
Beispiel #13
0
 static void CopyCfStreamsExcept(CFStorage src, CFStorage dest, string excludeName)
 {
     src.VisitEntries(i => {
         if (i.Name?.Equals(excludeName, StringComparison.InvariantCultureIgnoreCase) ?? false)
         {
             return;
         }
         if (i.IsStorage)
         {
             dest.AddStorage(i.Name);
             CopyCfStreamsExcept((CFStorage)i, dest.GetStorage(i.Name), null);
         }
         else
         {
             dest.AddStream(i.Name);
             dest.GetStream(i.Name).SetData(((CFStream)i).GetData());
         }
     }, false);
 }
Beispiel #14
0
        /// <summary>
        /// Добавить поток с указанными зашифрованными данными в указанный каталог файла MCDF.
        /// </summary>
        /// <param name="dir">Каталог, в который необходимо добавить поток</param>
        /// <param name="data">Данные в виде массива байт</param>
        /// <param name="diskKey">Ключ</param>
        /// <param name="diskTable">Таблица</param>
        /// <returns></returns>
        private static CFStream AddStream(CFStorage dir, byte[] data, byte[] diskKey, byte[] diskTable)
        {
            // сгенерировать синхропосылку
            byte[] synchroArr = GenerateSynchro();
            byte[] imito;
            // зашифровать данные и получить от них хеш
            Mathdll.CryptData(diskKey, diskTable, synchroArr, ref data, out imito);
            // создать поток с именем, являющимся 16-тиричным представлением массива байт - imito
            CFStream stream = dir.AddStream(ReadKey.BinToHex(imito));

            // создать бефер для объединения данных и синхропосылки
            byte[] buffer = new byte[data.Length + synchroArr.Length];
            Array.Copy(data, 0, buffer, 0, data.Length);
            Array.Copy(synchroArr, 0, buffer, data.Length, synchroArr.Length);
            // записать данные в поток
            stream.SetData(buffer);
            //
            return(stream);
        }
Beispiel #15
0
 /// <summary>
 /// Returns the complete tree with all the <see cref="CFStorage"/> and <see cref="CFStream"/> children
 /// </summary>
 /// <param name="rootStorage"></param>
 /// <param name="storage"></param>
 private static void GetStorageChain(CFStorage rootStorage, CFStorage storage)
 {
     foreach (var child in storage.Children)
     {
         if (child.IsStorage)
         {
             var newRootStorage = rootStorage.AddStorage(child.Name);
             GetStorageChain(newRootStorage, child as CFStorage);
         }
         else if (child.IsStream)
         {
             var childStream = child as CFStream;
             if (childStream == null)
             {
                 continue;
             }
             var stream = rootStorage.AddStream(child.Name);
             var bytes  = childStream.GetData();
             stream.SetData(bytes);
         }
     }
 }
        public void Test_FIX_BUG_GH_15()
        {
            String filename       = "MyFile.dat";
            String storageName    = "MyStorage";
            String streamName     = "MyStream";
            int    BUFFER_SIZE    = 800 * Mb;
            int    iterationCount = 6;
            int    streamCount    = 1;

            CompoundFile compoundFile = new CompoundFile(CFSVersion.Ver_4, CFSConfiguration.Default);
            CFStorage    st           = compoundFile.RootStorage.AddStorage(storageName);

            for (int streamId = 0; streamId < streamCount; ++streamId)
            {
                CFStream sm = st.AddStream(streamName + streamId);
                for (int iteration = 0; iteration < iterationCount; ++iteration)
                {
                    byte b = (byte)(0x0A + iteration);
                    sm.Append(Helpers.GetBuffer(BUFFER_SIZE, b));
                }
            }
            compoundFile.Save(filename);
            compoundFile.Close();

            byte[] readBuffer = new byte[15];
            compoundFile = new CompoundFile(filename);

            byte c = 0x0A;

            for (int i = 0; i < iterationCount; i++)
            {
                compoundFile.RootStorage.GetStorage(storageName).GetStream(streamName + 0.ToString()).Read(readBuffer, ((long)BUFFER_SIZE + ((long)BUFFER_SIZE * i)) - 15, 15);
                Assert.IsTrue(readBuffer.All(by => by == c));
                c++;
            }

            compoundFile.Close();
        }
 /// <summary>
 /// Copies the given <paramref name="source"/> to the given <paramref name="destination"/>
 /// </summary>
 /// <param name="source"></param>
 /// <param name="destination"></param>
 public static void Copy(CFStorage source, CFStorage destination)
 {
     source.VisitEntries(action =>
     {
         if (action.IsStorage)
         {
             var destionationStorage          = destination.AddStorage(action.Name);
             destionationStorage.CLSID        = action.CLSID;
             destionationStorage.CreationDate = action.CreationDate;
             destionationStorage.ModifyDate   = action.ModifyDate;
             Copy(action as CFStorage, destionationStorage);
         }
         else
         {
             var sourceStream      = action as CFStream;
             var destinationStream = destination.AddStream(action.Name);
             if (sourceStream != null)
             {
                 destinationStream.SetData(sourceStream.GetData());
             }
         }
     }, false);
 }
Beispiel #18
0
        private void SingleWriteReadMatchingSTREAMED(int size)
        {
            MemoryStream ms = new MemoryStream(size);

            CompoundFile cf = new CompoundFile();
            CFStorage    st = cf.RootStorage.AddStorage("MyStorage");
            CFStream     sm = st.AddStream("MyStream");

            byte[] b = Helpers.GetBuffer(size);

            sm.SetData(b);
            cf.Save(ms);
            cf.Close();

            CompoundFile cf2 = new CompoundFile(ms);
            CFStorage    st2 = cf2.RootStorage.GetStorage("MyStorage");
            CFStream     sm2 = st2.GetStream("MyStream");

            Assert.IsNotNull(sm2);
            Assert.IsTrue(sm2.Size == size);
            Assert.IsTrue(Helpers.CompareBuffer(sm2.GetData(), b));

            cf2.Close();
        }
Beispiel #19
0
        /// <summary>
        /// Returns the complete tree with all the <see cref="CFStorage"/> and <see cref="CFStream"/> children
        /// </summary>
        /// <param name="rootStorage"></param>
        /// <param name="storage"></param>
        private static void GetStorageChain(CFStorage rootStorage, CFStorage storage)
        {
            Action <CFItem> entries = item =>
            {
                if (item.IsStorage)
                {
                    var newRootStorage = rootStorage.AddStorage(item.Name);
                    GetStorageChain(newRootStorage, item as CFStorage);
                }
                else if (item.IsStream)
                {
                    var childStream = item as CFStream;
                    if (childStream == null)
                    {
                        return;
                    }
                    var stream = rootStorage.AddStream(item.Name);
                    var bytes  = childStream.GetData();
                    stream.SetData(bytes);
                }
            };

            storage.VisitEntries(entries, false);
        }
Beispiel #20
0
        /// <summary>
        /// Получить ссылку на объект контейнера с заполненными данными
        /// </summary>
        /// <param name="mapXml">Карта</param>
        /// <param name="szv3Xml">Сводная ведомость</param>
        /// <param name="szv2XmlArray">Описи пакетов</param>
        /// <param name="szv1XmlArray">Документы СЗВ-1</param>
        /// <param name="diskKey">Ключ</param>
        /// <param name="diskTable">Таблица</param>
        /// <returns></returns>
        public static CompoundFile MakeContainer(XmlDocument mapXml, XmlDocument szv3Xml,
                                                 IEnumerable <XmlDocument> szv2XmlArray,
                                                 IEnumerable <IEnumerable <XmlDocument> > szv1XmlArray,
                                                 byte[] diskKey, byte[] diskTable)
        {
            XmlElement  rootMap     = mapXml[MapXml.tagTopics];
            XmlElement  svodRootMap = rootMap[MapXml.tagSvod];
            XmlNodeList lists       = rootMap.GetElementsByTagName(MapXml.tagTopics);

            if (lists.Count != szv2XmlArray.Count() || lists.Count != szv1XmlArray.Count())
            {
                return(null);
            }

            CompoundFile container = new CompoundFile(CFSVersion.Ver_3, false, false);
            CFStorage    dir4      = container.RootStorage.AddStorage(rootMap.GetAttribute(MapXml.paramID));

            for (int i = 0; i < szv2XmlArray.Count(); i++)
            {
                XmlElement  curList = lists[i] as XmlElement;
                XmlElement  curOpis = curList[MapXml.tagOpis];
                CFStorage   curDir  = dir4.AddStorage(curList.GetAttribute(MapXml.paramID));
                XmlDocument szv2Xml = szv2XmlArray.ElementAt(i);

                CFStream opisStream = AddStream(curDir, szv2Xml, diskKey, diskTable);
                curOpis[MapXml.tagFilename].InnerText = opisStream.Name;

                XmlNodeList docs = curList.GetElementsByTagName(MapXml.tagTopic);
                if (docs.Count != szv1XmlArray.ElementAt(i).Count())
                {
                    continue;
                }

                for (int j = 0; j < szv1XmlArray.ElementAt(i).Count(); j++)
                {
                    /*if (i >= 10 && j >= 51)
                     * {
                     *  Console.WriteLine("Packet {0}, Doc {1}", i, j);
                     * }*/
                    XmlDocument szv1Xml   = szv1XmlArray.ElementAt(i).ElementAt(j);
                    XmlElement  curDoc    = docs[j] as XmlElement;
                    CFStream    docStream = AddStream(curDir, szv1Xml, diskKey, diskTable);
                    curDoc[MapXml.tagFilename].InnerText = docStream.Name;
                }
            }


            CFStream svod = AddStream(dir4, szv3Xml, diskKey, diskTable);

            svodRootMap[MapXml.tagFilename].InnerText = svod.Name;

            CFStream map = container.RootStorage.AddStream("map");

            SetDataToStream(map, mapXml.InnerXml, diskKey, diskTable);

            CFStorage styleDir        = container.RootStorage.AddStorage("styles");
            CFStream  mapStyleStream  = styleDir.AddStream("map_style");
            CFStream  szv1StyleStream = styleDir.AddStream("szv_style");
            CFStream  szv3StyleStream = styleDir.AddStream("svod_style");
            CFStream  szv2StyleStream = styleDir.AddStream("szv_opis_style");

            SetDataToStream(mapStyleStream, File.ReadAllBytes(MapXml.GetXslUrl()), diskKey, diskTable);
            SetDataToStream(szv1StyleStream, File.ReadAllBytes(Szv1Xml.GetXslUrl()), diskKey, diskTable);
            SetDataToStream(szv3StyleStream, File.ReadAllBytes(Szv3Xml.GetXslUrl()), diskKey, diskTable);
            SetDataToStream(szv2StyleStream, File.ReadAllBytes(Szv2Xml.GetXslUrl()), diskKey, diskTable);
            return(container);
        }
Beispiel #21
0
        public static CFStream GetOrAddStream(this CFStorage storage, string streamName)
        {
            if (storage == null)
            {
                throw new ArgumentNullException(nameof(storage));
            }

            return(storage.TryGetStream(streamName, out var childStream) ? childStream : storage.AddStream(streamName));
        }
Beispiel #22
0
        /// <summary>
        ///     Writes all <see cref="Property">properties</see> either as a <see cref="CFStream"/> or as a collection in
        ///     a <see cref="PropertyTags.PropertiesStreamName"/> stream to the given <paramref name="storage"/>, this depends
        ///     on the <see cref="PropertyType"/>
        /// </summary>
        /// <param name="storage">The <see cref="CFStorage"/></param>
        /// <param name="binaryWriter">The <see cref="BinaryWriter" /></param>
        /// <param name="messageSize">Used to calculate the exact size of the <see cref="Message"/></param>
        /// <returns>
        ///     Total size of the written <see cref="Properties"/>
        /// </returns>
        internal long WriteProperties(CFStorage storage, BinaryWriter binaryWriter, long?messageSize = null)
        {
            long size = 0;

            // The data inside the property stream (1) MUST be an array of 16-byte entries. The number of properties,
            // each represented by one entry, can be determined by first measuring the size of the property stream (1),
            // then subtracting the size of the header from it, and then dividing the result by the size of one entry.
            // The structure of each entry, representing one property, depends on whether the property is a fixed length
            // property or not.
            foreach (var property in this)
            {
                // property tag: A 32-bit value that contains a property type and a property ID. The low-order 16 bits
                // represent the property type. The high-order 16 bits represent the property ID.
                binaryWriter.Write(Convert.ToUInt16(property.Type));  // 2 bytes
                binaryWriter.Write(Convert.ToUInt16(property.Id));    // 2 bytes
                binaryWriter.Write(Convert.ToUInt32(property.Flags)); // 4 bytes

                switch (property.Type)
                {
                //case PropertyType.PT_ACTIONS:
                //    break;

                case PropertyType.PT_APPTIME:
                case PropertyType.PT_SYSTIME:
                case PropertyType.PT_DOUBLE:
                case PropertyType.PT_I8:
                    binaryWriter.Write(property.Data);
                    break;

                case PropertyType.PT_ERROR:
                case PropertyType.PT_LONG:
                case PropertyType.PT_FLOAT:
                    binaryWriter.Write(property.Data);
                    binaryWriter.Write(new byte[4]);
                    break;

                case PropertyType.PT_SHORT:
                    binaryWriter.Write(property.Data);
                    binaryWriter.Write(new byte[6]);
                    break;

                case PropertyType.PT_BOOLEAN:
                    binaryWriter.Write(property.Data);
                    binaryWriter.Write(new byte[7]);
                    break;

                //case PropertyType.PT_CURRENCY:
                //    binaryWriter.Write(property.Data);
                //    break;

                case PropertyType.PT_UNICODE:
                    // Write the length of the property to the propertiesstream
                    binaryWriter.Write(property.Data.Length + 2);
                    binaryWriter.Write(new byte[4]);
                    storage.AddStream(property.Name).SetData(property.Data);
                    size += property.Data.LongLength;
                    break;

                case PropertyType.PT_STRING8:
                    // Write the length of the property to the propertiesstream
                    binaryWriter.Write(property.Data.Length + 1);
                    binaryWriter.Write(new byte[4]);
                    storage.AddStream(property.Name).SetData(property.Data);
                    size += property.Data.LongLength;
                    break;

                case PropertyType.PT_CLSID:
                    binaryWriter.Write(property.Data);
                    break;

                //case PropertyType.PT_SVREID:
                //    break;

                //case PropertyType.PT_SRESTRICT:
                //    storage.AddStream(property.Name).SetData(property.Data);
                //    break;

                case PropertyType.PT_BINARY:
                    // Write the length of the property to the propertiesstream
                    binaryWriter.Write(property.Data.Length);
                    binaryWriter.Write(new byte[4]);
                    storage.AddStream(property.Name).SetData(property.Data);
                    size += property.Data.LongLength;
                    break;

                case PropertyType.PT_MV_SHORT:
                    break;

                case PropertyType.PT_MV_LONG:
                    break;

                case PropertyType.PT_MV_FLOAT:
                    break;

                case PropertyType.PT_MV_DOUBLE:
                    break;

                case PropertyType.PT_MV_CURRENCY:
                    break;

                case PropertyType.PT_MV_APPTIME:
                    break;

                case PropertyType.PT_MV_LONGLONG:
                    break;

                case PropertyType.PT_MV_UNICODE:
                    // PropertyType.PT_MV_TSTRING
                    break;

                case PropertyType.PT_MV_STRING8:
                    break;

                case PropertyType.PT_MV_SYSTIME:
                    break;

                //case PropertyType.PT_MV_CLSID:
                //    break;

                case PropertyType.PT_MV_BINARY:
                    break;

                case PropertyType.PT_UNSPECIFIED:
                    break;

                case PropertyType.PT_NULL:
                    break;

                case PropertyType.PT_OBJECT:
                    // TODO: Adding new MSG file
                    break;
                }
            }

            if (messageSize.HasValue)
            {
                binaryWriter.Write(Convert.ToUInt16(PropertyTags.PR_MESSAGE_SIZE.Type));                                 // 2 bytes
                binaryWriter.Write(Convert.ToUInt16(PropertyTags.PR_MESSAGE_SIZE.Id));                                   // 2 bytes
                binaryWriter.Write(Convert.ToUInt32(PropertyFlags.PROPATTR_READABLE | PropertyFlags.PROPATTR_WRITABLE)); // 4 bytes
                var totalSize = messageSize.Value + size + 8;
                var bytes     = BitConverter.GetBytes(totalSize);
                binaryWriter.Write(bytes);
                binaryWriter.Write(new byte[4]);
            }

            // Make the properties stream
            binaryWriter.BaseStream.Position = 0;
            var propertiesStream = storage.TryGetStream(PropertyTags.PropertiesStreamName) ?? storage.AddStream(PropertyTags.PropertiesStreamName);

            propertiesStream.SetData(binaryWriter.BaseStream.ToByteArray());
            return(size + binaryWriter.BaseStream.Length);
        }
Beispiel #23
0
 /// <summary>
 /// Returns the complete tree with all the <see cref="CFStorage"/> and <see cref="CFStream"/> children
 /// </summary>
 /// <param name="rootStorage"></param>
 /// <param name="storage"></param>
 private static void GetStorageChain(CFStorage rootStorage, CFStorage storage)
 {
     foreach (var child in storage.Children)
     {
         if (child.IsStorage)
         {
             var newRootStorage = rootStorage.AddStorage(child.Name);
             GetStorageChain(newRootStorage, child as CFStorage);
         }
         else if (child.IsStream)
         {
             var childStream = child as CFStream;
             if (childStream == null) continue;
             var stream = rootStorage.AddStream(child.Name);
             var bytes = childStream.GetData();
             stream.SetData(bytes);
         }
     }
 }
        public void WriteData(CFStorage gameStorage, HashWriter hashWriter = null)
        {
            var itemData = gameStorage.AddStream(StorageName);

            itemData.SetData(GetBytes(hashWriter));
        }
Beispiel #25
0
 private static void WriteStream(CFStorage storage, string streamName, byte[] data, HashWriter hashWriter = null)
 {
     storage.AddStream(streamName).SetData(data);
     hashWriter?.Write(data);
 }
Beispiel #26
0
        private void AddStreamToStorage(CFStorage storage, CFStream stream)
        {
            CFStream cfStream = storage.AddStream(stream.Name);

            cfStream.SetData(stream.GetData());
        }