Ejemplo n.º 1
0
        public void ParseFileExampleTest()
        {
            using (var ms = new MemoryStream(GetFileExample()))
            {
                var target = ShellShortcut.Load(ms);

                // Assert.AreEqual(LinkFlags.HasLinkTargetIDList | LinkFlags.HasLinkInfo | LinkFlags.HasRelativePath | LinkFlags.HasWorkingDir | LinkFlags.IsUnicode | LinkFlags.EnableTargetMetadata,null);
                Assert.AreEqual(FileAttributesFlags.Archive, target.FileAttributes);
                Assert.IsTrue(Math.Abs((new DateTime(2008, 9, 12, 20, 27, 17) - target.CreationTime.Value).TotalSeconds) < 1);
                Assert.IsTrue(Math.Abs((new DateTime(2008, 9, 12, 20, 27, 17) - target.AccessTime.Value).TotalSeconds) < 1);
                Assert.IsTrue(Math.Abs((new DateTime(2008, 9, 12, 20, 27, 17) - target.WriteTime.Value).TotalSeconds) < 1);
                Assert.AreEqual(0, target.FileSize);
                Assert.AreEqual(0, target.IconIndex);
                Assert.AreEqual(ShowCommand.Normal, target.ShowCommand);
                Assert.AreEqual(Key.None, target.HotKey);
                Assert.AreEqual(Modifiers.None, target.HotKeyModifiers);
                Assert.AreEqual(4, target.LinkTargetIDList.Count);
                Assert.AreEqual(18, target.LinkTargetIDList[0].Length);
                Assert.AreEqual(23, target.LinkTargetIDList[1].Length);
                Assert.AreEqual(68, target.LinkTargetIDList[2].Length);
                Assert.AreEqual(70, target.LinkTargetIDList[3].Length);

                Assert.AreEqual(DriveType.Fixed, target.LinkInfo.VolumeID.DriveType);
                Assert.AreEqual(0x307A8A81, target.LinkInfo.VolumeID.SerialNumber);
                Assert.AreEqual("", target.LinkInfo.VolumeID.VolumeLabel);

                Assert.AreEqual(@"C:\test\a.txt", target.LinkInfo.LocalBasePath);
                Assert.AreEqual("", target.LinkInfo.CommonPathSuffix);

                Assert.AreEqual(@".\a.txt", target.RelativePath);
                Assert.AreEqual(@"C:\test", target.WorkingDir);

                Assert.AreEqual(1, target.ExtraData.Count);

                Assert.IsInstanceOfType(target.ExtraData[0], typeof(TrackerDataBlock));
                var tbd = (TrackerDataBlock)target.ExtraData[0];

                Assert.AreEqual("chris-xps", tbd.MachineID);
                Assert.AreEqual(new Guid(new byte[] { 0x40, 0x78, 0xC7, 0x94, 0x47, 0xFA, 0xC7, 0x46, 0xB3, 0x56, 0x5C, 0x2D, 0xC6, 0xB6, 0xD1, 0x15, }), tbd.Droid1);
                Assert.AreEqual(new Guid(new byte[] { 0xEC, 0x46, 0xCD, 0x7B, 0x22, 0x7F, 0xDD, 0x11, 0x94, 0x99, 0x00, 0x13, 0x72, 0x16, 0x87, 0x4A, }), tbd.Droid2);
                Assert.AreEqual(new Guid(new byte[] { 0x40, 0x78, 0xC7, 0x94, 0x47, 0xFA, 0xC7, 0x46, 0xB3, 0x56, 0x5C, 0x2D, 0xC6, 0xB6, 0xD1, 0x15, }), tbd.DroidBirth1);
                Assert.AreEqual(new Guid(new byte[] { 0xEC, 0x46, 0xCD, 0x7B, 0x22, 0x7F, 0xDD, 0x11, 0x94, 0x99, 0x00, 0x13, 0x72, 0x16, 0x87, 0x4A, }), tbd.DroidBirth2);
            }
        }
Ejemplo n.º 2
0
        public static ShellShortcut Load(BinaryReader reader)
        {
            if (reader.ReadInt32() != 0x4c)
            {
                throw new FormatException("ファイルヘッダーが無効です。");
            }
            var a = reader.ReadInt32();
            var b = reader.ReadInt32();
            var c = reader.ReadInt32();
            var d = reader.ReadInt32();

            if (a != 0x00021401 ||
                b != 0 ||
                c != 0xC0 ||
                d != 0x46000000)
            {
                throw new FormatException("ファイルヘッダーが無効です。");
            }

            var r = new ShellShortcut();

            var flags = (LinkFlags)reader.ReadInt32();

            r.FileAttributes = (FileAttributesFlags)reader.ReadInt32();

            var crt = reader.ReadInt64();

            r.CreationTime = crt != 0 ? DateTime.FromFileTimeUtc(crt) : (DateTime?)null;
            var acc = reader.ReadInt64();

            r.AccessTime = acc != 0 ? DateTime.FromFileTimeUtc(acc) : (DateTime?)null;
            var wrt = reader.ReadInt64();

            r.WriteTime = wrt != 0 ? DateTime.FromFileTimeUtc(wrt) : (DateTime?)null;

            r.FileSize  = reader.ReadInt32();
            r.IconIndex = reader.ReadInt32();

            r.ShowCommand = (ShowCommand)reader.ReadInt32();

            r.HotKey          = (Key)reader.ReadByte();
            r.HotKeyModifiers = (Modifiers)reader.ReadByte();

            reader.ReadInt16();
            reader.ReadInt32();
            reader.ReadInt32();

            byte[]        bytes = null;
            StringBuilder sb    = null;

            if ((flags & LinkFlags.HasLinkTargetIDList) == LinkFlags.HasLinkTargetIDList)
            {
                r.LinkTargetIDList = reader.ReadIDList();
            }
            if ((flags & LinkFlags.HasLinkInfo) == LinkFlags.HasLinkInfo)
            {
                r.LinkInfo = LinkInfo.Parse(reader, ref bytes, ref sb);
            }
            var isUnicode = (flags & LinkFlags.IsUnicode) == LinkFlags.IsUnicode;

            if ((flags & LinkFlags.HasName) == LinkFlags.HasName)
            {
                r.Name = reader.ReadStringData(isUnicode, ref sb, ref bytes);
            }
            if ((flags & LinkFlags.HasRelativePath) == LinkFlags.HasRelativePath)
            {
                r.RelativePath = reader.ReadStringData(isUnicode, ref sb, ref bytes);
            }
            if ((flags & LinkFlags.HasWorkingDir) == LinkFlags.HasWorkingDir)
            {
                r.WorkingDir = reader.ReadStringData(isUnicode, ref sb, ref bytes);
            }
            if ((flags & LinkFlags.HasArguments) == LinkFlags.HasArguments)
            {
                r.Arguments = reader.ReadStringData(isUnicode, ref sb, ref bytes);
            }
            if ((flags & LinkFlags.HasIconLocation) == LinkFlags.HasIconLocation)
            {
                r.IconLocation = reader.ReadStringData(isUnicode, ref sb, ref bytes);
            }

            foreach (var db in DataBlock.Parse(reader, ref bytes, ref sb))
            {
                r.ExtraData.Add(db);
            }

            return(r);
        }
Ejemplo n.º 3
0
        public void AnsiFileTest()
        {
            var target = ShellShortcut.Load("ansi_file.lnk");

            Assert.IsNotNull(target);
        }
Ejemplo n.º 4
0
        public void UnicodeFileTest()
        {
            var target = ShellShortcut.Load("unicode_file.lnk");

            Assert.IsNotNull(target);
        }