mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-03-30 21:05:56 -05:00
Added enums and bitfields
@@ -91,4 +91,55 @@ union Color {
|
||||
Color color @ 0x100;
|
||||
```
|
||||
|
||||

|
||||

|
||||
|
||||
## Enums
|
||||
|
||||
Enums are types whose value is restricted to a distinct number of values. When placed in memory, the Pattern Data View will show the relevant enum entry name instead of the numerical value.
|
||||
|
||||
Every enum has an underlying type which is used to specify the size of the enum when placed in memory. `u32` will create a 4 byte enum, `s8` will create a 1 byte enum.
|
||||
|
||||
Every enum entry can be set to a distinct value using the `<identifier> = <expression>` syntax as seen below. If no value is specified for an entry, it's value will be the value of the last entry plus one. Counting starts at zero.
|
||||
|
||||
```cpp
|
||||
enum <typeName> : <builtinTypeName> {
|
||||
<enumEntry>
|
||||
...
|
||||
};
|
||||
|
||||
// Example
|
||||
enum Architecture : u8 {
|
||||
x86 = 0x20,
|
||||
x64, // Value 0x21
|
||||
ARM32 = 0x35,
|
||||
ARM64 // Value 0x36
|
||||
};
|
||||
|
||||
Architecture arch @ 0x100;
|
||||
```
|
||||
|
||||

|
||||
|
||||
## Bitfields
|
||||
|
||||
If you're trying to parse a region of memory that is not aligned to the usual 8 bit boundaries or has variables that are smaller than one 8 bits (such as bit flags), a bitfield can be used.
|
||||
Bitfields allow variables to be specified with a custom number bits used. This is done by using the `<identifier> : <expression>` syntax where the identifier before the colon specifies the field name and the expression after the colon the size of the field in bits.
|
||||
There is no padding inserted between members, however the size of the entire bitfield will be rounded up to the next 8 bit boundary.
|
||||
|
||||
```cpp
|
||||
bitfield <typeName> {
|
||||
<bitfieldEntry>
|
||||
...
|
||||
};
|
||||
|
||||
// Example
|
||||
bitfield Permission {
|
||||
r : 1;
|
||||
w : 1;
|
||||
x : 1;
|
||||
};
|
||||
|
||||
Permission perm @ 0x20;
|
||||
```
|
||||
|
||||

|
||||
Reference in New Issue
Block a user