diff --git a/README.md b/README.md index 695e312..6f0cc41 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,7 @@ Everything will immediately show up in ImHex's Content Store and gets bundled wi | ReFS | | [`patterns/refs.hexpat`](patterns/fs/refs.hexpat) | Microsoft Resilient File System | | RGBDS | | [`patterns/rgbds.hexpat`](patterns/rgbds.hexpat) | [RGBDS](https://rgbds.gbdev.io) object file format | | RPM | | [`patterns/rpm.hexpat`](patterns/rpm.hexpat) | [RPM](http://ftp.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html) package file format | +| SDB | | [`patterns/sdb.hexpat`](patterns/sdb.hexpat) | [Shim DataBase](https://learn.microsoft.com/en-us/windows/win32/devnotes/application-compatibility-database) file format | | Shell Link | `application/x-ms-shortcut` | [`patterns/lnk.hexpat`](patterns/lnk.hexpat) | Windows Shell Link file format | | shp | | [`patterns/shp.hexpat`](patterns/shp.hexpat) | ESRI shape file | | shx | | [`patterns/shx.hexpat`](patterns/shx.hexpat) | ESRI index file | diff --git a/patterns/sdb.hexpat b/patterns/sdb.hexpat new file mode 100644 index 0000000..e097c3c --- /dev/null +++ b/patterns/sdb.hexpat @@ -0,0 +1,87 @@ +#pragma description SDB File (Shim DataBase file) +#pragma author learn_more +#pragma magic [ 73 64 62 66 ] @ 0x08 +#pragma endian little + +import std.mem; +import std.io; +import std.string; +import type.base; + +enum TagType : u8 { + Null = 0x1, + Byte = 0x2, + Word = 0x3, + DWord = 0x4, + QWord = 0x5, + StringRef = 0x6, + List = 0x7, + String = 0x8, + Binary = 0x9, +}; + +bitfield TypeId { + id : 12; + type : 4; +}; + +fn get_tag(TypeId tag) { + return std::format("{:x}{:03x}", tag.type, tag.id); +}; + +fn get_type(TypeId tag) { + TagType tmp = tag.type; + str name = std::format("{}", tmp); + u32 len = std::string::length(name); + return std::string::substr(name, 9, len-9); +}; + +struct Tag { + TypeId tag[[format_read("get_tag")]]; + match (tag.type) { + (TagType::Null) : { + // All set + } + (TagType::Byte) : { + u8 value; + u8 pad[[hidden]]; + } + (TagType::Word) : { + u16 value; + } + (TagType::DWord) : { + u32 value; + } + (TagType::QWord) : { + u64 value; + } + (TagType::StringRef) : { + u32 str_offset; + char value @ str_offset; + } + (TagType::List) : { + u32 size ; + Tag tags[while($ < ((addressof(size) + size + 4) ))]; + } + (TagType::String) : { + u32 size; + char16 value[size/2]; + } + (TagType::Binary) : { + u32 size; + u8 value[size]; + if (size & 1 ) { + u8 pad[[hidden]]; + } + } + } +}[[name(get_tag(tag)), comment(get_type(tag))]]; + +struct Header { + u32 Major; + u32 Minor; + char Magic[4]; + Tag tags[while(!std::mem::eof())]; +}; + +Header file @ 0x0; \ No newline at end of file diff --git a/tests/patterns/test_data/sdb.hexpat.sdb b/tests/patterns/test_data/sdb.hexpat.sdb new file mode 100644 index 0000000..e98a40e Binary files /dev/null and b/tests/patterns/test_data/sdb.hexpat.sdb differ