예제 #1
0
        public override void WriteTo(BinaryWriter writer)
        {
            base.WriteTo(writer);

            FormatChecker.CheckExpression(() => Item.Value == null || Item.Value.Length < ValueSize);
            FormatChecker.CheckExpression(() => Item.ValueUnicode == null || Item.ValueUnicode.Length < ValueSizeUnicode);
            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);

            writer.WriteASCIIZF(Item.Value, Encoding.Default, ValueSize, Item.ValuePadding);
            writer.WriteASCIIZF(Item.ValueUnicode, Encoding.Unicode, ValueSizeUnicode, Item.ValueUnicodePadding);
        }
예제 #2
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);
        }
예제 #3
0
        public override void ReadFrom(BinaryReader reader)
        {
            base.ReadFrom(reader);

            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);

            Item.Value        = reader.ReadASCIIZF(Encoding.Default, ValueSize, out var padding);
            Item.ValuePadding = padding;

            Item.ValueUnicode        = reader.ReadASCIIZF(Encoding.Unicode, ValueSizeUnicode, out padding);
            Item.ValueUnicodePadding = padding;
        }
예제 #4
0
        public override void ReadFrom(System.IO.BinaryReader reader)
        {
            base.ReadFrom(reader);

            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);

            Length = reader.ReadInt32();
            FormatChecker.CheckExpression(() => Length >= MinimumLength);

            Item.Version    = reader.ReadInt32();
            Item.MachineID  = reader.ReadASCIIZF(Encoding.Default, MachineIDLength); // 16 bytes, 0 fill
            Item.Droid      = new[] { new Guid(reader.ReadBytes(16)), new Guid(reader.ReadBytes(16)) };
            Item.DroidBirth = new[] { new Guid(reader.ReadBytes(16)), new Guid(reader.ReadBytes(16)) };
        }
        public void ReadFrom(BinaryReader reader)
        {
            var readerOffset = reader.BaseStream.Position;

            CommonNetworkRelativeLinkSize = reader.ReadInt32();
            FormatChecker.CheckExpression(() => CommonNetworkRelativeLinkSize >= MinimumCommonNetworkRelativeLinkSize);

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

            NetNameOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => NetNameOffset < CommonNetworkRelativeLinkSize);

            DeviceNameOffset = reader.ReadInt32();
            FormatChecker.CheckExpression(() => DeviceNameOffset < CommonNetworkRelativeLinkSize);

            var nptvalue = reader.ReadInt32();

            if ((Item.CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidNetType) != 0)
            {
                Item.NetworkProviderType = (NetworkProviderType)(nptvalue);
            }
            else
            {
                Item.NetworkProviderType = null;
            }

            if (NetNameOffset > MinimumCommonNetworkRelativeLinkSize)
            {
                NetNameOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => NetNameOffsetUnicode < CommonNetworkRelativeLinkSize);

                DeviceNameOffsetUnicode = reader.ReadInt32();
                FormatChecker.CheckExpression(() => DeviceNameOffsetUnicode < CommonNetworkRelativeLinkSize);
            }
            else
            {
                FormatChecker.CheckExpression(() => NetNameOffset == MinimumCommonNetworkRelativeLinkSize);
            }

            Item.NetName = reader.ReadASCIIZ(readerOffset, NetNameOffset, NetNameOffsetUnicode);
            if ((Item.CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidDevice) != 0)
            {
                Item.DeviceName = reader.ReadASCIIZ(readerOffset, DeviceNameOffset, DeviceNameOffsetUnicode);
            }
        }
예제 #6
0
        public override void WriteTo(System.IO.BinaryWriter writer)
        {
            base.WriteTo(writer);

            FormatChecker.CheckExpression(() => Item.FaceName == null || Item.FaceName.Length < FaceNameLength);
            FormatChecker.CheckExpression(() => Item.ColorTable != null && Item.ColorTable.Length == ColorTableLength);
            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);

            writer.Write((ushort)Item.FillAttributes);
            writer.Write((ushort)Item.PopupFillAttributes);

            writer.Write((short)Item.ScreenBufferSize.Width);
            writer.Write((short)Item.ScreenBufferSize.Height);
            writer.Write((short)Item.WindowSize.Width);
            writer.Write((short)Item.WindowSize.Height);
            writer.Write((short)Item.WindowOrigin.X);
            writer.Write((short)Item.WindowOrigin.Y);

            writer.Write(new byte[UnusedLength]);

            //writer.Write(Item.FontSize);
            writer.Write((short)0);
            writer.Write((short)Item.FontSize);

            writer.Write((uint)Item.FontFamily);
            writer.Write(Item.FontWeight);

            writer.WriteASCIIZF(Item.FaceName, Encoding.Unicode, FaceNameLength, Item.FaceNamePadding);

            writer.Write(Item.CursorSize);
            writer.Write(Convert.ToInt32(Item.FullScreen));
            writer.Write(Convert.ToInt32(Item.FastEdit));
            writer.Write(Convert.ToInt32(Item.InsertMode));
            writer.Write(Convert.ToInt32(Item.AutoPosition));

            writer.Write(Item.HistoryBufferSize);
            writer.Write(Item.NumberOfHistoryBuffers);
            writer.Write(Convert.ToInt32(Item.HistoryDuplicateAllowed));

            writer.Write(Item.ColorTable);
        }
        public void WriteTo(BinaryWriter writer)
        {
            CommonNetworkRelativeLinkSize = ComputedSize;
            FormatChecker.CheckExpression(() => CommonNetworkRelativeLinkSize >= MinimumCommonNetworkRelativeLinkSize);

            writer.Write(CommonNetworkRelativeLinkSize);
            writer.Write((int)Item.CommonNetworkRelativeLinkFlags);

            NetNameOffset = Marshal.SizeOf(ComputedSize) +
                            Marshal.SizeOf(CommonNetworkRelativeLinkSize) +
                            Marshal.SizeOf(typeof(int)) +
                            Marshal.SizeOf(NetNameOffset) +
                            Marshal.SizeOf(DeviceNameOffset);
            writer.Write(NetNameOffset);

            DeviceNameOffset = (Item.CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidDevice) != 0
                                ? NetNameOffset + Encoding.Default.GetASCIIZSize(Item.NetName)
                                : 0;
            writer.Write(DeviceNameOffset);

            var nptvalue = 0;

            if ((Item.CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidNetType) != 0 &&
                Item.NetworkProviderType != null)
            {
                nptvalue = (int)Item.NetworkProviderType;
            }
            writer.Write(nptvalue);

            // TODO: Handle unicode strings and offsets
            // NetNameOffsetUnicode =
            // DeviceNameOffsetUnicode =
            // NetNameOffset > &H14

            writer.WriteASCIIZ(Item.NetName, Encoding.Default);
            if (DeviceNameOffset > 0)
            {
                writer.WriteASCIIZ(Item.DeviceName, Encoding.Default);
            }
        }
예제 #8
0
        public void ReadFrom(BinaryReader reader)
        {
            HeaderSize = reader.ReadInt32();
            FormatChecker.CheckExpression(() => HeaderSize == ExactHeaderSize);

            Item.Guid = new Guid(reader.ReadBytes(16));
            FormatChecker.CheckExpression(() => Item.Guid.ToString().Equals(ShellLinkHeader.LNKGuid));

            Item.LinkFlags      = (LinkFlags)(reader.ReadInt32());
            Item.FileAttributes = (FileAttributes)(reader.ReadInt32());

            Item.CreationTime = DateTime.FromFileTime(reader.ReadInt64());
            Item.AccessTime   = DateTime.FromFileTime(reader.ReadInt64());
            Item.WriteTime    = DateTime.FromFileTime(reader.ReadInt64());
            Item.FileSize     = reader.ReadInt32();
            Item.IconIndex    = reader.ReadInt32();

            Item.ShowCommand = (ShowCommand)reader.ReadInt32();
            Item.HotKey      = reader.ReadInt16();

            reader.ReadBytes(ReservedSize);             // Reserved
        }
예제 #9
0
        public void ReadFrom(BinaryReader reader)
        {
            var readerOffset = reader.BaseStream.Position;

            VolumeIDSize = reader.ReadInt32();
            FormatChecker.CheckExpression(() => VolumeIDSize > MinimumVolumeIDSize);

            _item.DriveType         = (DriveType)(reader.ReadInt32());
            _item.DriveSerialNumber = reader.ReadInt32();
            VolumeLabelOffset       = reader.ReadInt32();

            if (VolumeLabelOffset > MinimumVolumeIDSize)
            {
                VolumeLabelOffsetUnicode = reader.ReadInt32();
            }
            else
            {
                FormatChecker.CheckExpression(() => VolumeLabelOffset == MinimumVolumeIDSize);
            }

            _item.VolumeLabel = reader.ReadASCIIZ(readerOffset, VolumeLabelOffset, VolumeLabelOffsetUnicode);
        }
예제 #10
0
        public void WriteTo(BinaryWriter writer)
        {
            VolumeIDSize = ComputedSize;

            FormatChecker.CheckExpression(() => VolumeIDSize > MinimumVolumeIDSize);

            writer.Write(VolumeIDSize);
            writer.Write((int)_item.DriveType);
            writer.Write(_item.DriveSerialNumber);

            VolumeLabelOffset = Marshal.SizeOf(VolumeIDSize) +
                                Marshal.SizeOf(typeof(int)) +
                                Marshal.SizeOf(_item.DriveSerialNumber) +
                                Marshal.SizeOf(VolumeLabelOffset);
            writer.Write(VolumeLabelOffset);

            // TODO: Handle unicode strings and offsets
            // VolumeLabelOffsetUnicode =
            // VolumeLabelOffset = &H14

            writer.WriteASCIIZ(_item.VolumeLabel, Encoding.Default);
        }
예제 #11
0
        public override void ReadFrom(System.IO.BinaryReader reader)
        {
            base.ReadFrom(reader);

            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);

            Item.FillAttributes      = (FillAttributes)reader.ReadUInt16();
            Item.PopupFillAttributes = (FillAttributes)reader.ReadUInt16();

            Item.ScreenBufferSize = new Size(reader.ReadInt16(), reader.ReadInt16());
            Item.WindowSize       = new Size(reader.ReadInt16(), reader.ReadInt16());
            Item.WindowOrigin     = new Point(reader.ReadInt16(), reader.ReadInt16());

            reader.ReadBytes(UnusedLength);

            //Item.FontSize = reader.ReadInt32();
            reader.ReadInt16();
            Item.FontSize = reader.ReadInt16();

            Item.FontFamily = (ExtraData.FontFamily)reader.ReadUInt32();
            Item.FontWeight = reader.ReadUInt32();

            // Keep unknown data padding to preserve valid file roundtrip
            byte[] padding;
            Item.FaceName        = reader.ReadASCIIZF(Encoding.Unicode, FaceNameLength, out padding);
            Item.FaceNamePadding = padding;

            Item.CursorSize   = reader.ReadUInt32();
            Item.FullScreen   = reader.ReadUInt32() > 0;
            Item.FastEdit     = reader.ReadUInt32() > 0;
            Item.InsertMode   = reader.ReadUInt32() > 0;
            Item.AutoPosition = reader.ReadUInt32() > 0;

            Item.HistoryBufferSize       = reader.ReadUInt32();
            Item.NumberOfHistoryBuffers  = reader.ReadUInt32();
            Item.HistoryDuplicateAllowed = reader.ReadUInt32() > 0;
            Item.ColorTable = reader.ReadBytes(ColorTableLength);
        }
예제 #12
0
        public override void WriteTo(System.IO.BinaryWriter writer)
        {
            base.WriteTo(writer);

            FormatChecker.CheckExpression(() => Item.MachineID == null || Item.MachineID.Length <= MachineIDLength);
            FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
            FormatChecker.CheckExpression(() => Item.Droid != null && Item.Droid.Length == 2);
            FormatChecker.CheckExpression(() => Item.DroidBirth != null && Item.DroidBirth.Length == 2);

            Length = ComputedSize - base.ComputedSize;
            FormatChecker.CheckExpression(() => Length >= MinimumLength);

            writer.Write(Length);
            writer.Write(Item.Version);
            writer.WriteASCIIZF(Item.MachineID, Encoding.Default, MachineIDLength);
            foreach (var guid in Item.Droid)
            {
                writer.Write(guid.ToByteArray());
            }
            foreach (var guid in Item.DroidBirth)
            {
                writer.Write(guid.ToByteArray());
            }
        }
 protected override void WriteID(System.IO.BinaryWriter writer)
 {
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     writer.Write(Item.KnownFolder.ToByteArray());
 }
 protected override void ReadID(System.IO.BinaryReader reader)
 {
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     Item.KnownFolder = new Guid(reader.ReadBytes(Marshal.SizeOf(Item.KnownFolder)));
 }
 public override void ReadFrom(BinaryReader reader)
 {
     base.ReadFrom(reader);
     FormatChecker.CheckExpression(() => BlockSize >= MinimumBlockSize);
     Item.Raw = reader.ReadBytes(BlockSize - base.ComputedSize);
 }
예제 #16
0
 public override void WriteTo(System.IO.BinaryWriter writer)
 {
     base.WriteTo(writer);
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     writer.Write(Item.CodePage);
 }
예제 #17
0
 public override void ReadFrom(System.IO.BinaryReader reader)
 {
     base.ReadFrom(reader);
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     Item.CodePage = reader.ReadUInt32();
 }
 protected override void WriteID(System.IO.BinaryWriter writer)
 {
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     writer.Write((int)Item.SpecialFolder);
 }
 protected override void ReadID(System.IO.BinaryReader reader)
 {
     FormatChecker.CheckExpression(() => BlockSize == ExactBlockSize);
     Item.SpecialFolder = (Environment.SpecialFolder)reader.ReadInt32();
 }