I am trying to parse a c struct in python using the construct library Here is my struct:
typedef struct _MACHINEID {
UINT32 ui32Hash;
DWORD dwLength;
DWORD dwMemoryLoad;
DWORDLONG ullTotalPhys;
DWORDLONG ullAvailPhys;
DWORDLONG ullTotalPageFile;
DWORDLONG ullAvailPageFile;
DWORDLONG ullTotalVirtual;
DWORDLONG ullAvailVirtual;
DWORDLONG ullAvailExtendedVirtual;
} MACHINEID, * PMACHINEID;
from construct import Int32un, Int8sn, Int16un, Int64un, Int
from construct import Array, Struct
MACHINE_ID = Struct(
'ui32Hash' / Int32un,
'dwLength' / Int32un,
'dwMemoryLoad' / Int32un,
'ullTotalPhys' / Int64un,
'ullAvailPhys' / Int64un,
'ullTotalPageFile' / Int64un,
'ullAvailPageFile' / Int64un,
'ullTotalVirtual' / Int64un,
'ullAvailVirtual' / Int64un,
'ullAvailExtendedVirtual' / Int64un
)
But when i receive the struct in python as a bytes object The vallues of all DWORDLONG
members are incorrect. Does anyone know whats causing this?
As "Some programmer dude" suggested it had to do with padding. Putting __pragma(pack(push, 1))
and __pragma(pack(pop))
around my struct to disable padding solves the issue.