示例#1
0
        public virtual WzooBlock ParseBlock(MemoryStream ms)
        {
            if (ms.Position == ms.Length)
            {
                return(null);
            }

            var sizeBuffer = new byte[4];

            var block = new WzooBlock();

            ms.Read(sizeBuffer, 0, 4);
            block.BlockLength = BigEndian.ToInt32(sizeBuffer, 0);

            ms.Read(sizeBuffer, 0, 4);
            block.BlockVersion = BigEndian.ToInt32(sizeBuffer, 0);

            ms.Read(block.DeviceType, 0, 12);
            ms.Read(block.ConfigType, 0, 4);

            var dataLength = block.BlockLength - 24;

            block.BlockData = new byte[dataLength];
            ms.Read(block.BlockData, 0, dataLength);

            return(block);
        }
示例#2
0
        public MagicBlock ParseMagicBlock(WzooBlock block)
        {
            var magicBlock = new MagicBlock();

            if (BlockMagic.Length != 4)
            {
                throw new Exception(
                          $"the block magic was expected to be 4 bytes in length, found a length of {BlockMagic.Length}");
            }

            magicBlock.BlockMagic = BlockMagic;

            using (var ms = new MemoryStream(block.BlockData))
            {
                if (!ContainsMagicBlock(block))
                {
                    // Block without magic
                    magicBlock.IsMagicBlock = false;
                    ms.Seek(32, SeekOrigin.Begin);

                    var blockDataLength = block.BlockData.Length - 32;

                    magicBlock.BlockData = new byte[blockDataLength];
                    ms.Read(magicBlock.BlockData, 0, blockDataLength);
                }
                else
                {
                    ms.Seek(36, SeekOrigin.Begin);

                    var pluginNameLengthBuffer = new byte[4];
                    ms.Read(pluginNameLengthBuffer, 0, 4);
                    var pluginNameLength = BigEndian.ToInt32(pluginNameLengthBuffer, 0);

                    magicBlock.PluginName = new byte[pluginNameLength];

                    ms.Read(magicBlock.PluginName, 0, pluginNameLength);

                    var blockDataLength = block.BlockData.Length - 4 - pluginNameLength - 36;

                    magicBlock.BlockData = new byte[blockDataLength];
                    ms.Read(magicBlock.BlockData, 0, blockDataLength);
                }
            }

            return(magicBlock);
        }
示例#3
0
        public bool ContainsMagicBlock(WzooBlock block)
        {
            using (var ms = new MemoryStream(block.BlockData))
            {
                var emptyBuffer = new byte[4];
                var empty       = new byte[] { 0xDE, 0xAD, 0xBE, 0xEF };

                ms.Seek(-4, SeekOrigin.End);

                ms.Read(emptyBuffer, 0, 4);

                if (!emptyBuffer.SequenceEqual(empty))
                {
                    return(false);
                }
            }

            return(true);
        }