Extract data from hex file

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
number45
Forum Newbie
Posts: 3
Joined: Sun Mar 08, 2009 1:15 pm

Extract data from hex file

Post 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.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: Extract data from hex file

Post 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.
number45
Forum Newbie
Posts: 3
Joined: Sun Mar 08, 2009 1:15 pm

Re: Extract data from hex file

Post 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.
Post Reply