From 4fcb7196138f802b9ab7181741d42d13b3849b50 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 9 Nov 2022 14:19:23 -0800 Subject: [PATCH] Start adding PE cursor and icon resources --- .../CursorAndIconResource.cs | 40 +++++++++++++++++++ .../PortableExecutable/NewHeader.cs | 31 ++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 BurnOutSharp.Models/PortableExecutable/CursorAndIconResource.cs create mode 100644 BurnOutSharp.Models/PortableExecutable/NewHeader.cs diff --git a/BurnOutSharp.Models/PortableExecutable/CursorAndIconResource.cs b/BurnOutSharp.Models/PortableExecutable/CursorAndIconResource.cs new file mode 100644 index 00000000..921bbe71 --- /dev/null +++ b/BurnOutSharp.Models/PortableExecutable/CursorAndIconResource.cs @@ -0,0 +1,40 @@ +namespace BurnOutSharp.Models.PortableExecutable +{ + /// + /// The system handles each icon and cursor as a single file. However, these are stored in + /// .res files and in executable files as a group of icon resources or a group of cursor + /// resources. The file formats of icon and cursor resources are similar. In the .res file + /// a resource group header follows all of the individual icon or cursor group components. + /// + /// The format of each icon component closely resembles the format of the .ico file. Each + /// icon image is stored in a BITMAPINFO structure followed by the color device-independent + /// bitmap (DIB) bits of the icon's XOR mask. The monochrome DIB bits of the icon's AND + /// mask follow the color DIB bits. + /// + /// The format of each cursor component resembles the format of the .cur file. Each cursor + /// image is stored in a BITMAPINFO structure followed by the monochrome DIB bits of the + /// cursor's XOR mask, and then by the monochrome DIB bits of the cursor's AND mask. Note + /// that there is a difference in the bitmaps of the two resources: Unlike icons, cursor + /// XOR masks do not have color DIB bits. Although the bitmaps of the cursor masks are + /// monochrome and do not have DIB headers or color tables, the bits are still in DIB + /// format with respect to alignment and direction. Another significant difference + /// between cursors and icons is that cursors have a hotspot and icons do not. + /// + /// The group header for both icon and cursor resources consists of a NEWHEADER structure + /// plus one or more RESDIR structures. There is one RESDIR structure for each icon or + /// cursor. The group header contains the information an application needs to select the + /// correct icon or cursor to display. Both the group header and the data that repeats for + /// each icon or cursor in the group have a fixed length. This allows the application to + /// randomly access the information. + /// + /// + public class CursorAndIconResource + { + /// + /// Describes keyboard accelerator characteristics. + /// + public NewHeader NEWHEADER; + + // TODO: Add array of entries in the resource + } +} diff --git a/BurnOutSharp.Models/PortableExecutable/NewHeader.cs b/BurnOutSharp.Models/PortableExecutable/NewHeader.cs new file mode 100644 index 00000000..6defcd80 --- /dev/null +++ b/BurnOutSharp.Models/PortableExecutable/NewHeader.cs @@ -0,0 +1,31 @@ +using System.Runtime.InteropServices; + +namespace BurnOutSharp.Models.PortableExecutable +{ + /// + /// Contains the number of icon or cursor components in a resource group. The + /// structure definition provided here is for explanation only; it is not present + /// in any standard header file. + /// + /// + [StructLayout(LayoutKind.Sequential)] + public class NewHeader + { + /// + /// Reserved; must be zero. + /// + public ushort Reserved; + + /// + /// The resource type. This member must have one of the following values. + /// - RES_ICON (1): Icon resource type. + /// - RES_CURSOR (2): Cursor resource type. + /// + public ushort ResType; + + /// + /// The number of icon or cursor components in the resource group. + /// + public ushort ResCount; + } +}