From 0c992a389151bdc245cfe0d029d27b6c0e7b9b48 Mon Sep 17 00:00:00 2001 From: Phil <phil@secdev.org> Date: Sun, 8 Mar 2009 10:56:21 +0100 Subject: [PATCH] Improve hexdump capture import --- scapy/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/scapy/utils.py b/scapy/utils.py index 2016f4be..960dfb71 100644 --- a/scapy/utils.py +++ b/scapy/utils.py @@ -666,7 +666,7 @@ class PcapWriter(RawPcapWriter): RawPcapWriter._write_packet(self, s, sec, usec, caplen, caplen) -re_extract_hexcap = re.compile("^(0x[0-9a-fA-F]{2,}[ :\t]|(0x)?[0-9a-fA-F]{2,}:|(0x)?[0-9a-fA-F]{3,}[: \t]|) *(([0-9a-fA-F]{2} {,2}){,16})") +re_extract_hexcap = re.compile("^((0x)?[0-9a-fA-F]{2,}[ :\t]{,3}|) *(([0-9a-fA-F]{2} {,2}){,16})") def import_hexcap(): p = "" @@ -674,7 +674,7 @@ def import_hexcap(): while 1: l = raw_input().strip() try: - p += re_extract_hexcap.match(l).groups()[3] + p += re_extract_hexcap.match(l).groups()[2] except: warning("Parsing error during hexcap") continue @@ -682,10 +682,7 @@ def import_hexcap(): pass p = p.replace(" ","") - p2="" - for i in range(len(p)/2): - p2 += chr(int(p[2*i:2*i+2],16)) - return p2 + return p.decode("hex") -- GitLab