From b13a4a95d817495a54c2fc439a9c20d88c843542 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Mon, 16 Oct 2017 14:13:42 +0100 Subject: [PATCH] Moved logic to a shared library. --- exeinfo.sln | 6 +++ exeinfo/Program.cs | 42 ++++++++-------- exeinfo/exeinfo.csproj | 14 ++---- {exeinfo => libexeinfo}/MZ/Consts.cs | 2 +- {exeinfo => libexeinfo}/MZ/Info.cs | 2 +- {exeinfo => libexeinfo}/MZ/Structs.cs | 2 +- {exeinfo => libexeinfo}/NE/Consts.cs | 2 +- {exeinfo => libexeinfo}/NE/Enums.cs | 2 +- {exeinfo => libexeinfo}/NE/Info.cs | 2 +- {exeinfo => libexeinfo}/NE/Structs.cs | 2 +- {exeinfo => libexeinfo}/NE/Version.cs | 2 +- libexeinfo/Properties/AssemblyInfo.cs | 26 ++++++++++ libexeinfo/libexeinfo.csproj | 71 +++++++++++++++++++++++++++ libexeinfo/packages.config | 4 ++ 14 files changed, 140 insertions(+), 39 deletions(-) rename {exeinfo => libexeinfo}/MZ/Consts.cs (80%) rename {exeinfo => libexeinfo}/MZ/Info.cs (98%) rename {exeinfo => libexeinfo}/MZ/Structs.cs (97%) rename {exeinfo => libexeinfo}/NE/Consts.cs (98%) rename {exeinfo => libexeinfo}/NE/Enums.cs (99%) rename {exeinfo => libexeinfo}/NE/Info.cs (99%) rename {exeinfo => libexeinfo}/NE/Structs.cs (98%) rename {exeinfo => libexeinfo}/NE/Version.cs (99%) create mode 100644 libexeinfo/Properties/AssemblyInfo.cs create mode 100644 libexeinfo/libexeinfo.csproj create mode 100644 libexeinfo/packages.config diff --git a/exeinfo.sln b/exeinfo.sln index 9110853..21adc69 100644 --- a/exeinfo.sln +++ b/exeinfo.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 2012 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "exeinfo", "exeinfo\exeinfo.csproj", "{504F0A15-25DC-42B1-81FE-BA22A8EF24B5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "libexeinfo", "libexeinfo\libexeinfo.csproj", "{5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x86 = Debug|x86 @@ -13,5 +15,9 @@ Global {504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Debug|x86.Build.0 = Debug|x86 {504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Release|x86.ActiveCfg = Release|x86 {504F0A15-25DC-42B1-81FE-BA22A8EF24B5}.Release|x86.Build.0 = Release|x86 + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0}.Debug|x86.ActiveCfg = Debug|Any CPU + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0}.Debug|x86.Build.0 = Debug|Any CPU + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0}.Release|x86.ActiveCfg = Release|Any CPU + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection EndGlobal diff --git a/exeinfo/Program.cs b/exeinfo/Program.cs index 643a65a..839b7e8 100644 --- a/exeinfo/Program.cs +++ b/exeinfo/Program.cs @@ -9,8 +9,8 @@ namespace exeinfo { class MainClass { - static MZ.Header mzHdr; - static NE.Header neHdr; + static libexeinfo.MZ.Header mzHdr; + static libexeinfo.NE.Header neHdr; public static void Main(string[] args) { @@ -25,53 +25,53 @@ namespace exeinfo bool recognized = false; - byte[] buffer = new byte[Marshal.SizeOf(typeof(MZ.Header))]; + byte[] buffer = new byte[Marshal.SizeOf(typeof(libexeinfo.MZ.Header))]; exeFs.Read(buffer, 0, buffer.Length); IntPtr hdrPtr = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, hdrPtr, buffer.Length); - mzHdr = (MZ.Header)Marshal.PtrToStructure(hdrPtr, typeof(MZ.Header)); + mzHdr = (libexeinfo.MZ.Header)Marshal.PtrToStructure(hdrPtr, typeof(libexeinfo.MZ.Header)); Marshal.FreeHGlobal(hdrPtr); - if(mzHdr.signature == MZ.Consts.Signature) + if(mzHdr.signature == libexeinfo.MZ.Consts.Signature) { recognized = true; - MZ.Info.PrintInfo(mzHdr); + libexeinfo.MZ.Info.PrintInfo(mzHdr); if (mzHdr.new_offset < exeFs.Length) { exeFs.Seek(mzHdr.new_offset, SeekOrigin.Begin); - buffer = new byte[Marshal.SizeOf(typeof(NE.Header))]; + buffer = new byte[Marshal.SizeOf(typeof(libexeinfo.NE.Header))]; exeFs.Read(buffer, 0, buffer.Length); hdrPtr = Marshal.AllocHGlobal(buffer.Length); Marshal.Copy(buffer, 0, hdrPtr, buffer.Length); - neHdr = (NE.Header)Marshal.PtrToStructure(hdrPtr, typeof(NE.Header)); + neHdr = (libexeinfo.NE.Header)Marshal.PtrToStructure(hdrPtr, typeof(libexeinfo.NE.Header)); Marshal.FreeHGlobal(hdrPtr); - if (neHdr.signature == NE.Consts.Signature) + if (neHdr.signature == libexeinfo.NE.Consts.Signature) { - NE.Info.PrintInfo(neHdr); - NE.ResourceTable resources = NE.Info.GetResources(exeFs, mzHdr.new_offset, neHdr.resource_table_offset); - foreach(NE.ResourceType type in resources.types) + libexeinfo.NE.Info.PrintInfo(neHdr); + libexeinfo.NE.ResourceTable resources = libexeinfo.NE.Info.GetResources(exeFs, mzHdr.new_offset, neHdr.resource_table_offset); + foreach(libexeinfo.NE.ResourceType type in resources.types) { - if((type.id & 0x7FFF) == (int)NE.ResourceTypes.RT_VERSION) + if((type.id & 0x7FFF) == (int)libexeinfo.NE.ResourceTypes.RT_VERSION) { - foreach(NE.Resource resource in type.resources) + foreach(libexeinfo.NE.Resource resource in type.resources) { - NE.Version vers = new NE.Version(resource.data); + libexeinfo.NE.Version vers = new libexeinfo.NE.Version(resource.data); Console.WriteLine("\tVersion resource {0}:", resource.name); Console.WriteLine("\t\tFile version: {0}", vers.FileVersion); Console.WriteLine("\t\tProduct version: {0}", vers.ProductVersion); - Console.WriteLine("\t\tFile type: {0}", NE.Version.TypeToString(vers.FileType)); - if(vers.FileType == NE.VersionFileType.VFT_DRV) - Console.WriteLine("\t\tFile subtype: {0} driver", NE.Version.DriverToString(vers.FileSubtype)); - else if (vers.FileType == NE.VersionFileType.VFT_DRV) - Console.WriteLine("\t\tFile subtype: {0} font", NE.Version.FontToString(vers.FileSubtype)); + Console.WriteLine("\t\tFile type: {0}", libexeinfo.NE.Version.TypeToString(vers.FileType)); + if(vers.FileType == libexeinfo.NE.VersionFileType.VFT_DRV) + Console.WriteLine("\t\tFile subtype: {0} driver", libexeinfo.NE.Version.DriverToString(vers.FileSubtype)); + else if (vers.FileType == libexeinfo.NE.VersionFileType.VFT_DRV) + Console.WriteLine("\t\tFile subtype: {0} font", libexeinfo.NE.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}", NE.Version.OsToString(vers.FileOS)); + Console.WriteLine("\t\tFile OS: {0}", libexeinfo.NE.Version.OsToString(vers.FileOS)); foreach (KeyValuePair> strByLang in vers.StringsByLanguage) { diff --git a/exeinfo/exeinfo.csproj b/exeinfo/exeinfo.csproj index 4d53ed9..36eecd0 100644 --- a/exeinfo/exeinfo.csproj +++ b/exeinfo/exeinfo.csproj @@ -34,18 +34,12 @@ - - - - - - - - - - + + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0} + libexeinfo + \ No newline at end of file diff --git a/exeinfo/MZ/Consts.cs b/libexeinfo/MZ/Consts.cs similarity index 80% rename from exeinfo/MZ/Consts.cs rename to libexeinfo/MZ/Consts.cs index efb1e4e..ae0696f 100644 --- a/exeinfo/MZ/Consts.cs +++ b/libexeinfo/MZ/Consts.cs @@ -1,5 +1,5 @@ using System; -namespace exeinfo.MZ +namespace libexeinfo.MZ { public class Consts { diff --git a/exeinfo/MZ/Info.cs b/libexeinfo/MZ/Info.cs similarity index 98% rename from exeinfo/MZ/Info.cs rename to libexeinfo/MZ/Info.cs index 89ae317..6b4f72b 100644 --- a/exeinfo/MZ/Info.cs +++ b/libexeinfo/MZ/Info.cs @@ -1,5 +1,5 @@ using System; -namespace exeinfo.MZ +namespace libexeinfo.MZ { public class Info { diff --git a/exeinfo/MZ/Structs.cs b/libexeinfo/MZ/Structs.cs similarity index 97% rename from exeinfo/MZ/Structs.cs rename to libexeinfo/MZ/Structs.cs index 19085dd..f074677 100644 --- a/exeinfo/MZ/Structs.cs +++ b/libexeinfo/MZ/Structs.cs @@ -1,6 +1,6 @@ using System.Runtime.InteropServices; -namespace exeinfo.MZ +namespace libexeinfo.MZ { [StructLayout(LayoutKind.Sequential, Pack = 1)] public struct Header diff --git a/exeinfo/NE/Consts.cs b/libexeinfo/NE/Consts.cs similarity index 98% rename from exeinfo/NE/Consts.cs rename to libexeinfo/NE/Consts.cs index 8754432..8307dac 100644 --- a/exeinfo/NE/Consts.cs +++ b/libexeinfo/NE/Consts.cs @@ -1,6 +1,6 @@ using System; using System.ComponentModel; -namespace exeinfo.NE +namespace libexeinfo.NE { public static class Consts { diff --git a/exeinfo/NE/Enums.cs b/libexeinfo/NE/Enums.cs similarity index 99% rename from exeinfo/NE/Enums.cs rename to libexeinfo/NE/Enums.cs index 6e02791..8456550 100644 --- a/exeinfo/NE/Enums.cs +++ b/libexeinfo/NE/Enums.cs @@ -1,5 +1,5 @@ using System; -namespace exeinfo.NE +namespace libexeinfo.NE { [Flags] public enum ProgramFlags : byte diff --git a/exeinfo/NE/Info.cs b/libexeinfo/NE/Info.cs similarity index 99% rename from exeinfo/NE/Info.cs rename to libexeinfo/NE/Info.cs index 25f4a60..8e70b29 100644 --- a/exeinfo/NE/Info.cs +++ b/libexeinfo/NE/Info.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text; -namespace exeinfo.NE +namespace libexeinfo.NE { public class Info { diff --git a/exeinfo/NE/Structs.cs b/libexeinfo/NE/Structs.cs similarity index 98% rename from exeinfo/NE/Structs.cs rename to libexeinfo/NE/Structs.cs index d9244cf..9ac7210 100644 --- a/exeinfo/NE/Structs.cs +++ b/libexeinfo/NE/Structs.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; -namespace exeinfo.NE +namespace libexeinfo.NE { [StructLayout(LayoutKind.Sequential/*, Pack = 2*/)] public struct Header diff --git a/exeinfo/NE/Version.cs b/libexeinfo/NE/Version.cs similarity index 99% rename from exeinfo/NE/Version.cs rename to libexeinfo/NE/Version.cs index ee707ae..f6595fb 100644 --- a/exeinfo/NE/Version.cs +++ b/libexeinfo/NE/Version.cs @@ -4,7 +4,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Text; -namespace exeinfo.NE +namespace libexeinfo.NE { public class Version { diff --git a/libexeinfo/Properties/AssemblyInfo.cs b/libexeinfo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..32e3943 --- /dev/null +++ b/libexeinfo/Properties/AssemblyInfo.cs @@ -0,0 +1,26 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("libexeinfo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Claunia.com")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright © Claunia.com")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] diff --git a/libexeinfo/libexeinfo.csproj b/libexeinfo/libexeinfo.csproj new file mode 100644 index 0000000..b2360bf --- /dev/null +++ b/libexeinfo/libexeinfo.csproj @@ -0,0 +1,71 @@ + + + + + Debug + AnyCPU + {5DD22357-AEA1-4B1D-9CAB-F51873A3A5D0} + Library + libexeinfo + libexeinfo + v4.6 + true + libexeinfo + 0.1 + Natalia Portillo + Natalia Portillo + Library to get information about executable files. + libexeinfo + Library to get information about executable files. + + + true + full + false + bin\Debug + DEBUG; + prompt + 4 + false + + + true + bin\Release + prompt + 4 + bin\Release\libexeinfo.xml + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/libexeinfo/packages.config b/libexeinfo/packages.config new file mode 100644 index 0000000..7600cbc --- /dev/null +++ b/libexeinfo/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file