I’m trying to parse an incoming packet, split some values and store them into their respective variable.
This illustrate what I’m trying to do:
Incoming = "\x00\x31\x00\x62\x00\x6a\x00\x61\x00\x61\x00\x61\x00\x71\x00\x71"
Incoming+= "\x00\x71\x00\x61\x00\x71\x00\x6a\x00\x71\x00\x00\x00\x55\x00\x4e"
Incoming+= "\x00\x45\x00\x00\x00\x61\x61\x61\x00\x00\x00"
print Incoming
>>> 1bjaaaqqqaqjqUNEaaa
The strings I need to use are delimited by 3 null bytes “\x00\x00\x00”, so it should look like this:
print Incoming
>>> 1bjaaaqqqaqjq UNE aaa
What I need to do is store “1bjaaaqqqaqjq” in var1, “UNE” in var2, “aaa” in var3.
I was thinking of something like :
Incoming = "\x00\x31\x00\x62\x00\x6a\x00\x61\x00\x61\x00\x61\x00\x71\x00\x71"
Incoming+= "\x00\x71\x00\x61\x00\x71\x00\x6a\x00\x71\x00\x00\x00\x55\x00\x4e"
Incoming+= "\x00\x45\x00\x00\x00\x61\x61\x61\x00\x00\x00"
pack = list(Incoming)
null = [i for i in range(len(pack)) if pack[i:i+3] == ['\x00','\x00','\x00']]
for i in null:
pack[i] = "\n"
print ''.join(pack)
>>>1bjaaaqqqaqjq
UNE
aaa
However my code can’t assign these values to their respective var (var1,var2,var3,etc)
Any help would be greatly appreciated.
Thanks
Is this what you mean: