From 5a3036149c2b7ec87c201b48e168d14c56ce0f43 Mon Sep 17 00:00:00 2001 From: Nik Date: Wed, 21 Dec 2022 19:57:04 +0100 Subject: [PATCH] patterns/nbt: Added NBT pattern --- README.md | 1 + patterns/nbt.hexpat | 70 ++++++++++++++++++++++++ tests/patterns/test_data/nbt.hexpat.nbt | Bin 0 -> 1544 bytes 3 files changed, 71 insertions(+) create mode 100644 patterns/nbt.hexpat create mode 100644 tests/patterns/test_data/nbt.hexpat.nbt diff --git a/README.md b/README.md index 4f9af26..87f6870 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ Hex patterns, include patterns and magic files for the use with the ImHex Hex Ed | CPIO | `application/x-cpio` | [`patterns/cpio.hexpat`](patterns/cpio.hexpat) | Old Binary CPIO Format | | FDT | | [`patterns/fdt.hexpat`](patterns/fdt.hexpat) | Flat Linux Device Tree blob | | StuffItV5 | `application/x-stuffit` | [`patterns/sit5.hexpat`](patterns/sit5.hexpat) | StuffIt V5 archive | +| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format | ### Scripts diff --git a/patterns/nbt.hexpat b/patterns/nbt.hexpat new file mode 100644 index 0000000..8d84743 --- /dev/null +++ b/patterns/nbt.hexpat @@ -0,0 +1,70 @@ +#include + +#pragma endian big + +enum Tag : u8 { + End = 0, + Byte = 1, + Short = 2, + Int = 3, + Long = 4, + Float = 5, + Double = 6, + ByteArray = 7, + String = 8, + List = 9, + Compound = 10, + IntArray = 11, + LongArray = 12 +}; + +using Element; + +struct Value { + if (parent.tag == Tag::Byte) + s8 value; + else if (parent.tag == Tag::Short) + s16 value; + else if (parent.tag == Tag::Int) + s32 value; + else if (parent.tag == Tag::Long) + s64 value; + else if (parent.tag == Tag::Float) + float value; + else if (parent.tag == Tag::Double) + double value; + else if (parent.tag == Tag::ByteArray) { + s32 arrayLength; + s8 value[arrayLength] [[sealed]]; + } else if (parent.tag == Tag::String) { + u16 stringLength; + char value[stringLength]; + } else if (parent.tag == Tag::List) { + Tag tag; + s32 listLength; + Value values[listLength] [[static]]; + } else if (parent.tag == Tag::Compound) { + Element values[while(true)]; + } else { + std::error(std::format("Invalid tag {:02X}", TypeTag)); + } +} [[inline]]; + +struct Element { + Tag tag; + if (tag == Tag::End) + break; + else { + + u16 nameLength; + char name[nameLength]; + + Value value; + } +}; + +struct NBT { + Element element[while(true)] [[inline]]; +}; + +NBT nbt @ 0x00; \ No newline at end of file diff --git a/tests/patterns/test_data/nbt.hexpat.nbt b/tests/patterns/test_data/nbt.hexpat.nbt new file mode 100644 index 0000000000000000000000000000000000000000..a2021df7cb5ee7125965c18aaaf45fa60a3e2759 GIT binary patch literal 1544 zcmeHHUr*Xl6hA_N(lIcO7-Eb$bB?sEYYIao#vwXzXc{!os4<4v%B7&CHEnV6X)oL3 zvbTMiJ@Og$yw`mTb}8Uqw&%TYbCYxK@BHrhcmHq@Qpi0q8DLG@GF0MvA4iiBfT-KG z9dClMz`35&n@~WgRTbqJ&yE{P1=ZSN6Y1PTwc1p%sWuMl?{WBf_-XjG*e@df_D&i}gqPGPqU&jnM^6kt^t>)wZ)M~uTF8m` zCNE;PAYxHONsx(S6EGkO}$eh+sF5}WUA2=$?xstlL&DF$}r6d+kS5GqW ztMiLMs;K8;>i+glt+i4~HVPZ7Ynk#@`XZkS>kwPtXLpucO68!zY}D5-%Tk)pABE+4 fjCrr-_v-(?k1%j;d!U>C53~F8>+Sc^O$&Yl_JmkZ literal 0 HcmV?d00001