mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
patterns/ico: Add embedded BMP and PNG parsing to ICO pattern (#426)
Co-authored-by: Nik <werwolv98@gmail.com>
This commit is contained in:
@@ -4,6 +4,10 @@
|
||||
#pragma endian little
|
||||
|
||||
import std.sys;
|
||||
import std.mem;
|
||||
import std.string;
|
||||
import * from bmp as BMP;
|
||||
import * from png as PNG;
|
||||
|
||||
#pragma MIME image/vnd.microsoft.icon
|
||||
#pragma MIME image/x-icon
|
||||
@@ -23,8 +27,30 @@ struct ICONDIR {
|
||||
u16 num_images;
|
||||
};
|
||||
|
||||
struct BMPData {
|
||||
u8 data[sizeof(parent.data)] [[hidden, no_unique_address]];
|
||||
std::mem::Section section = std::mem::create_section("BMP Image " + std::string::to_string(addressof(this)));
|
||||
std::mem::set_section_size(section, sizeof(data) + 14);
|
||||
u8 headerData[14] @ 0x00 in section [[hidden]];
|
||||
headerData[0x00] = 0x42;
|
||||
headerData[0x01] = 0x4D;
|
||||
u32 size @ 0x02 in section [[hidden]];
|
||||
size = std::mem::get_section_size(section);
|
||||
std::mem::copy_value_to_section(data, section, 0x0E);
|
||||
BMP image @ 0x00 in section;
|
||||
u32 offset @ 0x0D in section [[hidden]];
|
||||
offset = addressof(image.lineData);
|
||||
};
|
||||
|
||||
struct ImageData {
|
||||
u8 data[parent.image_data_size] [[inline]];
|
||||
std::mem::Bytes<parent.image_data_size> data [[no_unique_address]];
|
||||
be u64 png_magic [[hidden, no_unique_address]];
|
||||
if (png_magic == 0x89504e470d0a1a0a) {
|
||||
PNG png_image @ $ [[inline, highlight_hidden]];
|
||||
} else {
|
||||
BMPData data [[hidden]];
|
||||
BMP bmp_image @ addressof(this) - 14 [[inline, highlight_hidden]];
|
||||
}
|
||||
};
|
||||
|
||||
struct ICONDIRENTRY {
|
||||
@@ -41,7 +67,8 @@ struct ICONDIRENTRY {
|
||||
}
|
||||
|
||||
u32 image_data_size;
|
||||
ImageData *image_data : u32;
|
||||
u32 image_data_offset;
|
||||
ImageData image_data @ image_data_offset;
|
||||
};
|
||||
|
||||
ICONDIR header @ 0x00;
|
||||
|
||||
Reference in New Issue
Block a user