Searching binary data

Darrell darrell at dorb.com
Wed Feb 2 22:17:07 EST 2000


Didn't have access to the internet today which forced me to have a creative
thought of my own. Now to find out if I wasted my time.

The problem is to find patterns in gobs of binary data.
Treat it as a string you see something like this.
MZ\220\000\003\000\000\000\004\000\000\000\377\377

I found writing a re for patterns in that, a pain.
What if I wanted r"[\000-\077]".
It won't work because there are nulls in the result and re doesn't like
that.
Not to mention all this octal to hex is annoying an who knows what trouble
Nulls will be.

So I wrote an extension to covert everything to hex in the following format.
4d5aff000300000004000000ffff0000ff
Now I can treat the whole thing as a string :)

Guess it needs a function to go back the other way now.

Yes the stuct module is useful but I wanted to use re also.
Now someone will say why didn't you use binhex or binascii.
But unless I missed it they didn't seem to solve this problem.

--Darrell





More information about the Python-list mailing list