Reputation: 91
I want to convert this 8 Byte structure:
nt!_POOL_HEADER
+0x000 PreviousSize : Pos 0, 9 Bits
+0x000 PoolIndex : Pos 9, 7 Bits
+0x002 BlockSize : Pos 0, 9 Bits
+0x002 PoolType : Pos 9, 7 Bits
+0x000 Ulong1 : Uint4B
+0x004 PoolTag : Uint4B
+0x004 AllocatorBackTraceIndex : Uint2B
+0x006 PoolTagHash : Uint2B
Into a C structure like this:
struct _POOL_HEADER {
PreviousSize; // what SIZE do i Need to specify here ?
PoolIndex; // what SIZE do i Need to specify here ?
BlockSize; // what SIZE do i Need to specify here ?
PoolType; // what SIZE do i Need to specify here ?
unsigned int Ulong1;
unsigned int PoolTag;
unsigned short AllocatorBackTraceIndex;
unsigned short PoolTagHash;
};
I know this can be done with bitfields but how? This is on x86.
Upvotes: 1
Views: 75
Reputation: 70883
Assuming int
to be 32 bits this would do:
struct _POOL_HEADER {
int PreviousSize :9;
int PoolIndex :7;
int BlockSize :9;
int PoolType :7;
...
The part above uses 4 bytes.
If you want to stick to 8 bytes all in all you need to change the lower part,
unsigned int Ulong1;
unsigned int PoolTag;
unsigned short AllocatorBackTraceIndex;
unsigned short PoolTagHash;
};
as your proposal uses more then the 4 bytes left, namely 12 bytes.
Upvotes: 1