Results 1 to 3 of 3

Thread: How would you parse binary data based on C++ definition files?

  1. #1
    Join Date
    May 2010
    Posts
    86
    Thanks
    17
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question 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....

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default 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.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3

    Default 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.

Similar Threads

  1. Replies: 2
    Last Post: 20th October 2011, 16:14
  2. Reading Binary Files
    By archanasubodh in forum Newbie
    Replies: 1
    Last Post: 27th February 2008, 13:31
  3. How can I read Binary files with Qt
    By geo_saleh in forum Qt Programming
    Replies: 2
    Last Post: 16th August 2007, 11:37
  4. Replies: 0
    Last Post: 29th May 2007, 07:28
  5. How to convert binary data to hexadecimal data
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 8th March 2006, 17:17

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.