Beispiel #1
0
        static internal V8DataElement Create(V8ItemHandle handle)
        {
            using (var DataStream = handle.Container.GetDataStream(handle))
            {
                byte[] data = new byte[DataStream.Length];
                DataStream.Read(data, 0, data.Length);
                DataStream.Position = 0;

                if (DataStream.Length >= sizeof(UInt32))
                {
                    byte[] signature = new byte[] { 0xff, 0xff, 0xff, 0x7f };

                    //var strReader = new BinaryReader(DataStream);
                    //UInt32 signature = strReader.ReadUInt32();

                    if (ArrayStartsWith(data, signature))
                    {
                        // Это правильный заголовок блока, значит, данные - несжатый cf-файл.
                        return(new V8ContainerElement(handle, data));
                    }
                    else
                    {
                        // Это сырые данные
                        return(new V8DataElement(handle, data));
                    }
                }
                else
                {
                    // Это сырые данные
                    return(new V8DataElement(handle));
                }
            }
        }
Beispiel #2
0
        internal override Stream GetDataStream(V8ItemHandle Handle)
        {
            MemoryStream resultStream = new MemoryStream();

            using (var ReadStream = base.GetDataStream(Handle))
            {
                using (var DeflateStream = new System.IO.Compression.DeflateStream(ReadStream, System.IO.Compression.CompressionMode.Decompress))
                {
                    DeflateStream.CopyTo(resultStream);
                }
            }

            resultStream.Position = 0;
            return(resultStream);
        }
Beispiel #3
0
        internal virtual Stream GetDataStream(V8ItemHandle Handle)
        {
            if (Handle.Container != this)
            {
                throw new ArgumentException("Handle does not belong to an image");
            }

            if (Handle.Length == 0)
            {
                return(new MemoryStream());
            }

            byte[] buffer = ReadChunkedBlock((int)Handle.Offset);

            var ItemStream = new MemoryStream(buffer);

            return(ItemStream);
        }
Beispiel #4
0
        private void FillDataItems()
        {
            m_ItemsMap = new Dictionary <string, V8ItemHandle>();

            int startAddr = stFileHeader.Size;

            stElemAddr[] toc = ReadTableOfContents(startAddr);

            unsafe
            {
                for (int i = 0; i < toc.Length; i++)
                {
                    var tocItem = toc[i];

                    stBlockHeader itemHdr = MemReadStruct <stBlockHeader>((int)tocItem.elem_header_addr);
                    if (!itemHdr.Check())
                    {
                        throw new V8WrongFileException();
                    }

                    int titleSize  = (int)Helpers.FromHexStr((sbyte *)itemHdr.data_size_hex);
                    int titleDelta = (int)stBlockHeader.Size + stElemHeaderPrefix.Size;
                    int nameSize   = titleSize - stElemHeaderPrefix.Size - 4;

                    byte[] arr = new byte[nameSize];
                    MemReadFrom((int)tocItem.elem_header_addr + titleDelta, nameSize, ref arr);

                    string itemName;
                    fixed(byte *ptr = arr)
                    {
                        itemName = new string((sbyte *)ptr, 0, (int)nameSize, Encoding.Unicode);
                    }

                    V8ItemHandle itemHandle = new V8ItemHandle();
                    itemHandle.Container = this;
                    itemHandle.Name      = itemName;

                    if (tocItem.elem_data_addr != 0x7fffffff)
                    {
                        // длина тела данных
                        itemHdr = MemReadStruct <stBlockHeader>((int)tocItem.elem_data_addr);
                        if (!itemHdr.Check())
                        {
                            throw new V8WrongFileException();
                        }

                        uint BodySize = Helpers.FromHexStr((sbyte *)itemHdr.data_size_hex);

                        itemHandle.Offset = tocItem.elem_data_addr;
                        itemHandle.Length = BodySize;
                    }
                    else
                    {
                        itemHandle.Offset = 0;
                        itemHandle.Length = 0;
                    }

                    m_ItemsMap.Add(itemName, itemHandle);
                }
            }
        }
Beispiel #5
0
 internal V8ContainerElement(V8ItemHandle handle, byte[] data) : base(handle, data)
 {
     m_ParentContainer = handle.Container;
     m_FoldedImage     = new V8Image(m_ParentContainer.GetDataStream(handle));
 }
Beispiel #6
0
 internal V8ContainerElement(V8ItemHandle handle) : this(handle, null)
 {
 }
Beispiel #7
0
 internal V8DataElement(V8ItemHandle handle, byte[] data)
 {
     m_handle = handle;
     m_data   = data;
 }
Beispiel #8
0
 internal V8DataElement(V8ItemHandle handle) : this(handle, null)
 {
 }