From 249161a3a3c3c6154d16bb716488478d56144467 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Tue, 6 Mar 2018 17:55:47 +0000 Subject: [PATCH] Separated common operating system structures from executable format to their own namespace. --- exeinfogui/Os2/PanelOs2Bitmap.xeto.cs | 15 ++- exeinfogui/Windows/PanelWindowsIcon.xeto.cs | 2 +- iconviewer/iconviewer/MainForm.xeto.cs | 11 +- libexeinfo/NE/Consts.cs | 44 ++++--- libexeinfo/NE/Enums.cs | 98 -------------- libexeinfo/NE/Info.cs | 9 +- libexeinfo/NE/NE.cs | 3 +- libexeinfo/NE/Structs.cs | 69 +--------- libexeinfo/Os2/Bitmap.cs | 68 ++-------- libexeinfo/Os2/Enums.cs | 128 ++++++++++++++++++ libexeinfo/Os2/Structs.cs | 138 ++++++++++++++++++++ libexeinfo/Windows/Bitmap.cs | 59 +-------- libexeinfo/Windows/Enums.cs | 42 ++++++ libexeinfo/Windows/Structs.cs | 63 +++++++++ libexeinfo/libexeinfo.csproj | 4 + 15 files changed, 439 insertions(+), 314 deletions(-) create mode 100644 libexeinfo/Os2/Enums.cs create mode 100644 libexeinfo/Os2/Structs.cs create mode 100644 libexeinfo/Windows/Enums.cs create mode 100644 libexeinfo/Windows/Structs.cs diff --git a/exeinfogui/Os2/PanelOs2Bitmap.xeto.cs b/exeinfogui/Os2/PanelOs2Bitmap.xeto.cs index 6e24930..02dd2fd 100644 --- a/exeinfogui/Os2/PanelOs2Bitmap.xeto.cs +++ b/exeinfogui/Os2/PanelOs2Bitmap.xeto.cs @@ -2,6 +2,7 @@ using Eto.Drawing; using Eto.Forms; using Eto.Serialization.Xaml; +using libexeinfo.Os2; using Bitmap = libexeinfo.Os2.Bitmap; namespace exeinfogui.Os2 @@ -25,7 +26,7 @@ namespace exeinfogui.Os2 grdIcons.Columns.Add(new GridColumn { DataCell = - new TextBoxCell {Binding = Binding.Property(b => $"{b.Type}")}, + new TextBoxCell {Binding = Binding.Property(b => $"{b.Type}")}, HeaderText = "Command" }); @@ -33,7 +34,7 @@ namespace exeinfogui.Os2 { DataCell = new TextBoxCell { - Binding = Binding.Property(b => $"{b.Width}x{b.Height}") + Binding = Binding.Property(b => $"{b.Width}x{b.Height}") }, HeaderText = "Size" }); @@ -42,7 +43,7 @@ namespace exeinfogui.Os2 { DataCell = new TextBoxCell { - Binding = Binding.Property(b => $"{1 << (int)b.BitsPerPixel}") + Binding = Binding.Property(b => $"{1 << (int)b.BitsPerPixel}") }, HeaderText = "Colors" }); @@ -55,7 +56,7 @@ namespace exeinfogui.Os2 void GrdIconsOnSelectionChanged(object sender, EventArgs eventArgs) { - if(!(grdIcons.SelectedItem is Bitmap.DecodedBitmap icon)) + if(!(grdIcons.SelectedItem is DecodedBitmap icon)) { imgIcon.Image = null; return; @@ -84,12 +85,12 @@ namespace exeinfogui.Os2 return; } - Bitmap.DecodedBitmap[] icons = Bitmap.DecodeBitmap(data); + DecodedBitmap[] icons = Bitmap.DecodeBitmap(data); if(icons == null || icons.Length == 0) try { - libexeinfo.Windows.Bitmap.DecodedBitmap winIcon = null; + libexeinfo.Windows.DecodedBitmap winIcon = null; if(BitConverter.ToUInt32(data, 4) == 40) { @@ -103,7 +104,7 @@ namespace exeinfogui.Os2 if(winIcon != null) icons = new[] { - new Bitmap.DecodedBitmap + new DecodedBitmap { BitsPerPixel = winIcon.BitsPerPixel, Height = winIcon.Height, diff --git a/exeinfogui/Windows/PanelWindowsIcon.xeto.cs b/exeinfogui/Windows/PanelWindowsIcon.xeto.cs index c3449f4..765c1b2 100644 --- a/exeinfogui/Windows/PanelWindowsIcon.xeto.cs +++ b/exeinfogui/Windows/PanelWindowsIcon.xeto.cs @@ -36,7 +36,7 @@ namespace exeinfogui.Windows return; } - Bitmap.DecodedBitmap icon; + libexeinfo.Windows.DecodedBitmap icon; try { icon = Bitmap.DecodeIcon(data); } catch { icon = null; } diff --git a/iconviewer/iconviewer/MainForm.xeto.cs b/iconviewer/iconviewer/MainForm.xeto.cs index cfab357..9504843 100644 --- a/iconviewer/iconviewer/MainForm.xeto.cs +++ b/iconviewer/iconviewer/MainForm.xeto.cs @@ -3,6 +3,7 @@ using System.IO; using Eto.Drawing; using Eto.Forms; using Eto.Serialization.Xaml; +using libexeinfo.Os2; using Bitmap = libexeinfo.Os2.Bitmap; namespace iconviewer @@ -20,7 +21,7 @@ namespace iconviewer grdIcons.Columns.Add(new GridColumn { DataCell = - new TextBoxCell {Binding = Binding.Property(b => $"{b.Type}")}, + new TextBoxCell {Binding = Binding.Property(b => $"{b.Type}")}, HeaderText = "Command" }); @@ -28,7 +29,7 @@ namespace iconviewer { DataCell = new TextBoxCell { - Binding = Binding.Property(b => $"{b.Width}x{b.Height}") + Binding = Binding.Property(b => $"{b.Width}x{b.Height}") }, HeaderText = "Size" }); @@ -37,7 +38,7 @@ namespace iconviewer { DataCell = new TextBoxCell { - Binding = Binding.Property(b => $"{1 << (int)b.BitsPerPixel}") + Binding = Binding.Property(b => $"{1 << (int)b.BitsPerPixel}") }, HeaderText = "Colors" }); @@ -48,7 +49,7 @@ namespace iconviewer void GrdIconsOnSelectionChanged(object sender, EventArgs eventArgs) { - if(!(grdIcons.SelectedItem is Bitmap.DecodedBitmap icon)) + if(!(grdIcons.SelectedItem is DecodedBitmap icon)) { imgIcon.Image = null; return; @@ -78,7 +79,7 @@ namespace iconviewer fstream.Read(data, 0, data.Length); fstream.Dispose(); - Bitmap.DecodedBitmap[] icons = Bitmap.DecodeBitmap(data); + DecodedBitmap[] icons = Bitmap.DecodeBitmap(data); imgIcon.Image = new Eto.Drawing.Bitmap((int)icons[0].Width, (int)icons[0].Height, PixelFormat.Format32bppRgba, icons[0].Pixels); grdIcons.DataStore = icons; diff --git a/libexeinfo/NE/Consts.cs b/libexeinfo/NE/Consts.cs index 062174b..a9600c5 100644 --- a/libexeinfo/NE/Consts.cs +++ b/libexeinfo/NE/Consts.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. +using libexeinfo.Os2; + namespace libexeinfo { public partial class NE @@ -95,27 +97,27 @@ namespace libexeinfo { switch(id) { - case (int)Os2ResourceTypes.RT_POINTER: return "RT_POINTER"; - case (int)Os2ResourceTypes.RT_BITMAP: return "RT_BITMAP"; - case (int)Os2ResourceTypes.RT_MENU: return "RT_MENU"; - case (int)Os2ResourceTypes.RT_DIALOG: return "RT_DIALOG"; - case (int)Os2ResourceTypes.RT_STRING: return "RT_STRING"; - case (int)Os2ResourceTypes.RT_FONTDIR: return "RT_FONTDIR"; - case (int)Os2ResourceTypes.RT_FONT: return "RT_FONT"; - case (int)Os2ResourceTypes.RT_ACCELTABLE: return "RT_ACCELTABLE"; - case (int)Os2ResourceTypes.RT_RCDATA: return "RT_RCDATA"; - case (int)Os2ResourceTypes.RT_MESSAGE: return "RT_MESSAGE"; - case (int)Os2ResourceTypes.RT_DLGINCLUDE: return "RT_DLGINCLUDE"; - case (int)Os2ResourceTypes.RT_VKEYTBL: return "RT_VKEYTBL"; - case (int)Os2ResourceTypes.RT_KEYTBL: return "RT_KEYTBL"; - case (int)Os2ResourceTypes.RT_CHARTBL: return "RT_CHARTBL"; - case (int)Os2ResourceTypes.RT_DISPLAYINFO: return "RT_DISPLAYINFO"; - case (int)Os2ResourceTypes.RT_FKASHORT: return "RT_FKASHORT"; - case (int)Os2ResourceTypes.RT_FKALONG: return "RT_FKALONG"; - case (int)Os2ResourceTypes.RT_HELPTABLE: return "RT_HELPTABLE"; - case (int)Os2ResourceTypes.RT_HELPSUBTABLE: return "RT_HELPSUBTABLE"; - case (int)Os2ResourceTypes.RT_FDDIR: return "RT_FDDIR"; - case (int)Os2ResourceTypes.RT_FD: return "RT_FD"; + case (int)Os2.ResourceTypes.RT_POINTER: return "RT_POINTER"; + case (int)Os2.ResourceTypes.RT_BITMAP: return "RT_BITMAP"; + case (int)Os2.ResourceTypes.RT_MENU: return "RT_MENU"; + case (int)Os2.ResourceTypes.RT_DIALOG: return "RT_DIALOG"; + case (int)Os2.ResourceTypes.RT_STRING: return "RT_STRING"; + case (int)Os2.ResourceTypes.RT_FONTDIR: return "RT_FONTDIR"; + case (int)Os2.ResourceTypes.RT_FONT: return "RT_FONT"; + case (int)Os2.ResourceTypes.RT_ACCELTABLE: return "RT_ACCELTABLE"; + case (int)Os2.ResourceTypes.RT_RCDATA: return "RT_RCDATA"; + case (int)Os2.ResourceTypes.RT_MESSAGE: return "RT_MESSAGE"; + case (int)Os2.ResourceTypes.RT_DLGINCLUDE: return "RT_DLGINCLUDE"; + case (int)Os2.ResourceTypes.RT_VKEYTBL: return "RT_VKEYTBL"; + case (int)Os2.ResourceTypes.RT_KEYTBL: return "RT_KEYTBL"; + case (int)Os2.ResourceTypes.RT_CHARTBL: return "RT_CHARTBL"; + case (int)Os2.ResourceTypes.RT_DISPLAYINFO: return "RT_DISPLAYINFO"; + case (int)Os2.ResourceTypes.RT_FKASHORT: return "RT_FKASHORT"; + case (int)Os2.ResourceTypes.RT_FKALONG: return "RT_FKALONG"; + case (int)Os2.ResourceTypes.RT_HELPTABLE: return "RT_HELPTABLE"; + case (int)Os2.ResourceTypes.RT_HELPSUBTABLE: return "RT_HELPSUBTABLE"; + case (int)Os2.ResourceTypes.RT_FDDIR: return "RT_FDDIR"; + case (int)Os2.ResourceTypes.RT_FD: return "RT_FD"; default: return $"{id}"; } } diff --git a/libexeinfo/NE/Enums.cs b/libexeinfo/NE/Enums.cs index b0a3fb8..d250ded 100644 --- a/libexeinfo/NE/Enums.cs +++ b/libexeinfo/NE/Enums.cs @@ -43,104 +43,6 @@ namespace libexeinfo DLL = 1 << 7 } - /// - /// OS/2 flags. - /// - [Flags] - public enum OS2Flags : byte - { - LongFilename = 1 << 0, - ProtectedMode2 = 1 << 1, - ProportionalFonts = 1 << 2, - GangloadArea = 1 << 3 - } - - [Flags] - public enum Os2MenuAttribute : ushort - { - MIA_FRAMED = 0x1000, - MIA_CHECKED = 0x2000, - MIA_DISABLED = 0x4000, - MIA_HILITED = 0x8000 - } - - public enum Os2MenuType : ushort - { - MIS_TEXT = 0x0001, - MIS_BITMAP = 0x0002, - MIS_SEPARATOR = 0x0004, - MIS_OWNERDRAW = 0x0008, - MIS_SUBMENU = 0x0010, - /// - /// multiple choice submenu - /// - MIS_MULTMENU = 0x0020, - MIS_SYSCOMMAND = 0x0040, - MIS_HELP = 0x0080, - MIS_STATIC = 0x0100, - MIS_BUTTONSEPARATOR = 0x0200, - MIS_BREAK = 0x0400, - MIS_BREAKSEPARATOR = 0x0800, - /// - /// multiple choice group start - /// - MIS_GROUP = 0x1000, - /// - /// In multiple choice submenus a style of 'single' denotes the item is a radiobutton. Absence of this style defaults - /// the item to a checkbox. - /// - MIS_SINGLE = 0x2000 - } - - /// - /// Resource types. - /// - public enum Os2ResourceTypes : ushort - { - /// mouse pointer shape - RT_POINTER = 1, - /// bitmap - RT_BITMAP = 2, - /// menu template - RT_MENU = 3, - /// dialog template - RT_DIALOG = 4, - /// string tables - RT_STRING = 5, - /// font directory - RT_FONTDIR = 6, - /// font - RT_FONT = 7, - /// accelerator tables - RT_ACCELTABLE = 8, - /// binary data - RT_RCDATA = 9, - /// error msg tables - RT_MESSAGE = 10, - /// dialog include file name - RT_DLGINCLUDE = 11, - /// key to vkey tables - RT_VKEYTBL = 12, - /// key to UGL tables - RT_KEYTBL = 13, - /// glyph to character tables - RT_CHARTBL = 14, - /// screen display information - RT_DISPLAYINFO = 15, - /// function key area short form - RT_FKASHORT = 16, - /// function key area long form - RT_FKALONG = 17, - /// Help table for IPFC - RT_HELPTABLE = 18, - /// Help subtable for IPFC - RT_HELPSUBTABLE = 19, - /// DBCS uniq/font driver directory - RT_FDDIR = 20, - /// DBCS uniq/font driver - RT_FD = 21 - } - /// /// Program flags. /// diff --git a/libexeinfo/NE/Info.cs b/libexeinfo/NE/Info.cs index 016143e..35d2517 100644 --- a/libexeinfo/NE/Info.cs +++ b/libexeinfo/NE/Info.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; +using libexeinfo.Os2; namespace libexeinfo { @@ -87,13 +88,13 @@ namespace libexeinfo else if(Header.application_flags.HasFlag(ApplicationFlags.FullScreen) && Header.application_flags.HasFlag(ApplicationFlags.GUICompatible)) sb.AppendLine("\tApplication uses Presentation Manager"); - if(Header.os2_flags.HasFlag(OS2Flags.LongFilename)) + if(Header.ExecutableFlags.HasFlag(ExecutableFlags.LongFilename)) sb.AppendLine("\tApplication supports long filenames"); - if(Header.os2_flags.HasFlag(OS2Flags.ProtectedMode2)) + if(Header.ExecutableFlags.HasFlag(ExecutableFlags.ProtectedMode2)) sb.AppendLine("\tApplication uses OS/2 2.x protected mode"); - if(Header.os2_flags.HasFlag(OS2Flags.ProportionalFonts)) + if(Header.ExecutableFlags.HasFlag(ExecutableFlags.ProportionalFonts)) sb.AppendLine("\tApplication uses OS/2 2.x proportional fonts"); - if(Header.os2_flags.HasFlag(OS2Flags.GangloadArea)) + if(Header.ExecutableFlags.HasFlag(ExecutableFlags.GangloadArea)) sb.AppendFormat("\tGangload area starts at {0} an runs for {1} bytes", Header.return_thunks_offset, Header.segment_reference_thunks).AppendLine(); else diff --git a/libexeinfo/NE/NE.cs b/libexeinfo/NE/NE.cs index 84b9fbb..87f0a57 100644 --- a/libexeinfo/NE/NE.cs +++ b/libexeinfo/NE/NE.cs @@ -30,6 +30,7 @@ using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; +using libexeinfo.Os2; namespace libexeinfo { @@ -246,7 +247,7 @@ namespace libexeinfo BaseStream.Position = BaseExecutable.Header.new_offset + Header.resource_table_offset; buffer = new byte[Header.resource_entries * 4]; BaseStream.Read(buffer, 0, buffer.Length); - Os2ResourceTableEntry[] entries = new Os2ResourceTableEntry[Header.resource_entries]; + ResourceTableEntry[] entries = new ResourceTableEntry[Header.resource_entries]; for(int i = 0; i < entries.Length; i++) { entries[i].etype = BitConverter.ToUInt16(buffer, i * 4 + 0); diff --git a/libexeinfo/NE/Structs.cs b/libexeinfo/NE/Structs.cs index 4e27e9a..ebe868e 100644 --- a/libexeinfo/NE/Structs.cs +++ b/libexeinfo/NE/Structs.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System.Runtime.InteropServices; +using libexeinfo.Os2; namespace libexeinfo { @@ -62,7 +63,7 @@ namespace libexeinfo public ushort alignment_shift; public ushort resource_entries; public TargetOS target_os; - public OS2Flags os2_flags; + public ExecutableFlags ExecutableFlags; public ushort return_thunks_offset; public ushort segment_reference_thunks; public ushort minimum_swap_area; @@ -167,7 +168,7 @@ namespace libexeinfo /// public ushort dwSegmentLength; /// - /// Flag word, , , + /// Flag word, , , /// , /// public ushort dwFlags; @@ -176,69 +177,5 @@ namespace libexeinfo /// public ushort dwMinimumAllocation; } - - [StructLayout(LayoutKind.Sequential)] - public struct Os2ResourceTableEntry - { - public ushort etype; - public ushort ename; - } - - [StructLayout(LayoutKind.Sequential)] - public struct Os2MenuHeader - { - public ushort cb; - public ushort type; - public ushort cp; - public ushort offset; - public ushort count; - } - - /// - /// Followed by data, if is a null-terminated - /// string follows, if a resource ID follows and if - /// another header follows. - /// - [StructLayout(LayoutKind.Sequential)] - public struct Os2MenuItem - { - public Os2MenuType style; - public Os2MenuAttribute attrib; - public ushort id; - } - - [StructLayout(LayoutKind.Sequential)] - public struct Os2DialogTemplateItem - { - public ushort fsItemStatus; - public ushort cChildren; - public ushort cchClassName; - public ushort offClassName; - public ushort cchText; - public ushort offText; - public uint flStyle; - public short x; - public short y; - public short cx; - public short cy; - public ushort id; - public ushort offPresParams; - public ushort offCtlData; - } - - /// - /// Dialog template, followed by several - /// - [StructLayout(LayoutKind.Sequential)] - public struct Os2DialogTemplate - { - public ushort cbTemplate; - public ushort type; - public ushort codepage; - public ushort offadlgti; - public ushort fsTemplateStatus; - public ushort iItemFocus; - public ushort coffPresParams; - } } } \ No newline at end of file diff --git a/libexeinfo/Os2/Bitmap.cs b/libexeinfo/Os2/Bitmap.cs index 402540a..bd2aff3 100644 --- a/libexeinfo/Os2/Bitmap.cs +++ b/libexeinfo/Os2/Bitmap.cs @@ -31,7 +31,7 @@ using System.Runtime.InteropServices; namespace libexeinfo.Os2 { - public class Bitmap + public static class Bitmap { /// /// 'IC', OS/2 only, icon @@ -69,13 +69,8 @@ namespace libexeinfo.Os2 { long pos = 0; BitmapArrayHeader bitmapArrayHeader; - BitmapInfoHeader bitmapFileHeader; byte[] buffer = new byte[Marshal.SizeOf(typeof(BitmapInfoHeader))]; - Array.Copy(data, pos, buffer, 0, buffer.Length); - bitmapArrayHeader = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); - bitmapFileHeader = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); - List bitmaps = new List(); do @@ -100,7 +95,8 @@ namespace libexeinfo.Os2 { buffer = new byte[Marshal.SizeOf(typeof(BitmapInfoHeader))]; Array.Copy(data, pos, buffer, 0, buffer.Length); - bitmapFileHeader = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); + BitmapInfoHeader bitmapFileHeader = + BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); // Stop at unknown header if(bitmapFileHeader.Fix != 12) break; @@ -110,13 +106,13 @@ namespace libexeinfo.Os2 // TODO: Non paletted? pos += Marshal.SizeOf(typeof(BitmapInfoHeader)); - RGB[] palette = new RGB[1 << bitmapFileHeader.BitsPerPlane]; - buffer = new byte[Marshal.SizeOf(typeof(RGB))]; + Rgb[] palette = new Rgb[1 << bitmapFileHeader.BitsPerPlane]; + buffer = new byte[Marshal.SizeOf(typeof(Rgb))]; for(int i = 0; i < palette.Length; i++) { Array.Copy(data, pos, buffer, 0, buffer.Length); pos += buffer.Length; - palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); + palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); } remaining -= bitmapFileHeader.Fix; @@ -179,13 +175,13 @@ namespace libexeinfo.Os2 // TODO: Non paletted? pos += bitmapFileHeader.Size; - palette = new RGB[1 << bitmapFileHeader.BitsPerPlane]; - buffer = new byte[Marshal.SizeOf(typeof(RGB))]; + palette = new Rgb[1 << bitmapFileHeader.BitsPerPlane]; + buffer = new byte[Marshal.SizeOf(typeof(Rgb))]; for(int i = 0; i < palette.Length; i++) { Array.Copy(data, pos, buffer, 0, buffer.Length); pos += buffer.Length; - palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); + palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); } remaining -= bitmapFileHeader.Fix; @@ -242,7 +238,7 @@ namespace libexeinfo.Os2 } // TODO: Mask is not correctly decoded on XGA icons (20x20 and 40x40)... - static DecodedBitmap DecodeBitmap(BitmapInfoHeader header, IList palette, byte[] data) + static DecodedBitmap DecodeBitmap(BitmapInfoHeader header, IList palette, byte[] data) { DecodedBitmap bitmap = new DecodedBitmap { @@ -303,49 +299,5 @@ namespace libexeinfo.Os2 return bitmap; } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct BitmapArrayHeader - { - public ushort Type; - public uint Size; - public uint Next; - public ushort XDisplay; - public ushort YDisplay; - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct BitmapInfoHeader - { - public ushort Type; - public uint Size; - public short XHotspot; - public short YHostpot; - public uint Offset; - public uint Fix; - public ushort X; - public ushort Y; - public ushort Planes; - public ushort BitsPerPlane; - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct RGB - { - public byte Blue; - public byte Green; - public byte Red; - } - - public class DecodedBitmap - { - public uint BitsPerPixel; - public uint Height; - public int[] Pixels; - public string Type; - public uint Width; - public short XHotspot; - public short YHostpot; - } } } \ No newline at end of file diff --git a/libexeinfo/Os2/Enums.cs b/libexeinfo/Os2/Enums.cs new file mode 100644 index 0000000..382cb94 --- /dev/null +++ b/libexeinfo/Os2/Enums.cs @@ -0,0 +1,128 @@ +// +// Enums.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2017 Copyright © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; + +namespace libexeinfo.Os2 +{ + /// + /// OS/2 flags. + /// + [Flags] + public enum ExecutableFlags : byte + { + LongFilename = 1 << 0, + ProtectedMode2 = 1 << 1, + ProportionalFonts = 1 << 2, + GangloadArea = 1 << 3 + } + + [Flags] + public enum MenuAttribute : ushort + { + MIA_FRAMED = 0x1000, + MIA_CHECKED = 0x2000, + MIA_DISABLED = 0x4000, + MIA_HILITED = 0x8000 + } + + public enum MenuType : ushort + { + MIS_TEXT = 0x0001, + MIS_BITMAP = 0x0002, + MIS_SEPARATOR = 0x0004, + MIS_OWNERDRAW = 0x0008, + MIS_SUBMENU = 0x0010, + /// + /// multiple choice submenu + /// + MIS_MULTMENU = 0x0020, + MIS_SYSCOMMAND = 0x0040, + MIS_HELP = 0x0080, + MIS_STATIC = 0x0100, + MIS_BUTTONSEPARATOR = 0x0200, + MIS_BREAK = 0x0400, + MIS_BREAKSEPARATOR = 0x0800, + /// + /// multiple choice group start + /// + MIS_GROUP = 0x1000, + /// + /// In multiple choice submenus a style of 'single' denotes the item is a radiobutton. Absence of this style defaults + /// the item to a checkbox. + /// + MIS_SINGLE = 0x2000 + } + + /// + /// Resource types. + /// + public enum ResourceTypes : ushort + { + /// mouse pointer shape + RT_POINTER = 1, + /// bitmap + RT_BITMAP = 2, + /// menu template + RT_MENU = 3, + /// dialog template + RT_DIALOG = 4, + /// string tables + RT_STRING = 5, + /// font directory + RT_FONTDIR = 6, + /// font + RT_FONT = 7, + /// accelerator tables + RT_ACCELTABLE = 8, + /// binary data + RT_RCDATA = 9, + /// error msg tables + RT_MESSAGE = 10, + /// dialog include file name + RT_DLGINCLUDE = 11, + /// key to vkey tables + RT_VKEYTBL = 12, + /// key to UGL tables + RT_KEYTBL = 13, + /// glyph to character tables + RT_CHARTBL = 14, + /// screen display information + RT_DISPLAYINFO = 15, + /// function key area short form + RT_FKASHORT = 16, + /// function key area long form + RT_FKALONG = 17, + /// Help table for IPFC + RT_HELPTABLE = 18, + /// Help subtable for IPFC + RT_HELPSUBTABLE = 19, + /// DBCS uniq/font driver directory + RT_FDDIR = 20, + /// DBCS uniq/font driver + RT_FD = 21 + } +} \ No newline at end of file diff --git a/libexeinfo/Os2/Structs.cs b/libexeinfo/Os2/Structs.cs new file mode 100644 index 0000000..0f69e14 --- /dev/null +++ b/libexeinfo/Os2/Structs.cs @@ -0,0 +1,138 @@ +// +// Structs.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2017 Copyright © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Runtime.InteropServices; + +namespace libexeinfo.Os2 +{ + [StructLayout(LayoutKind.Sequential)] + public struct ResourceTableEntry + { + public ushort etype; + public ushort ename; + } + + [StructLayout(LayoutKind.Sequential)] + public struct MenuHeader + { + public ushort cb; + public ushort type; + public ushort cp; + public ushort offset; + public ushort count; + } + + /// + /// Followed by data, if is a null-terminated + /// string follows, if a resource ID follows and if + /// another header follows. + /// + [StructLayout(LayoutKind.Sequential)] + public struct MenuItem + { + public MenuType style; + public MenuAttribute attrib; + public ushort id; + } + + [StructLayout(LayoutKind.Sequential)] + public struct DialogTemplateItem + { + public ushort fsItemStatus; + public ushort cChildren; + public ushort cchClassName; + public ushort offClassName; + public ushort cchText; + public ushort offText; + public uint flStyle; + public short x; + public short y; + public short cx; + public short cy; + public ushort id; + public ushort offPresParams; + public ushort offCtlData; + } + + /// + /// Dialog template, followed by several + /// + [StructLayout(LayoutKind.Sequential)] + public struct DialogTemplate + { + public ushort cbTemplate; + public ushort type; + public ushort codepage; + public ushort offadlgti; + public ushort fsTemplateStatus; + public ushort iItemFocus; + public ushort coffPresParams; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct BitmapArrayHeader + { + public ushort Type; + public uint Size; + public uint Next; + public ushort XDisplay; + public ushort YDisplay; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct BitmapInfoHeader + { + public ushort Type; + public uint Size; + public short XHotspot; + public short YHostpot; + public uint Offset; + public uint Fix; + public ushort X; + public ushort Y; + public ushort Planes; + public ushort BitsPerPlane; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct Rgb + { + public byte Blue; + public byte Green; + public byte Red; + } + + public class DecodedBitmap + { + public uint BitsPerPixel; + public uint Height; + public int[] Pixels; + public string Type; + public uint Width; + public short XHotspot; + public short YHostpot; + } +} \ No newline at end of file diff --git a/libexeinfo/Windows/Bitmap.cs b/libexeinfo/Windows/Bitmap.cs index 14624db..1824785 100644 --- a/libexeinfo/Windows/Bitmap.cs +++ b/libexeinfo/Windows/Bitmap.cs @@ -31,22 +31,8 @@ using System.Runtime.InteropServices; namespace libexeinfo.Windows { - public class Bitmap + public static class Bitmap { - public enum Compression : uint - { - None = 0, - Rle8 = 1, - Rle4 = 2, - Bitfields = 3, - Jpeg = 4, - Png = 5, - AlphaBitfields = 6, - Cmyk = 11, - CmykRle8 = 12, - CmykRle4 = 13 - } - const int VISIBLE = -16777216; /// @@ -70,13 +56,13 @@ namespace libexeinfo.Windows // TODO: Non paletted? pos += bitmapFileHeader.HeaderSize; - RGB[] palette = new RGB[1 << bitmapFileHeader.BitsPerPlane]; - buffer = new byte[Marshal.SizeOf(typeof(RGB))]; + Rgb[] palette = new Rgb[1 << bitmapFileHeader.BitsPerPlane]; + buffer = new byte[Marshal.SizeOf(typeof(Rgb))]; for(int i = 0; i < palette.Length; i++) { Array.Copy(data, pos, buffer, 0, buffer.Length); pos += buffer.Length; - palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); + palette[i] = BigEndianMarshal.ByteArrayToStructureLittleEndian(buffer); } // First let's do the icon itself @@ -147,9 +133,9 @@ namespace libexeinfo.Windows return bitmap; } - static DecodedBitmap DecodeBitmap(BitmapInfoHeader header, IList palette, byte[] data) + static DecodedBitmap DecodeBitmap(BitmapInfoHeader header, IList palette, byte[] data) { - if(header.Compression != Compression.None) return null; + if(header.BitmapCompression != BitmapCompression.None) return null; DecodedBitmap bitmap = new DecodedBitmap { @@ -188,38 +174,5 @@ namespace libexeinfo.Windows return bitmap; } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct BitmapInfoHeader - { - public uint HeaderSize; - public uint Width; - public uint Height; - public ushort Planes; - public ushort BitsPerPlane; - public Compression Compression; - public uint ImageSize; - public uint HorizontalResolution; - public uint VerticalResolution; - public uint ColorsInPalette; - public uint ImportantColors; - } - - [StructLayout(LayoutKind.Sequential, Pack = 1)] - public struct RGB - { - public byte Blue; - public byte Green; - public byte Red; - public byte Reserved; - } - - public class DecodedBitmap - { - public uint BitsPerPixel; - public uint Height; - public int[] Pixels; - public uint Width; - } } } \ No newline at end of file diff --git a/libexeinfo/Windows/Enums.cs b/libexeinfo/Windows/Enums.cs new file mode 100644 index 0000000..e64833d --- /dev/null +++ b/libexeinfo/Windows/Enums.cs @@ -0,0 +1,42 @@ +// +// Enums.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2017 Copyright © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +namespace libexeinfo.Windows +{ + public enum BitmapCompression : uint + { + None = 0, + Rle8 = 1, + Rle4 = 2, + Bitfields = 3, + Jpeg = 4, + Png = 5, + AlphaBitfields = 6, + Cmyk = 11, + CmykRle8 = 12, + CmykRle4 = 13 + } +} \ No newline at end of file diff --git a/libexeinfo/Windows/Structs.cs b/libexeinfo/Windows/Structs.cs new file mode 100644 index 0000000..daa027c --- /dev/null +++ b/libexeinfo/Windows/Structs.cs @@ -0,0 +1,63 @@ +// +// Structs.cs +// +// Author: +// Natalia Portillo +// +// Copyright (c) 2017 Copyright © Claunia.com +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System.Runtime.InteropServices; + +namespace libexeinfo.Windows +{ + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct BitmapInfoHeader + { + public uint HeaderSize; + public uint Width; + public uint Height; + public ushort Planes; + public ushort BitsPerPlane; + public BitmapCompression BitmapCompression; + public uint ImageSize; + public uint HorizontalResolution; + public uint VerticalResolution; + public uint ColorsInPalette; + public uint ImportantColors; + } + + [StructLayout(LayoutKind.Sequential, Pack = 1)] + public struct Rgb + { + public byte Blue; + public byte Green; + public byte Red; + public byte Reserved; + } + + public class DecodedBitmap + { + public uint BitsPerPixel; + public uint Height; + public int[] Pixels; + public uint Width; + } +} \ No newline at end of file diff --git a/libexeinfo/libexeinfo.csproj b/libexeinfo/libexeinfo.csproj index cb5ef5a..c2f3912 100644 --- a/libexeinfo/libexeinfo.csproj +++ b/libexeinfo/libexeinfo.csproj @@ -59,6 +59,8 @@ + + @@ -96,6 +98,8 @@ + +