Esempio n. 1
0
    public static int Main(string[] args)
    {
        // TODO:
        // 1. Dump the file version info
        // 2. Try to load the file as a .NET assembly, and dump *that* info if successful
        // 3. Check the PE header, and write the bitness if you can find it
        // 4. Argument parsing
        var file = args[0];

        using (ExtendedFileVersionInfo info = ExtendedFileVersionInfo.TryCreate(file))
        {
            Log.Info("File " + file + " has the following attributes:");
            StringBuilder sb = new StringBuilder();
            foreach (string name in s_properties)
            {
                try
                {
                    if (info.TryGetVersionString(name, out var value))
                    {
                        Log.Info("  " + name + " = " + value);
                    }
                }
                catch (ExtendedFileVersionInfoException)
                {
                    sb.Append("  " + name + Environment.NewLine);
                }
            }
            string notFound = sb.ToString();
            if (notFound != "")
            {
                Log.Verbose(Environment.NewLine + "The following values are not found in the version resource:" + Environment.NewLine + notFound);
            }
        }
        return(0);
    }
Esempio n. 2
0
    /// <summary>
    /// Trying to get the string from the version resource.
    /// </summary>
    /// <param name="name">Name of the resource property</param>
    /// <param name="fileName">The name of the PE file whose version resource we want to read.</param>
    /// <returns>True if such string is found, otherwise false</returns>
    unsafe public static string GetVersionString(string fileName, string name)
    {
        //Ensure.ArgIsNotNullOrWhiteSpace(fileName, "fileName");
        //Ensure.ArgIsNotNullOrWhiteSpace(name, "name");

        if (!ExtendedEnvironment.IsWindows)
        {
            return(null);
        }

        using (var info = new ExtendedFileVersionInfo(fileName))
        {
            return(info[name]);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// Trying to get the string from the version resource.
    /// </summary>
    /// <param name="name">Name of the resource property</param>
    /// <param name="fileName">The name of the PE file whose version resource we want to read.</param>
    /// <param name="result">Holds the version string</param>
    /// <returns>True if such string is found, otherwise false</returns>
    unsafe public static bool TryGetVersionString(string fileName, string name, out string result)
    {
        //Ensure.ArgIsNotNullOrWhiteSpace(fileName, "fileName");
        //Ensure.ArgIsNotNullOrWhiteSpace(name, "name");

        if (!ExtendedEnvironment.IsWindows)
        {
            result = null;
            return(false);
        }

        try
        {
            using (var info = new ExtendedFileVersionInfo(fileName))
            {
                return(info.TryGetVersionString(name, out result));
            }
        }
        catch (ExtendedFileVersionInfoException)
        {
            result = null;
            return(false);
        }
    }