mirror of
https://github.com/WerWolv/ImHex-Patterns.git
synced 2026-03-28 07:47:02 -05:00
includes/std: Added nullable pointers to std/ptr (#97)
This commit is contained in:
@@ -34,4 +34,34 @@ namespace std::ptr {
|
||||
return std::mem::size() - offset * 2;
|
||||
};
|
||||
|
||||
/**
|
||||
A nullable pointer, generic over both the pointee type and pointer type.
|
||||
|
||||
By nullable, we mean that if the pointer's value is zero (`0x0`), then the
|
||||
value will appear as padding rather than a pointer to something, but
|
||||
if the pointer's value is non-zero, that non-zero value will be treated as
|
||||
a pointer of type `PointerTy` which points to an element of type `PointeeTy`.
|
||||
|
||||
Example:
|
||||
A struct field called `p_myInfo` which is a nullable 64-bit pointer to an
|
||||
element of type `MyInfoTy` would be written as:
|
||||
```
|
||||
struct MyStruct {
|
||||
std::ptr::NullablePtr<MyInfoTy, u64> p_myInfo;
|
||||
}
|
||||
```
|
||||
*/
|
||||
struct NullablePtr<PointeeTy, PointerTy> {
|
||||
// `pointerValue` is `no_unique_address` because we don't want to advance
|
||||
// the current memory location after reading the value of the pointer itself;
|
||||
// we want to examine the value at this address to determine what should be
|
||||
// displayed. It's also `hidden` so the editor only displays either thee
|
||||
// padding or the populated pointer/pointee field.
|
||||
PointerTy pointerValue [[no_unique_address, hidden]];
|
||||
if (pointerValue == 0x0) {
|
||||
padding[sizeof(PointerTy)];
|
||||
} else {
|
||||
PointeeTy *data : PointerTy;
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user