Example #1
0
        public void ReadFrom(BinaryReader reader)
        {
            var readerOffset = reader.BaseStream.Position;

            LinkInfoSize       = reader.ReadInt32();
            LinkInfoHeaderSize = reader.ReadInt32();
            FormatChecker.CheckExpression(() => LinkInfoHeaderSize < LinkInfoSize);

            Item.LinkInfoFlags = (LinkInfoFlags)(reader.ReadInt32());

            VolumeIDOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => VolumeIDOffset < LinkInfoSize);

            LocalBasePathOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => LocalBasePathOffset < LinkInfoSize);

            CommonNetworkRelativeLinkOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => CommonNetworkRelativeLinkOffset < LinkInfoSize);

            CommonPathSuffixOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => CommonPathSuffixOffset < LinkInfoSize);

            if (LinkInfoHeaderSize > MinimumLinkInfoHeaderSize)
            {
                LocalBasePathOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => LocalBasePathOffsetUnicode < LinkInfoSize);

                CommonPathSuffixOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => CommonPathSuffixOffsetUnicode < LinkInfoSize);
            }
            else
            {
                FormatChecker.CheckExpression(() => LinkInfoHeaderSize == MinimumLinkInfoHeaderSize);
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                EnsurePosition(reader, readerOffset, VolumeIDOffset);
                Item.VolumeID = new VolumeID();
                var vidReader = new VolumeIDHandler(Item.VolumeID);
                vidReader.ReadFrom(reader);
                Item.LocalBasePath = reader.ReadASCIIZ(readerOffset, LocalBasePathOffset, LocalBasePathOffsetUnicode);
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                EnsurePosition(reader, readerOffset, CommonNetworkRelativeLinkOffset);
                Item.CommonNetworkRelativeLink = new CommonNetworkRelativeLink();
                var cnrlReader = new CommonNetworkRelativeLinkHandler(Item.CommonNetworkRelativeLink);
                cnrlReader.ReadFrom(reader);
            }

            Item.CommonPathSuffix = reader.ReadASCIIZ(readerOffset, CommonPathSuffixOffset, CommonPathSuffixOffsetUnicode);
        }
Example #2
0
        public void WriteTo(System.IO.BinaryWriter writer)
        {
            byte[] padding = new byte[]{};

            LinkInfoHeaderSize = Marshal.SizeOf(LinkInfoSize) +
            Marshal.SizeOf(LinkInfoHeaderSize) +
            Marshal.SizeOf(typeof(int)) +
            Marshal.SizeOf(VolumeIDOffset) +
            Marshal.SizeOf(LocalBasePathOffset) +
            Marshal.SizeOf(CommonNetworkRelativeLinkOffset) +
            Marshal.SizeOf(CommonPathSuffixOffset);

            LinkInfoSize = LinkInfoHeaderSize + Encoding.Default.GetASCIIZSize(Item.CommonPathSuffix);

            VolumeIDHandler vidWriter = null;
            CommonNetworkRelativeLinkHandler cnrWriter = null;

            VolumeIDOffset = 0;
            LocalBasePathOffset = 0;
            CommonNetworkRelativeLinkOffset = 0;
            int nextBlockOffset = LinkInfoHeaderSize;

            if ((Item.LinkInfoFlags & (LinkInfoFlags.VolumeIDAndLocalBasePath | LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix)) == (LinkInfoFlags.VolumeIDAndLocalBasePath | LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix))
            {
                padding = new byte[] {0};
                LinkInfoSize += padding.Length;
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                vidWriter = new VolumeIDHandler(Item.VolumeID);
                LinkInfoSize += vidWriter.ComputedSize + Encoding.Default.GetASCIIZSize(Item.LocalBasePath);
                VolumeIDOffset = nextBlockOffset;
                LocalBasePathOffset = VolumeIDOffset + vidWriter.ComputedSize;
                CommonPathSuffixOffset = LocalBasePathOffset + Encoding.Default.GetASCIIZSize(Item.LocalBasePath);
                nextBlockOffset = CommonPathSuffixOffset + padding.Length;
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                cnrWriter = new CommonNetworkRelativeLinkHandler(Item.CommonNetworkRelativeLink);
                LinkInfoSize += cnrWriter.ComputedSize;
                CommonNetworkRelativeLinkOffset = nextBlockOffset;
                CommonPathSuffixOffset = CommonNetworkRelativeLinkOffset + cnrWriter.ComputedSize;
            }

            writer.Write(LinkInfoSize);
            writer.Write(LinkInfoHeaderSize);
            writer.Write((int)Item.LinkInfoFlags);

            writer.Write(VolumeIDOffset);
            writer.Write(LocalBasePathOffset);
            writer.Write(CommonNetworkRelativeLinkOffset);
            writer.Write(CommonPathSuffixOffset);

            // TODO: Handle unicode strings and offsets
            // LocalBasePathOffsetUnicode =
            // CommonPathSuffixOffsetUnicode =
            // LinkInfoHeaderSize >= &H24

            if (vidWriter != null)
            {
                vidWriter.WriteTo(writer);
                writer.WriteASCIIZ(Item.LocalBasePath, Encoding.Default);
            }
            if (padding.Length > 0)
            {
                writer.Write(padding);
            }
            if (cnrWriter != null)
            {
                cnrWriter.WriteTo(writer);
            }
            writer.WriteASCIIZ(Item.CommonPathSuffix, Encoding.Default);
        }
Example #3
0
        public void WriteTo(BinaryWriter writer)
        {
            var padding = new byte[] { };

            LinkInfoHeaderSize = Marshal.SizeOf(LinkInfoSize) +
                                 Marshal.SizeOf(LinkInfoHeaderSize) +
                                 Marshal.SizeOf(typeof(int)) +
                                 Marshal.SizeOf(VolumeIDOffset) +
                                 Marshal.SizeOf(LocalBasePathOffset) +
                                 Marshal.SizeOf(CommonNetworkRelativeLinkOffset) +
                                 Marshal.SizeOf(CommonPathSuffixOffset);

            LinkInfoSize = LinkInfoHeaderSize + Encoding.Default.GetASCIIZSize(Item.CommonPathSuffix);

            VolumeIDHandler vidWriter = null;
            CommonNetworkRelativeLinkHandler cnrWriter = null;

            VolumeIDOffset                  = 0;
            LocalBasePathOffset             = 0;
            CommonNetworkRelativeLinkOffset = 0;
            var nextBlockOffset = LinkInfoHeaderSize;

            if ((Item.LinkInfoFlags & (LinkInfoFlags.VolumeIDAndLocalBasePath | LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix)) == (LinkInfoFlags.VolumeIDAndLocalBasePath | LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix))
            {
                padding       = new byte[] { 0 };
                LinkInfoSize += padding.Length;
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                vidWriter              = new VolumeIDHandler(Item.VolumeID);
                LinkInfoSize          += vidWriter.ComputedSize + Encoding.Default.GetASCIIZSize(Item.LocalBasePath);
                VolumeIDOffset         = nextBlockOffset;
                LocalBasePathOffset    = VolumeIDOffset + vidWriter.ComputedSize;
                CommonPathSuffixOffset = LocalBasePathOffset + Encoding.Default.GetASCIIZSize(Item.LocalBasePath);
                nextBlockOffset        = CommonPathSuffixOffset + padding.Length;
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                cnrWriter     = new CommonNetworkRelativeLinkHandler(Item.CommonNetworkRelativeLink);
                LinkInfoSize += cnrWriter.ComputedSize;
                CommonNetworkRelativeLinkOffset = nextBlockOffset;
                CommonPathSuffixOffset          = CommonNetworkRelativeLinkOffset + cnrWriter.ComputedSize;
            }

            writer.Write(LinkInfoSize);
            writer.Write(LinkInfoHeaderSize);
            writer.Write((int)Item.LinkInfoFlags);

            writer.Write(VolumeIDOffset);
            writer.Write(LocalBasePathOffset);
            writer.Write(CommonNetworkRelativeLinkOffset);
            writer.Write(CommonPathSuffixOffset);

            // TODO: Handle unicode strings and offsets
            // LocalBasePathOffsetUnicode =
            // CommonPathSuffixOffsetUnicode =
            // LinkInfoHeaderSize >= &H24

            if (vidWriter != null)
            {
                vidWriter.WriteTo(writer);
                writer.WriteASCIIZ(Item.LocalBasePath, Encoding.Default);
            }

            if (padding.Length > 0)
            {
                writer.Write(padding);
            }

            cnrWriter?.WriteTo(writer);

            writer.WriteASCIIZ(Item.CommonPathSuffix, Encoding.Default);
        }
Example #4
0
        public void ReadFrom(BinaryReader reader)
        {
            long readerOffset = reader.BaseStream.Position;

            LinkInfoSize = reader.ReadInt32();
            LinkInfoHeaderSize = reader.ReadInt32();
            FormatChecker.CheckExpression(() => LinkInfoHeaderSize < LinkInfoSize);

            Item.LinkInfoFlags = (LinkInfoFlags) (reader.ReadInt32());

            VolumeIDOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => VolumeIDOffset < LinkInfoSize);

            LocalBasePathOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => LocalBasePathOffset < LinkInfoSize);

            CommonNetworkRelativeLinkOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => CommonNetworkRelativeLinkOffset < LinkInfoSize);

            CommonPathSuffixOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => CommonPathSuffixOffset < LinkInfoSize);

            if (LinkInfoHeaderSize > MinimumLinkInfoHeaderSize)
            {
                LocalBasePathOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => LocalBasePathOffsetUnicode < LinkInfoSize);

                CommonPathSuffixOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => CommonPathSuffixOffsetUnicode < LinkInfoSize);
            }
            else
            {
                FormatChecker.CheckExpression(() => LinkInfoHeaderSize == MinimumLinkInfoHeaderSize);
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                EnsurePosition(reader, readerOffset, VolumeIDOffset);
                Item.VolumeID = new VolumeID();
                VolumeIDHandler vidReader = new VolumeIDHandler(Item.VolumeID);
                vidReader.ReadFrom(reader);
                Item.LocalBasePath = reader.ReadASCIIZ(readerOffset, LocalBasePathOffset, LocalBasePathOffsetUnicode);
            }

            if ((Item.LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                EnsurePosition(reader, readerOffset, CommonNetworkRelativeLinkOffset);
                Item.CommonNetworkRelativeLink = new CommonNetworkRelativeLink();
                CommonNetworkRelativeLinkHandler cnrlReader = new CommonNetworkRelativeLinkHandler(Item.CommonNetworkRelativeLink);
                cnrlReader.ReadFrom(reader);
            }

            Item.CommonPathSuffix = reader.ReadASCIIZ(readerOffset, CommonPathSuffixOffset, CommonPathSuffixOffsetUnicode);
        }