Page 1 of 1

Extract data from hex file

Posted: Sun Mar 08, 2009 3:14 pm
by number45
I am trying to use the following to extract data from a hex file.

Code: Select all

preg_match_all('/\x00\x0E[\x07|\x06]\x00(a\x00u\x00s\x00t\x00r\x00i\x00a|b\x00r\x00i\x00t\x00a\x00i\x00n|f\x00r\x00a\x00n\x00c\x00e)\x00(.*?)\x00\x0E/s',$data,$matches);
The data I want to extract has a series of hex characters followed by either austria, britain or france (with each character separated by the hex 00) then another couple of hex characters then a user name. The regular expression above works in editpad pro but not in PHP and I don't see why. I've tried using the u modifier but no change.

This link shows the sample data I am working with.

I am by no means a regular expression expert but can usually muddle my way through. This time however I just don't understand where I'm going wrong.

Re: Extract data from hex file

Posted: Sun Mar 08, 2009 8:06 pm
by Benjamin
The file is most likely binary rather than hex on disk. Can you save it as a hex file? You may have to convert it to hex using PHP first.

Re: Extract data from hex file

Posted: Mon Mar 09, 2009 7:24 am
by number45
:banghead: :banghead:

It was because the entire file wasn't being read. I just had to override the read method in my inherited class so it read the entire file and it found the data I was looking for.

Thanks for your help. If it wasn't for your suggestion I wouldn't have thought to go back to the read and check the actual file contents.