def parse(self, fname): with open(fname, 'r') as f: m = self.marshal() meta = {} code = None d = load_dump(f, meta) pkts = m.parse(d) if meta.get('code'): code = eval(meta['code']) return pkts, code
def load(dumpfilename): with open(dumpfilename, "r") as infile: data = load_dump(infile) print("load len={}".format(len(data))) # from tests/decoder/decoder.py offset = 0 scan_dump = [] counter = 0 while offset < len(data): print("counter={} offset={} len={}".format(counter, offset, len(data))) msg = nl80211cmd(data[offset:]) msg.decode() offset += msg['header']['length'] counter += 1 scan_dump.append(msg) return scan_dump
Module is a name within rtnl hierarchy. File should be a binary data in the escaped string format (see samples). ''' import sys from pprint import pprint from importlib import import_module from pyroute2.common import load_dump from pyroute2.common import hexdump mod = sys.argv[1] f = open(sys.argv[2], 'r') s = mod.split('.') package = '.'.join(s[:-1]) module = s[-1] m = import_module(package) met = getattr(m, module) data = load_dump(f) offset = 0 inbox = [] while offset < len(data): msg = met(data[offset:]) msg.decode() print(hexdump(msg.raw)) pprint(msg) print('.'*40) offset += msg['header']['length']
./decoder.py pyroute2.netlink.rtnl.tcmsg.tcmsg ./sample_packet_01.data ./decoder.py pyroute2.netlink.nl80211.nl80211cmd ./nl80211.data Module is a name within rtnl hierarchy. File should be a binary data in the escaped string format (see samples). ''' import sys from io import StringIO from pprint import pprint from importlib import import_module from pyroute2.common import load_dump from pyroute2.common import hexdump from pyroute2.netlink.generic.wireguard import wgmsg as met if __name__ == "__main__": with open(sys.argv[1], 'r') as f: for line in f.readlines(): try: data = load_dump(StringIO(line)) offset = 0 inbox = [] while offset < len(data): msg = met(data[offset:]) msg.decode() print(hexdump(msg.data)) pprint(msg) print('.' * 40) offset += msg['header']['length'] except Exception as e: pprint(e)
Sample:: ./decoder.py pyroute2.netlink.rtnl.tcmsg.tcmsg ./sample_packet_01.data ./decoder.py pyroute2.netlink.nl80211.nl80211cmd ./nl80211.data Module is a name within rtnl hierarchy. File should be a binary data in the escaped string format (see samples). ''' import sys from pprint import pprint from importlib import import_module from pyroute2.common import load_dump mod = sys.argv[1] f = open(sys.argv[2], 'r') s = mod.split('.') package = '.'.join(s[:-1]) module = s[-1] m = import_module(package) met = getattr(m, module) data = load_dump(f) offset = 0 inbox = [] while offset < len(data): msg = met(data[offset:]) msg.decode() pprint(msg) offset += msg['header']['length']