Regex'ing null bytes

J

Jonas Galvez

Hi,

I'm trying to parse some binary data with regexes. It works well in
the latest Python build, but I need to run this on Python 1.5.2. The
binary data has a pattern like this:

keyName1\002..(.*)\000.*keyName2\002..(.*)\000
(I'm using regex syntax to illustrate)

So I wrote the following script:

def amfKey(str):
return "%s\002..([^\000]*)" % str

keys = re.compile(amfKey("key"), re.DOTALL).findall(amfStr)

Works on 2.3.3, but produces the following error on 1.5.2:

Traceback (innermost last):
File "test.py", line 26, in ?
keys = re.compile(amfKey("key"), re.DOTALL).findall(amfStr)
File "C:\Python152\Lib\re.py", line 79, in compile
code=pcre_compile(pattern, flags, groupindex)
TypeError: argument 1: expected string without null bytes, string found

Does anyone know a workaround? The type of binary data I'm trying to
parse is AMF (Action Message Format), Macromedia's proprietary format
for fast communication between the Flash Player and their "Flash
Remoting" servers (ColdFusion/.NET/Java implementations). But there
are opensource "Flash Remoting" implementations in PHP (amfphp.org),
Perl (simonf.com/flap/) and Java (openamf.org) already - I've
started to work on the Python port.

And I wanted to keep this Python 1.5.2-compatible...



Thanks in advance,


=-
Jonas Galvez
jonasgalvez.com/blog
macromedia.com/go/team
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top