From 6b9f39cc2175c573fec2ae703f2c9ee3821f7335 Mon Sep 17 00:00:00 2001 From: Mark Jansen Date: Fri, 15 Aug 2025 17:16:50 +0200 Subject: [PATCH] patterns: Add SDB pattern (#424) Co-authored-by: Nik --- README.md | 1 + patterns/sdb.hexpat | 87 ++++++++++++++++++++++++ tests/patterns/test_data/sdb.hexpat.sdb | Bin 0 -> 260 bytes 3 files changed, 88 insertions(+) create mode 100644 patterns/sdb.hexpat create mode 100644 tests/patterns/test_data/sdb.hexpat.sdb 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 0000000000000000000000000000000000000000..e98a40e1be84ac8f94a9307bc4b94c882a2c5919 GIT binary patch literal 260 zcmYL?uMWa65XSGi@kg!*1PNpmO|oQW@&tk)$P9iEs6sR$VRnwmy&H0hSKtN8T_^aO z{CeNrcWnfN9@mRS_Z8zpCxO)Wka-W}Sx^c^&`mio)a)7+;!w$jVHXojp~s9pNmrFZ z5r*BNX4l9|PdLL}W|j1nTL=qPM11BHvD=VluE{V*?#LXwJ#*q_%q1~kMaay_XaxNK dSH2E*`?