Coming from a background of 010editor binary templates, these are a few optimization tips that I wish I knew from the beginning. These are mentioned in the ImHex docs, but are quite easy to miss if you are just skimming.
The [[static]]
attribute in ImHex is similar to the <optimize=true|false>
attribute in 010 Editor. However, there are a few key differences:
-
Opt-in vs Opt-out
[[static]]
is a purely opt-in feature in ImHex, whereas the respective<optimize>
in 010 Editor is opt-out. -
Applies to the type, rather than the array using the type.
ImHex:
type Foobar {
i32 x;
u8 data[256];
} [[static]]; // Must always be manually specified.
Foobar records[5] @ 0x0;
010 Editor:
typedef struct {
int x;
uint8 data[256];
} Foobar;
Foobar records[5] <optimize=true>; // Implicit, doesn't need to be set manually.
In ImHex, you should avoid pure arrays for large byte ranges/blobs, such as embedded files.
- DONT:
u8 data[length];
- DO:
std::mem::Bytes<length> data;
The pure array types will generate an actual u8
entry to each byte of the blob, which will cause your pattern to take SIGNIFICANTLY longer to evaluate, and SIGNIFICANTLY increase memory usage (on the order of GBs).