tool/dump_pklg: use struct module

This commit is contained in:
Matthias Ringwald 2022-01-15 12:48:30 +01:00
parent 53f240c0b0
commit cac83658f9

View File

@ -13,23 +13,16 @@
import sys
import datetime
import struct
packet_types = [ "CMD =>", "EVT <=", "ACL =>", "ACL <="]
def read_net_32(f):
a = f.read(1)
if a == '':
return -1
b = f.read(1)
if b == '':
return -1
c = f.read(1)
if c == '':
return -1
d = f.read(1)
if d == '':
return -1
return ord(a) << 24 | ord(b) << 16 | ord(c) << 8 | ord(d)
def read_header(f):
bytes_read = f.read(13)
if bytes_read:
return struct.unpack(">IIIB", bytes_read)
else:
return (-1, 0, 0, 0)
def as_hex(data):
str_list = []
@ -50,12 +43,9 @@ with open (infile, 'rb') as fin:
pos = 0
try:
while True:
len = read_net_32(fin)
(len, ts_sec, ts_usec, type) = read_header(fin)
if len < 0:
break
ts_sec = read_net_32(fin)
ts_usec = read_net_32(fin)
type = ord(fin.read(1))
packet_len = len - 9;
if (packet_len > 66000):
print ("Error parsing pklg at offset %u (%x)." % (pos, pos))