How would you parse binary data based on C++ definition files?
Hi,
At first, I don't know how to search for this thing and where to turn regarding the topic. I tried to google it out, but had no success, this is why I'm turning here.
I'm trying to write an application that reads binary file data as input and puts this read data into a e.g. tree representation based on a descriptor file that defines which position and what quantity defines a specific field. The right descriptor file is chosen based on the name of the source input file.
The descriptor files are given, which are following standard C format and can point/link to other descriptor files if e.g. an unknown struct is used inside.
How could I implement an application that could show the right representation of a data file based on the logic of these descriptors instead of showing just the meaningless lines of hexa values?
I already implemented the solution for one of these data files, and it is represented well in this tree view, but I don't want to do the same for hundreds of like this, because it would be much nicer and quicker to have the code automatically match them.
I just would like to have the basic idea/suggestion, not the full explanation, so thanks for any ideas in advance!
Example:
xyz.bin:
00 21 AF 23 39 29 C4 ...
xyz_desc.c:
struct {
dword something;
byte secret_code;
byte gate_code;
byte explanation [20];
} some_struct;
representation based on descriptor:
something is 2207523.
secret code is 57.
etc....
Re: How would you parse binary data based on C++ definition files?
In order to have it "automated" you need somehow to know which type of content you have in your binary file.
If you are the one creating the binary files, one method would be to add a field at the top of the file, describing the type of data in it - then your parser can know how to parse it.
If you are not the author of the binaries, maybe you can rename the files with different extensions.
But you must know in some way how to read the file - since binary data is nothing more then ones and zeroes which can mean anything.
Re: How would you parse binary data based on C++ definition files?
In order to have it "automated" you need somehow to know which type of content you have in your binary file.
If you are the one creating the binary files, one method would be to add a field at the top of the file, describing the type of data in it - then your parser can know how to parse it.