1

I would like to parse binary files with PCRE. My tactic until now was to use fgets to read a line of a file, then parse that line using pcre_exec.

This will not work for me now because the "lines" end with a null byte rather than a newline. I did not see a way to have fgets stop at a null byte rather than newline.

Edit

The functionality would be similar to running grep -az PATTERN FILE

Zombo
  • 1
  • 62
  • 391
  • 407
  • That's correct, frets doesn't work well with binary files. can you give more detail about the bin file? you want to parse using some structs for example? – TOC Aug 02 '12 at 00:35

1 Answers1

1

In this case, no luck, you need to read your binary file byte by byte and check for '\0'. You can then store this bytes on a buffer and:

  • Doing some comparaison on the fly with your PATTERN

or

  • If you want to keep data for later processing, you can store this buffers on a linked list for example (if you don't have a huge files).

Hope this help.

Regards.

TOC
  • 4,326
  • 18
  • 21