From 91609bd3b4dc3198a9e9aa630ab8f5295d498edf Mon Sep 17 00:00:00 2001 From: WerWolv Date: Tue, 19 Oct 2021 20:34:09 +0200 Subject: [PATCH] patterns: Added Icon/Cursor image pattern --- README.md | 1 + patterns/ico.hexpat | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 patterns/ico.hexpat diff --git a/README.md b/README.md index 1cf7317..d61535f 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed | NRO | | `patterns/nro.hexpat` | Nintendo Switch NRO files | | Java Class | `application/x-java-applet` | `patterns/java_class.hexpat` | Java Class files | | ARM VTOR | | `patterns/arm_cm_vtor.hexpat` | ARM Cortex M Vector Table Layout | +| ICO | | `patterns/ico.hexpat` | Icon (.ico) or Cursor (.cur) files | ### Pattern Libraries diff --git a/patterns/ico.hexpat b/patterns/ico.hexpat new file mode 100644 index 0000000..9843739 --- /dev/null +++ b/patterns/ico.hexpat @@ -0,0 +1,45 @@ +#pragma endian little + +#pragma MIME image/vnd.microsoft.icon +#pragma MIME image/x-icon +#pragma MIME image/icon +#pragma MIME image/ico +#pragma MIME text/ico +#pragma MIME application/ico + +enum ImageType : u16 { + Icon = 1, + Cursor = 2 +}; + +struct ICONDIR { + u16 reserved [[hidden]]; + ImageType type; + u16 num_images; +}; + +struct ImageData { + u8 data[parent.image_data_size] [[inline]]; +}; + +struct ICONDIRENTRY { + u8 width, height; + u8 num_colors; + u8 reserved [[hidden]]; + + if (header.type == ImageType::Icon) { + u16 color_planes; + u16 bits_per_pixel; + } else if (header.type == ImageType::Cursor) { + u16 horizontal_hotspot_coordinate; + u16 vertical_hotspot_coordinate; + } + + u32 image_data_size; + ImageData *image_data : u32; +}; + +ICONDIR header @ 0x00; +ICONDIRENTRY images[header.num_images] @ $; + +std::assert(header.reserved == 0x00, "Invalid ICO header"); \ No newline at end of file