I've trying to write a small program which could read .h file, then generate ctypes.Structure classes from struct in .h file. Then i'm reading binary file into the Structures. And then i need to print out all of the Structure field values (including arrays and subStructures). How can i do it?
This is basic function that print all fields and sub-structures.
def f(obj):
for k,v in obj.__dict__.items():
print k ,v
if hasattr(v,'__dict__'):
f(v)
Of course, you can add conditions to the function, to filter out unneeded data etc.
There is already a tool that does this. (No need to re-invent the wheel).
See: https://github.com/davidjamesca/ctypesgen
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With