mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-27 23:37:04 -05:00
patterns/nbt: Added NBT pattern
This commit is contained in:
@@ -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 |
|
| 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 |
|
| 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 |
|
| StuffItV5 | `application/x-stuffit` | [`patterns/sit5.hexpat`](patterns/sit5.hexpat) | StuffIt V5 archive |
|
||||||
|
| NBT | | [`patterns/nbt.hexpat`](patterns/nbt.hexpat) | Minecraft NBT format |
|
||||||
|
|
||||||
### Scripts
|
### Scripts
|
||||||
|
|
||||||
|
|||||||
70
patterns/nbt.hexpat
Normal file
70
patterns/nbt.hexpat
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
#include <std/sys.pat>
|
||||||
|
|
||||||
|
#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;
|
||||||
BIN
tests/patterns/test_data/nbt.hexpat.nbt
Normal file
BIN
tests/patterns/test_data/nbt.hexpat.nbt
Normal file
Binary file not shown.
Reference in New Issue
Block a user