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