Пример #1
0
        public void Update(libexeinfo.PE.Version version)
        {
            txtFileDate.Text  = version.FileDate != new DateTime(1601, 1, 1) ? $"{version.FileDate}" : "Not set";
            txtFileFlags.Text = version.FileFlags == 0 ? "Normal" : $"{version.FileFlags}";
            txtFileOs.Text    = Version.OsToString(version.FileOs);

            if (version.FileType == VersionFileType.VFT_DRV)
            {
                txtFileSubtype.Text = $"{Version.DriverToString(version.FileSubtype)} driver";
            }
            else if (version.FileType == VersionFileType.VFT_DRV)
            {
                txtFileSubtype.Text = $"{Version.FontToString(version.FileSubtype)} font";
            }
            else if (version.FileSubtype > 0)
            {
                txtFileSubtype.Text = $"{(uint)version.FileSubtype}";
            }
            else
            {
                txtFileSubtype.Text = "None";
            }

            txtFileType.Text       = Version.TypeToString(version.FileType);
            txtFileVersion.Text    = $"{version.FileVersion}";
            txtProductVersion.Text = $"{version.ProductVersion}";

            stringsByLanguage.Clear();

            foreach (KeyValuePair <string, Dictionary <string, string> > strByLang in version.StringsByLanguage)
            {
                string cultureName;
                string encodingName;

                try { cultureName = new CultureInfo(Convert.ToInt32(strByLang.Key.Substring(0, 4), 16)).DisplayName; }
                catch { cultureName = $"0x{Convert.ToInt32(strByLang.Key.Substring(0, 4), 16):X4}"; }

                try
                {
                    encodingName = Encoding.GetEncoding(Convert.ToInt32(strByLang.Key.Substring(4), 16)).EncodingName;
                }
                catch { encodingName = $"0x{Convert.ToInt32(strByLang.Key.Substring(4), 16):X4}"; }

                stringsByLanguage.Add(new StrByLang
                {
                    Name    = $"{cultureName} ({encodingName})",
                    Strings = strByLang.Value
                });
            }

            treeLanguages.DataStore = stringsByLanguage;
        }
Пример #2
0
        public static void Main(string[] args)
        {
            if (args.Length != 1)
            {
                Console.WriteLine("exeinfo version 0.1 © 2017-2018 Natalia Portillo");
                Console.WriteLine("Usage: exeinfo file.exe");
                return;
            }

            bool recognized = false;

            IExecutable mzExe   = new MZ(args[0]);
            IExecutable neExe   = new NE(args[0]);
            IExecutable stExe   = new AtariST(args[0]);
            IExecutable lxExe   = new LX(args[0]);
            IExecutable coffExe = new COFF(args[0]);
            IExecutable peExe   = new PE(args[0]);
            IExecutable geosExe = new Geos(args[0]);
            IExecutable elfExe  = new ELF(args[0]);

            if (neExe.Recognized)
            {
                recognized = true;
                Console.Write(neExe.Information);
                if (((NE)neExe).Versions != null)
                {
                    foreach (NE.Version vers in ((NE)neExe).Versions)
                    {
                        Console.WriteLine("\tVersion resource {0}:", vers.Name);
                        Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
                        Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
                        Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
                        if (vers.FileType == VersionFileType.VFT_DRV)
                        {
                            Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
                        }
                        else if (vers.FileType == VersionFileType.VFT_DRV)
                        {
                            Console.WriteLine("\t\tFile subtype: {0} font", Version.FontToString(vers.FileSubtype));
                        }
                        else if (vers.FileSubtype > 0)
                        {
                            Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
                        }
                        Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
                        Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));

                        foreach (KeyValuePair <string, Dictionary <string, string> > strByLang in vers.StringsByLanguage)
                        {
                            string cultureName;
                            string encodingName;

                            try
                            {
                                cultureName = new CultureInfo(Convert.ToInt32(strByLang.Key.Substring(0, 4), 16))
                                              .DisplayName;
                            }
                            catch
                            {
                                cultureName =
                                    $"unsupported culture 0x{Convert.ToInt32(strByLang.Key.Substring(0, 4), 16):X4}";
                            }

                            try
                            {
                                encodingName = Encoding
                                               .GetEncoding(Convert.ToInt32(strByLang.Key.Substring(4), 16))
                                               .EncodingName;
                            }
                            catch
                            {
                                encodingName =
                                    $"unsupported encoding 0x{Convert.ToInt32(strByLang.Key.Substring(4), 16):X4}";
                            }

                            Console.WriteLine("\t\tStrings for {0} in codepage {1}:", cultureName, encodingName);
                            foreach (KeyValuePair <string, string> strings in strByLang.Value)
                            {
                                Console.WriteLine("\t\t\t{0}: {1}", strings.Key, strings.Value);
                            }
                        }
                    }
                }

                if (neExe.Strings != null && neExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in neExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }
            else if (lxExe.Recognized)
            {
                recognized = true;
                Console.Write(lxExe.Information);

                if (((LX)lxExe).WinVersion != null)
                {
                    NE.Version vers = ((LX)lxExe).WinVersion;
                    Console.WriteLine("\tVxD version resource {0}:", vers.Name);
                    Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
                    Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
                    Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
                    if (vers.FileType == VersionFileType.VFT_DRV)
                    {
                        Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
                    }
                    else if (vers.FileType == VersionFileType.VFT_DRV)
                    {
                        Console.WriteLine("\t\tFile subtype: {0} font",
                                          Version.FontToString(vers.FileSubtype));
                    }
                    else if (vers.FileSubtype > 0)
                    {
                        Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
                    }
                    Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
                    Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));

                    foreach (KeyValuePair <string, Dictionary <string, string> > strByLang in vers.StringsByLanguage)
                    {
                        string cultureName;
                        string encodingName;

                        try
                        {
                            cultureName = new CultureInfo(Convert.ToInt32(strByLang.Key.Substring(0, 4), 16))
                                          .DisplayName;
                        }
                        catch
                        {
                            cultureName =
                                $"unsupported culture 0x{Convert.ToInt32(strByLang.Key.Substring(0, 4), 16):X4}";
                        }

                        try
                        {
                            encodingName = Encoding.GetEncoding(Convert.ToInt32(strByLang.Key.Substring(4), 16))
                                           .EncodingName;
                        }
                        catch
                        {
                            encodingName =
                                $"unsupported encoding 0x{Convert.ToInt32(strByLang.Key.Substring(4), 16):X4}";
                        }

                        Console.WriteLine("\t\tStrings for {0} in codepage {1}:", cultureName, encodingName);
                        foreach (KeyValuePair <string, string> strings in strByLang.Value)
                        {
                            Console.WriteLine("\t\t\t{0}: {1}", strings.Key, strings.Value);
                        }
                    }
                }

                if (lxExe.Strings != null && lxExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in lxExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }
            else if (peExe.Recognized)
            {
                recognized = true;
                Console.Write(peExe.Information);

                if (((PE)peExe).Versions != null)
                {
                    foreach (PE.Version vers in ((PE)peExe).Versions)
                    {
                        Console.WriteLine("\tVersion resource {0}:", vers.Name);
                        Console.WriteLine("\t\tFile version: {0}", vers.FileVersion);
                        Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion);
                        Console.WriteLine("\t\tFile type: {0}", Version.TypeToString(vers.FileType));
                        if (vers.FileType == VersionFileType.VFT_DRV)
                        {
                            Console.WriteLine("\t\tFile subtype: {0} driver", Version.DriverToString(vers.FileSubtype));
                        }
                        else if (vers.FileType == VersionFileType.VFT_DRV)
                        {
                            Console.WriteLine("\t\tFile subtype: {0} font", Version.FontToString(vers.FileSubtype));
                        }
                        else if (vers.FileSubtype > 0)
                        {
                            Console.WriteLine("\t\tFile subtype: {0}", (uint)vers.FileSubtype);
                        }
                        Console.WriteLine("\t\tFile flags: {0}", vers.FileFlags);
                        Console.WriteLine("\t\tFile OS: {0}", Version.OsToString(vers.FileOs));

                        foreach (KeyValuePair <string, Dictionary <string, string> > strByLang in vers.StringsByLanguage)
                        {
                            string cultureName;
                            string encodingName;

                            try
                            {
                                cultureName = new CultureInfo(Convert.ToInt32(strByLang.Key.Substring(0, 4), 16))
                                              .DisplayName;
                            }
                            catch
                            {
                                cultureName =
                                    $"unsupported culture 0x{Convert.ToInt32(strByLang.Key.Substring(0, 4), 16):X4}";
                            }

                            try
                            {
                                encodingName = Encoding
                                               .GetEncoding(Convert.ToInt32(strByLang.Key.Substring(4), 16))
                                               .EncodingName;
                            }
                            catch
                            {
                                encodingName =
                                    $"unsupported encoding 0x{Convert.ToInt32(strByLang.Key.Substring(4), 16):X4}";
                            }

                            Console.WriteLine("\t\tStrings for {0} in codepage {1}:", cultureName, encodingName);
                            foreach (KeyValuePair <string, string> strings in strByLang.Value)
                            {
                                Console.WriteLine("\t\t\t{0}: {1}", strings.Key, strings.Value);
                            }
                        }
                    }
                }

                if (peExe.Strings != null && peExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in peExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }
            else if (mzExe.Recognized)
            {
                recognized = true;
                Console.Write(mzExe.Information);
                if (((MZ)mzExe).ResourceStream != null || ((MZ)mzExe).ResourceHeader.rsh_vrsn != 0 &&
                    ((MZ)mzExe).ResourceHeader.rsh_vrsn != 1 &&
                    ((MZ)mzExe).ResourceHeader.rsh_vrsn != 4 &&
                    ((MZ)mzExe).ResourceHeader.rsh_vrsn != 5)
                {
                    PrintGemResources(((MZ)mzExe).ResourceHeader, ((MZ)mzExe).ResourceObjectRoots,
                                      ((MZ)mzExe).ResourceExtension, ((MZ)mzExe).GemColorIcons);
                }

                if (mzExe.Strings != null && mzExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in mzExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }

            if (stExe.Recognized)
            {
                recognized = true;
                Console.Write(stExe.Information);
                if (((AtariST)stExe).ResourceStream != null || ((AtariST)stExe).ResourceHeader.rsh_vrsn != 0 &&
                    ((AtariST)stExe).ResourceHeader.rsh_vrsn != 1 &&
                    ((AtariST)stExe).ResourceHeader.rsh_vrsn != 4 &&
                    ((AtariST)stExe).ResourceHeader.rsh_vrsn != 5)
                {
                    PrintGemResources(((AtariST)stExe).ResourceHeader, ((AtariST)stExe).ResourceObjectRoots,
                                      ((AtariST)stExe).ResourceExtension, ((AtariST)stExe).GemColorIcons);
                }

                if (stExe.Strings != null && stExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in stExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }

            if (coffExe.Recognized)
            {
                recognized = true;
                Console.Write(coffExe.Information);

                if (coffExe.Strings != null && coffExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in coffExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }
            else if (elfExe.Recognized)
            {
                recognized = true;
                Console.Write(elfExe.Information);

                if (elfExe.Strings != null && elfExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in elfExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }

            if (geosExe.Recognized)
            {
                recognized = true;
                Console.Write(geosExe.Information);

                if (geosExe.Strings != null && geosExe.Strings.Any())
                {
                    Console.WriteLine("\tStrings:");
                    foreach (string str in geosExe.Strings)
                    {
                        Console.WriteLine("\t\t{0}", str);
                    }
                }
            }

            if (!recognized)
            {
                Console.WriteLine("Executable format not recognized");
            }
        }