user2061913
user2061913

Reputation: 920

issue with formatting characters

having a bit of an issue displaying characters

i have a payload recieved from a protocol request :

538cb9350404521a6c44020404563b152606102001085800020002aabb0000563b1526000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

the length of that is 509

what i want to display is the first 4 bytes, then 1 byte, then 1 byte

538cb935

04

04

currently to view the payload i am doing the following :

tm = struct.unpack(">L", payload[0:4])
print "Time : ", tm
ouroripv = struct.unpack(">b", payload[5])
print "Our onion address : "    
print "Ip version : ", ouroripv
ouroraddrlen = struct.unpack(">b", payload[6]) # Giving a length of 82 etc atm 
print "Ip length : ", ouroraddrlen

i get the result :

Time :  (1401731381,)
Our onion address : 
Ip version :  (4,)
Ip length :  (82,)

as you can see the Ip length, the 6th byte in on the payload is displaying 82 rather than the 4 it should be, what is the correct struct.unpack command that is needed to display this ?

how can i do this ?

Thanks guys

Upvotes: 0

Views: 27

Answers (1)

Pavel
Pavel

Reputation: 7562

in python, the slicing doesn't include the last value, so payload[0:4] takes the first 4 bytes, from 0 to 3.

payload[3] is the fourth byte

payload[4] is the fifth byte

Upvotes: 2

Related Questions