コード例 #1
0
ファイル: LinkInfo.cs プロジェクト: glenm80/IconInfo
        /// <inheritdoc />
        public override String ToString()
        {
            StringBuilder builder = new StringBuilder();

            builder.Append(base.ToString());
            builder.AppendFormat("LinkInfoSize: {0} (0x{0:X})", LinkInfoSize);
            builder.AppendLine();
            builder.AppendFormat("LinkInfoHeaderSize: {0} (0x{0:X})", LinkInfoHeaderSize);
            builder.AppendLine();
            builder.AppendFormat("LinkInfoFlags: {0}", LinkInfoFlags);
            builder.AppendLine();
            builder.AppendFormat("VolumeIDOffset: {0} (0x{0:X})", VolumeIDOffset);
            builder.AppendLine();
            builder.AppendFormat("LocalBasePathOffset: {0} (0x{0:X})", LocalBasePathOffset);
            builder.AppendLine();
            builder.AppendFormat("CommonNetworkRelativeLinkOffset: {0} (0x{0:X})", CommonNetworkRelativeLinkOffset);
            builder.AppendLine();
            builder.AppendFormat("CommonPathSuffixOffset: {0} (0x{0:X})", CommonPathSuffixOffset);
            builder.AppendLine();
            if (LinkInfoHeaderSize > 0x1C)
            {
                if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
                {
                    builder.AppendFormat("LocalBasePathOffsetUnicode: {0} (0x{0:X})", LocalBasePathOffsetUnicode);
                    builder.AppendLine();
                }
                if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
                {
                    builder.AppendFormat("CommonPathSuffixOffsetUnicode: {0} (0x{0:X})", CommonPathSuffixOffsetUnicode);
                    builder.AppendLine();
                }
            }
            if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                builder.Append(VolumeID.ToString());
                builder.AppendFormat("LocalBasePath: {0}", LocalBasePath);
                builder.AppendLine();
            }
            if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                builder.Append(CommonNetworkRelativeLink.ToString());
            }
            builder.AppendFormat("CommonPathSuffix: {0}", CommonPathSuffix);
            builder.AppendLine();
            if (LinkInfoHeaderSize > 0x1C)
            {
                if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
                {
                    builder.AppendFormat("LocalBasePathUnicode: {0}", LocalBasePathUnicode);
                    builder.AppendLine();
                }
                if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
                {
                    builder.AppendFormat("CommonPathSuffixUnicode: {0}", CommonPathSuffixUnicode);
                    builder.AppendLine();
                }
            }
            return(builder.ToString());
        }
コード例 #2
0
ファイル: LinkInfo.cs プロジェクト: glenm80/IconInfo
        /// <inheritdoc />
        public override byte[] GetBytes()
        {
            byte[] LinkInfo = new byte[LinkInfoSize];
            Buffer.BlockCopy(BitConverter.GetBytes(LinkInfoSize), 0, LinkInfo, 0, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(LinkInfoHeaderSize), 0, LinkInfo, 4, 4);
            Buffer.BlockCopy(BitConverter.GetBytes((UInt32)LinkInfoFlags), 0, LinkInfo, 8, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(VolumeIDOffset), 0, LinkInfo, 12, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(LocalBasePathOffset), 0, LinkInfo, 16, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(CommonNetworkRelativeLinkOffset), 0, LinkInfo, 20, 4);
            Buffer.BlockCopy(BitConverter.GetBytes(CommonPathSuffixOffset), 0, LinkInfo, 24, 4);

            if (LinkInfoHeaderSize > 0x1C)
            {
                if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(LocalBasePathOffsetUnicode), 0, LinkInfo, 28, 4);
                    Buffer.BlockCopy(Encoding.Unicode.GetBytes(LocalBasePathUnicode), 0, LinkInfo, (int)LocalBasePathOffsetUnicode, LocalBasePathUnicode.Length * 2);
                }

                if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
                {
                    Buffer.BlockCopy(BitConverter.GetBytes(CommonPathSuffixOffsetUnicode), 0, LinkInfo, 32, 4);
                    Buffer.BlockCopy(Encoding.Unicode.GetBytes(CommonPathSuffixUnicode), 0, LinkInfo, (int)CommonPathSuffixOffsetUnicode, CommonPathSuffixUnicode.Length * 2);
                }
            }

            if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                Buffer.BlockCopy(VolumeID.GetBytes(), 0, LinkInfo, (int)VolumeIDOffset, (int)VolumeID.VolumeIDSize);
                Buffer.BlockCopy(Encoding.Default.GetBytes(LocalBasePath), 0, LinkInfo, (int)LocalBasePathOffset, LocalBasePath.Length);
            }

            if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                Buffer.BlockCopy(CommonNetworkRelativeLink.GetBytes(), 0, LinkInfo, (int)CommonNetworkRelativeLinkOffset, (int)CommonNetworkRelativeLink.CommonNetworkRelativeLinkSize);
                Buffer.BlockCopy(Encoding.Default.GetBytes(CommonPathSuffix), 0, LinkInfo, (int)CommonPathSuffixOffset, CommonPathSuffix.Length);
            }
            return(LinkInfo);
        }
コード例 #3
0
        /// <summary>
        /// Create a CommonNetworkRelativeLink from a given byte array
        /// </summary>
        /// <param name="ba">The byte array</param>
        /// <returns>A CommonNetworkRelativeLink object</returns>

        public static CommonNetworkRelativeLink FromByteArray(byte[] ba)
        {
            CommonNetworkRelativeLink CommonNetworkRelativeLink = new CommonNetworkRelativeLink();

            if (ba.Length < 0x14)
            {
                throw new ArgumentException(String.Format("Size of the CommonNetworkRelativeLink Structure is less than 20 ({0})", ba.Length));
            }

            UInt32 CommonNetworkRelativeLinkSize = BitConverter.ToUInt32(ba, 0);

            if (CommonNetworkRelativeLinkSize > ba.Length)
            {
                throw new ArgumentException(String.Format("The CommonNetworkRelativeLinkSize is {0} is incorrect (expected {1})", CommonNetworkRelativeLink, ba.Length));
            }

            CommonNetworkRelativeLinkFlags CommonNetworkRelativeLinkFlags = (CommonNetworkRelativeLinkFlags)BitConverter.ToUInt32(ba, 4);
            UInt32 NetNameOffset           = BitConverter.ToUInt32(ba, 8);
            UInt32 DeviceNameOffset        = BitConverter.ToUInt32(ba, 12);
            UInt32 NetNameOffsetUnicode    = 0;
            UInt32 DeviceNameOffsetUnicode = 0;

            CommonNetworkRelativeLink.NetworkProviderType = (NetworkProviderType)BitConverter.ToUInt32(ba, 16);

            if (NetNameOffset > 0x14)
            {
                NetNameOffsetUnicode    = BitConverter.ToUInt32(ba, 20);
                DeviceNameOffsetUnicode = BitConverter.ToUInt32(ba, 24);
            }

            byte[] tmp = ba.Skip((int)NetNameOffset).ToArray();
            CommonNetworkRelativeLink.NetName = Encoding.Default.GetString(tmp.Take(Array.IndexOf(tmp, (byte)0x00) + 1).ToArray()).TrimEnd(new char[] { (char)0 });

            if ((CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidDevice) != 0)
            {
                tmp = ba.Skip((int)DeviceNameOffset).ToArray();
                CommonNetworkRelativeLink.DeviceName = Encoding.Default.GetString(tmp.Take(Array.IndexOf(tmp, (byte)0x00) + 1).ToArray()).TrimEnd(new char[] { (char)0 });
            }

            if (NetNameOffset > 0x14)
            {
                int Index = 0;
                tmp = ba.Skip((int)NetNameOffsetUnicode).ToArray();
                for (int i = 0; i < tmp.Length - 1; i++)
                {
                    if (tmp[i] == 0x00 && tmp[i + 1] == 0x00)
                    {
                        Index = i;
                        break;
                    }
                }
                CommonNetworkRelativeLink.NetNameUnicode = Encoding.Unicode.GetString(tmp.Take(Index + 1).ToArray()).TrimEnd(new char[] { (char)0 });

                if ((CommonNetworkRelativeLinkFlags & CommonNetworkRelativeLinkFlags.ValidDevice) != 0)
                {
                    tmp = ba.Skip((int)DeviceNameOffsetUnicode).ToArray();
                    for (int i = 0; i < tmp.Length - 1; i++)
                    {
                        if (tmp[i] == 0x00 && tmp[i + 1] == 0x00)
                        {
                            Index = i;
                            break;
                        }
                    }
                    CommonNetworkRelativeLink.DeviceNameUnicode = Encoding.Unicode.GetString(tmp.Take(Index + 1).ToArray()).TrimEnd(new char[] { (char)0 });
                }
            }

            return(CommonNetworkRelativeLink);
        }
コード例 #4
0
ファイル: LinkInfo.cs プロジェクト: glenm80/IconInfo
        /// <summary>
        /// Create a LinkInfo from a given byte array
        /// </summary>
        /// <param name="ba">The byte array</param>
        /// <returns>A LinkInfo object</returns>
        public static LinkInfo FromByteArray(byte[] ba)
        {
            LinkInfo LinkInfo = new LinkInfo();

            if (ba.Length < 0x1C)
            {
                throw new ArgumentException(String.Format("Size of the LinkInfo Structure is less than 28 ({0})", ba.Length));
            }

            UInt32 LinkInfoSize = BitConverter.ToUInt32(ba, 0);

            if (LinkInfoSize > ba.Length)
            {
                throw new ArgumentException(String.Format("The LinkInfoSize is {0} is incorrect (expected {1})", LinkInfoSize, ba.Length));
            }

            UInt32 LinkInfoHeaderSize = BitConverter.ToUInt32(ba, 4);

            if (LinkInfoHeaderSize < 0x1C)
            {
                throw new ArgumentException(String.Format("The LinkInfoHeaderSize is {0} is incorrect)", LinkInfoHeaderSize));
            }

            LinkInfoFlags LinkInfoFlags = (LinkInfoFlags)BitConverter.ToUInt32(ba, 8);

            // TODO: check offsets
            UInt32 VolumeIDOffset                  = BitConverter.ToUInt32(ba, 12);
            UInt32 LocalBasePathOffset             = BitConverter.ToUInt32(ba, 16);
            UInt32 CommonNetworkRelativeLinkOffset = BitConverter.ToUInt32(ba, 20);
            UInt32 CommonPathSuffixOffset          = BitConverter.ToUInt32(ba, 24);
            UInt32 LocalBasePathOffsetUnicode      = 0;
            UInt32 CommonPathSuffixOffsetUnicode   = 0;

            if (LinkInfoHeaderSize > 0x1C)
            {
                if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
                {
                    LocalBasePathOffsetUnicode = BitConverter.ToUInt32(ba, 28);
                }
                if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
                {
                    CommonPathSuffixOffsetUnicode = BitConverter.ToUInt32(ba, 32);
                }
            }

            byte[] tmp;
            if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
            {
                tmp = ba.Skip((int)VolumeIDOffset).ToArray();
                LinkInfo.VolumeID = VolumeID.FromByteArray(tmp);
                tmp = ba.Skip((int)LocalBasePathOffset).ToArray();
                LinkInfo.LocalBasePath = Encoding.Default.GetString(tmp.Take(Array.IndexOf(tmp, (byte)0x00) + 1).ToArray()).TrimEnd(new char[] { (char)0 });
            }

            if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
            {
                tmp = ba.Skip((int)CommonNetworkRelativeLinkOffset).ToArray();
                LinkInfo.CommonNetworkRelativeLink = CommonNetworkRelativeLink.FromByteArray(tmp);
                tmp = ba.Skip((int)CommonPathSuffixOffset).ToArray();
                LinkInfo.CommonPathSuffix = Encoding.Default.GetString(tmp.Take(Array.IndexOf(tmp, (byte)0x00) + 1).ToArray()).TrimEnd(new char[] { (char)0 });
            }

            if (LinkInfoHeaderSize >= 0x24)
            {
                if ((LinkInfoFlags & LinkInfoFlags.VolumeIDAndLocalBasePath) != 0)
                {
                    int Index = 0;
                    tmp = ba.Skip((int)LocalBasePathOffsetUnicode).ToArray();
                    for (int i = 0; i < tmp.Length - 1; i++)
                    {
                        if (tmp[i] == 0x00 && tmp[i + 1] == 0x00)
                        {
                            Index = i;
                            break;
                        }
                    }

                    LinkInfo.LocalBasePathUnicode = Encoding.Unicode.GetString(tmp.Take(Index + 1).ToArray()).TrimEnd(new char[] { (char)0 });
                }

                if ((LinkInfoFlags & LinkInfoFlags.CommonNetworkRelativeLinkAndPathSuffix) != 0)
                {
                    int Index = 0;
                    tmp = ba.Skip((int)CommonPathSuffixOffsetUnicode).ToArray();
                    for (int i = 0; i < tmp.Length - 1; i++)
                    {
                        if (tmp[i] == 0x00 && tmp[i + 1] == 0x00)
                        {
                            Index = i;
                            break;
                        }
                    }
                    LinkInfo.CommonPathSuffixUnicode = Encoding.Unicode.GetString(tmp.Take(Index + 1).ToArray()).TrimEnd(new char[] { (char)0 });
                }
            }

            return(LinkInfo);
        }