Esempio n. 1
0
        /// <summary>
        /// Gets the File Version Information that is stored as a resource in the PE file.  (This is what the
        /// version tab a file's property page is populated with).
        /// </summary>
        public FileVersionInfo?GetFileVersionInfo()
        {
            ResourceEntry?versionNode = Resources.Children.FirstOrDefault(r => r.Name == "Version");

            if (versionNode is null || versionNode.ChildCount != 1)
            {
                return(null);
            }

            versionNode = versionNode.Children[0];
            if (!versionNode.IsLeaf && versionNode.ChildCount == 1)
            {
                versionNode = versionNode.Children[0];
            }

            int size = versionNode.Size;

            if (size < 16)  // Arbitrarily small value to ensure it's non-zero and has at least a little data in it
            {
                return(null);
            }

            byte[] buffer = ArrayPool <byte> .Shared.Rent(size);

            try
            {
                int count = versionNode.GetData(buffer);
                return(new FileVersionInfo(buffer.AsSpan(0, count)));
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(buffer);
            }
        }
Esempio n. 2
0
 internal ResourceEntry(PEImage image, ResourceEntry?parent, string name, bool leaf, int offset)
 {
     Image   = image;
     Parent  = parent;
     Name    = name;
     IsLeaf  = leaf;
     _offset = offset;
 }
Esempio n. 3
0
        /// <summary>
        /// Gets the File Version Information that is stored as a resource in the PE file.  (This is what the
        /// version tab a file's property page is populated with).
        /// </summary>
        public FileVersionInfo?GetFileVersionInfo()
        {
            ResourceEntry?versionNode = Resources.Children.FirstOrDefault(r => r.Name == "Version");

            if (versionNode == null || versionNode.Children.Count != 1)
            {
                return(null);
            }

            versionNode = versionNode.Children[0];
            if (!versionNode.IsLeaf && versionNode.Children.Count == 1)
            {
                versionNode = versionNode.Children[0];
            }

            int size = versionNode.Size;

            if (size <= FileVersionInfo.DataOffset)
            {
                return(null);
            }

            byte[] buffer = ArrayPool <byte> .Shared.Rent(size);

            try
            {
                int             count  = versionNode.GetData(buffer);
                Span <byte>     span   = new Span <byte>(buffer, 0, count);
                FileVersionInfo result = new FileVersionInfo(span);
                return(result);
            }
            finally
            {
                ArrayPool <byte> .Shared.Return(buffer);
            }
        }