// TODO: Icons void OnLoadComplete(object sender, EventArgs eventArgs) { if (Context.Executables?.Count > 0) { lblPanelName.Text = "Please wait while reading executables found"; prgProgress.MaxValue = Context.Executables.Count; prgProgress.MinValue = 0; prgProgress.Value = 0; foreach (string file in Context.Executables) { var exeStream = new FileStream(file, FileMode.Open, FileAccess.Read); var mzExe = new MZ(exeStream); var neExe = new NE(exeStream); var stExe = new AtariST(exeStream); var lxExe = new LX(exeStream); var coffExe = new COFF(exeStream); var peExe = new PE(exeStream); var geosExe = new Geos(exeStream); var elfExe = new ELF(exeStream); IExecutable recognizedExe; if (neExe.Recognized) { recognizedExe = neExe; } else if (lxExe.Recognized) { recognizedExe = lxExe; } else if (peExe.Recognized) { recognizedExe = peExe; } else if (mzExe.Recognized) { recognizedExe = mzExe; } else if (coffExe.Recognized) { recognizedExe = coffExe; } else if (stExe.Recognized) { recognizedExe = stExe; } else if (elfExe.Recognized) { recognizedExe = elfExe; } else if (geosExe.Recognized) { recognizedExe = geosExe; } else { exeStream.Close(); continue; } if (recognizedExe.Strings != null) { strings.AddRange(recognizedExe.Strings); } foreach (Architecture exeArch in recognizedExe.Architectures) { ArchitecturesTypeArchitecture?arch = ExeArchToSchemaArch(exeArch); if (arch.HasValue && !architectures.Contains($"{arch.Value}")) { architectures.Add($"{arch.Value}"); } } operatingSystems.Add(new TargetOsEntry { name = recognizedExe.RequiredOperatingSystem.Name, version = $"{recognizedExe.RequiredOperatingSystem.MajorVersion}.{recognizedExe.RequiredOperatingSystem.MinorVersion}" }); switch (recognizedExe) { case NE _: if (neExe.Versions != null) { foreach (NE.Version exeVersion in neExe.Versions) { versions.Add(exeVersion.FileVersion); versions.Add(exeVersion.ProductVersion); version = exeVersion.ProductVersion; foreach (KeyValuePair <string, Dictionary <string, string> > kvp in exeVersion. StringsByLanguage) { if (kvp.Value.TryGetValue("CompanyName", out string tmpValue)) { developer = tmpValue; } if (kvp.Value.TryGetValue("ProductName", out string tmpValue2)) { product = tmpValue2; } } } } break; case PE _: if (peExe.Versions != null) { foreach (PE.Version exeVersion in peExe.Versions) { versions.Add(exeVersion.FileVersion); versions.Add(exeVersion.ProductVersion); version = exeVersion.ProductVersion; foreach (KeyValuePair <string, Dictionary <string, string> > kvp in exeVersion. StringsByLanguage) { if (kvp.Value.TryGetValue("CompanyName", out string tmpValue)) { developer = tmpValue; } if (kvp.Value.TryGetValue("ProductName", out string tmpValue2)) { product = tmpValue2; } } } } break; case LX _: if (lxExe.WinVersion != null) { versions.Add(lxExe.WinVersion.FileVersion); versions.Add(lxExe.WinVersion.ProductVersion); version = lxExe.WinVersion.ProductVersion; foreach (KeyValuePair <string, Dictionary <string, string> > kvp in lxExe.WinVersion. StringsByLanguage) { if (kvp.Value.TryGetValue("CompanyName", out string tmpValue)) { developer = tmpValue; } if (kvp.Value.TryGetValue("ProductName", out string tmpValue2)) { product = tmpValue2; } } } break; } exeStream.Close(); prgProgress.Value++; } strings = strings.Distinct().ToList(); strings.Sort(); if (strings.Count == 0 && minimumPanel == Panels.Strings) { minimumPanel = Panels.Versions; } else { maximumPanel = Panels.Strings; } panelStrings.treeStrings.DataStore = strings; versions = versions.Distinct().ToList(); versions.Sort(); panelVersions.treeVersions.DataStore = versions; architectures = architectures.Distinct().ToList(); architectures.Sort(); panelVersions.treeArchs.DataStore = architectures; Dictionary <string, List <string> > osEntriesDictionary = new Dictionary <string, List <string> >(); foreach (TargetOsEntry osEntry in operatingSystems) { if (string.IsNullOrEmpty(osEntry.name)) { continue; } osEntriesDictionary.TryGetValue(osEntry.name, out List <string> osvers); if (osvers == null) { osvers = new List <string>(); } osvers.Add(osEntry.version); osEntriesDictionary.Remove(osEntry.name); osEntriesDictionary.Add(osEntry.name, osvers); } operatingSystems = new List <TargetOsEntry>(); foreach (KeyValuePair <string, List <string> > kvp in osEntriesDictionary.OrderBy(t => t.Key)) { kvp.Value.Sort(); foreach (string s in kvp.Value.Distinct()) { operatingSystems.Add(new TargetOsEntry { name = kvp.Key, version = s }); } } panelVersions.treeOs.DataStore = operatingSystems; if (versions.Count > 0 || architectures.Count > 0 || operatingSystems.Count > 0) { maximumPanel = Panels.Versions; } } prgProgress.Visible = false; btnPrevious.Enabled = false; switch (minimumPanel) { case Panels.Description: pnlPanel.Content = panelDescription; currentPanel = Panels.Description; break; case Panels.Strings: pnlPanel.Content = panelStrings; currentPanel = Panels.Strings; break; case Panels.Versions: pnlPanel.Content = panelVersions; currentPanel = Panels.Versions; break; } if (currentPanel == maximumPanel) { btnNext.Text = "Finish"; } lblPanelName.Visible = false; }
protected void OnBtnLoadClick(object sender, EventArgs e) { txtFile.Text = ""; txtType.Text = ""; txtInformation.Text = ""; cmbArch.Items.Clear(); lblSubsystem.Visible = false; txtSubsystem.Visible = false; tabStrings.Visible = false; tabGemResources.Visible = false; tabSegments.Visible = false; tabNeResources.Visible = false; tabLeVxdVersion.Visible = false; tabLxResources.Visible = false; tabPeResources.Visible = false; tabBeResources.Visible = false; OpenFileDialog dlgOpen = new OpenFileDialog { Title = "Choose executable file", MultiSelect = false }; if (dlgOpen.ShowDialog(this) != DialogResult.Ok) { return; } txtFile.Text = dlgOpen.FileName; txtInformation.Text = ""; txtOs.Text = ""; txtSubsystem.Text = ""; txtType.Text = ""; IExecutable mzExe = new MZ(dlgOpen.FileName); IExecutable neExe = new libexeinfo.NE(dlgOpen.FileName); IExecutable stExe = new AtariST(dlgOpen.FileName); IExecutable lxExe = new libexeinfo.LX(dlgOpen.FileName); IExecutable coffExe = new COFF(dlgOpen.FileName); IExecutable peExe = new libexeinfo.PE(dlgOpen.FileName); IExecutable geosExe = new Geos(dlgOpen.FileName); IExecutable elfExe = new ELF(dlgOpen.FileName); IExecutable recognizedExe = null; if (mzExe.Recognized) { recognizedExe = mzExe; if (((MZ)mzExe).ResourceObjectRoots != null && ((MZ)mzExe).ResourceObjectRoots.Any()) { tabGemResources.Update(((MZ)mzExe).ResourceObjectRoots, ((MZ)mzExe).GemColorIcons); tabGemResources.Visible = true; } } if (neExe.Recognized) { recognizedExe = neExe; if (((libexeinfo.NE)neExe).Resources.types != null && ((libexeinfo.NE)neExe).Resources.types.Any()) { tabNeResources.Update(((libexeinfo.NE)neExe).Resources.types, ((libexeinfo.NE)neExe).Header.target_os); tabNeResources.Visible = true; } } else if (lxExe.Recognized) { recognizedExe = lxExe; if (((libexeinfo.LX)lxExe).WinVersion != null) { tabLeVxdVersion.Visible = true; tabLeVxdVersion.Update(((libexeinfo.LX)lxExe).WinVersion); } if (((libexeinfo.LX)lxExe).neFormatResourceTable.types != null && ((libexeinfo.LX)lxExe).neFormatResourceTable.types.Any()) { tabLxResources.Update(((libexeinfo.LX)lxExe).neFormatResourceTable.types); tabLxResources.Visible = true; } } else if (peExe.Recognized) { recognizedExe = peExe; if (((libexeinfo.PE)peExe).WindowsResourcesRoot?.children != null) { tabPeResources.Update(((libexeinfo.PE)peExe).WindowsResourcesRoot); tabPeResources.Visible = true; } if (((libexeinfo.PE)peExe).BeosResources != null) { tabBeResources.Update(((libexeinfo.PE)peExe).BeosResources, peExe.IsBigEndian); tabBeResources.Visible = true; } } else if (stExe.Recognized) { recognizedExe = stExe; if (((AtariST)stExe).ResourceObjectRoots != null && ((AtariST)stExe).ResourceObjectRoots.Any()) { tabGemResources.Update(((AtariST)stExe).ResourceObjectRoots, ((AtariST)stExe).GemColorIcons); tabGemResources.Visible = true; } } else if (coffExe.Recognized) { recognizedExe = coffExe; } else if (elfExe.Recognized) { recognizedExe = elfExe; } else if (geosExe.Recognized) { recognizedExe = geosExe; } else { txtType.Text = "Format not recognized"; } if (recognizedExe == null) { return; } txtType.Text = recognizedExe.Type; txtInformation.Text = recognizedExe.Information; foreach (Architecture arch in recognizedExe.Architectures) { cmbArch.Items.Add(Enums.ArchitectureName.FirstOrDefault(ar => ar.arch == arch).longName); } cmbArch.SelectedIndex = 0; if (recognizedExe.RequiredOperatingSystem.MajorVersion > 0) { txtOs.Text = $"{recognizedExe.RequiredOperatingSystem.Name}" + $" {recognizedExe.RequiredOperatingSystem.MajorVersion}" + $".{recognizedExe.RequiredOperatingSystem.MinorVersion}"; } else { txtOs.Text = recognizedExe.RequiredOperatingSystem.Name; } if (!string.IsNullOrEmpty(recognizedExe.RequiredOperatingSystem.Subsystem)) { lblSubsystem.Visible = true; txtSubsystem.Visible = true; txtSubsystem.Text = recognizedExe.RequiredOperatingSystem.Subsystem; } if (recognizedExe.Strings != null && recognizedExe.Strings.Any()) { tabStrings.Update(recognizedExe.Strings); tabStrings.Visible = true; } if (recognizedExe.Segments != null && recognizedExe.Segments.Any()) { tabSegments.Update(recognizedExe.Segments); tabSegments.Visible = true; } }
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"); } }