From 4e2b6b13f6c71a81671fc4fb589f7919a81b931b Mon Sep 17 00:00:00 2001 From: Gerald Combs Date: Sun, 1 Dec 2013 01:53:26 +0000 Subject: Use 4-space (PEP 8) indentation. Add modelines. svn path=/trunk/; revision=53685 --- tools/make-tap-reg.py | 138 ++++----- tools/ncp2222.py | 12 + tools/pkt-from-core.py | 740 +++++++++++++++++++++++++------------------------ tools/rdps.py | 11 + tools/wireshark_gen.py | 43 +-- 5 files changed, 501 insertions(+), 443 deletions(-) (limited to 'tools') diff --git a/tools/make-tap-reg.py b/tools/make-tap-reg.py index 76dbec7634..fa5ea743b1 100755 --- a/tools/make-tap-reg.py +++ b/tools/make-tap-reg.py @@ -47,16 +47,16 @@ srcdir = sys.argv[1] # registertype = sys.argv[2] if registertype == "taps": - tmp_filename = "wireshark-tap-register.c-tmp" - final_filename = "wireshark-tap-register.c" - cache_filename = "wireshark-tap-register-cache.pkl" + tmp_filename = "wireshark-tap-register.c-tmp" + final_filename = "wireshark-tap-register.c" + cache_filename = "wireshark-tap-register-cache.pkl" elif registertype == "tshark-taps": - tmp_filename = "tshark-tap-register.c-tmp" - final_filename = "tshark-tap-register.c" - cache_filename = "tshark-tap-register-cache.pkl" + tmp_filename = "tshark-tap-register.c-tmp" + final_filename = "tshark-tap-register.c" + cache_filename = "tshark-tap-register-cache.pkl" else: - print("Unknown output type '%s'" % registertype) - sys.exit(1) + print("Unknown output type '%s'" % registertype) + sys.exit(1) # @@ -67,22 +67,22 @@ files = sys.argv[3:] # Create the proper list of filenames filenames = [] for file in files: - if os.path.isfile(file): - filenames.append(file) - else: - filenames.append("%s/%s" % (srcdir, file)) + if os.path.isfile(file): + filenames.append(file) + else: + filenames.append("%s/%s" % (srcdir, file)) if len(filenames) < 1: - print("No files found") - sys.exit(1) + print("No files found") + sys.exit(1) # Look through all files, applying the regex to each line. # If the pattern matches, save the "symbol" section to the # appropriate array. regs = { - 'tap_reg': [], - } + 'tap_reg': [], + } # For those that don't know Python, r"" indicates a raw string, # devoid of Python escapes. @@ -91,60 +91,60 @@ tap_regex1 = r"void\s+(?Pregister_tap_listener_[_A-Za-z0-9]+)\s*\([^;]+$ # This table drives the pattern-matching and symbol-harvesting patterns = [ - ( 'tap_reg', re.compile(tap_regex0) ), - ( 'tap_reg', re.compile(tap_regex1) ), - ] + ( 'tap_reg', re.compile(tap_regex0) ), + ( 'tap_reg', re.compile(tap_regex1) ), + ] # Open our registration symbol cache cache = None if cache_filename: - try: - cache_file = open(cache_filename, 'rb') - cache = pickle.load(cache_file) - cache_file.close() - except: - cache = {} + try: + cache_file = open(cache_filename, 'rb') + cache = pickle.load(cache_file) + cache_file.close() + except: + cache = {} # Grep for filename in filenames: - file = open(filename) - cur_mtime = os.fstat(file.fileno())[ST_MTIME] - if cache and filename in cache: - cdict = cache[filename] - if cur_mtime == cdict['mtime']: -# print "Pulling %s from cache" % (filename) - regs['tap_reg'].extend(cdict['tap_reg']) - file.close() - continue - # We don't have a cache entry - if cache is not None: - cache[filename] = { - 'mtime': cur_mtime, - 'tap_reg': [], - } -# print "Searching %s" % (filename) - for line in file.readlines(): - for action in patterns: - regex = action[1] - match = regex.search(line) - if match: - symbol = match.group("symbol") - sym_type = action[0] - regs[sym_type].append(symbol) - if cache is not None: -# print "Caching %s for %s: %s" % (sym_type, filename, symbol) - cache[filename][sym_type].append(symbol) - file.close() + file = open(filename) + cur_mtime = os.fstat(file.fileno())[ST_MTIME] + if cache and filename in cache: + cdict = cache[filename] + if cur_mtime == cdict['mtime']: +# print "Pulling %s from cache" % (filename) + regs['tap_reg'].extend(cdict['tap_reg']) + file.close() + continue + # We don't have a cache entry + if cache is not None: + cache[filename] = { + 'mtime': cur_mtime, + 'tap_reg': [], + } +# print "Searching %s" % (filename) + for line in file.readlines(): + for action in patterns: + regex = action[1] + match = regex.search(line) + if match: + symbol = match.group("symbol") + sym_type = action[0] + regs[sym_type].append(symbol) + if cache is not None: +# print "Caching %s for %s: %s" % (sym_type, filename, symbol) + cache[filename][sym_type].append(symbol) + file.close() if cache is not None and cache_filename is not None: - cache_file = open(cache_filename, 'wb') - pickle.dump(cache, cache_file) - cache_file.close() + cache_file = open(cache_filename, 'wb') + pickle.dump(cache, cache_file) + cache_file.close() # Make sure we actually processed something if len(regs['tap_reg']) < 1: - print("No protocol registrations found") - sys.exit(1) + print("No protocol registrations found") + sys.exit(1) # Sort the lists to make them pretty regs['tap_reg'].sort() @@ -161,8 +161,8 @@ void register_all_tap_listeners(void) { """); for symbol in regs['tap_reg']: - line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) - reg_code.write(line) + line = " {extern void %s (void); %s ();}\n" % (symbol, symbol) + reg_code.write(line) reg_code.write("}\n") @@ -172,10 +172,22 @@ reg_code.close() # Remove the old final_file if it exists. try: - os.stat(final_filename) - os.remove(final_filename) + os.stat(final_filename) + os.remove(final_filename) except OSError: - pass + pass # Move from tmp file to final file os.rename(tmp_filename, final_filename) + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# vi: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# diff --git a/tools/ncp2222.py b/tools/ncp2222.py index 4ea4ab4b53..9e07440d27 100755 --- a/tools/ncp2222.py +++ b/tools/ncp2222.py @@ -16469,3 +16469,15 @@ if __name__ == '__main__': # print "Function callees" # p.print_callees() main() + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# vi: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# diff --git a/tools/pkt-from-core.py b/tools/pkt-from-core.py index 58934f4ffc..47619d5748 100755 --- a/tools/pkt-from-core.py +++ b/tools/pkt-from-core.py @@ -8,17 +8,17 @@ and save it in a packet-capture file. # $Id$ # # Copyright (C) 2013 by Gilbert Ramirez -# +# # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. -# +# # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. @@ -28,7 +28,7 @@ import os import re import sys import tempfile - + exec_file = None core_file = None output_file = None @@ -37,56 +37,56 @@ verbose = 0 debug = 0 class BackTrace: - re_frame = re.compile(r"^#(?P\d+) ") - re_func1 = re.compile(r"^#\d+\s+(?P\w+) \(") - re_func2 = re.compile(r"^#\d+\s+0x[A-Fa-f\d]+ in (?P\w+) \(") - - def __init__(self, lines): - - # In order; each item is the function name. - self.frames = [] - found_non_bt_frame = 0 - frame_will_be = 0 - - for line in lines: - m = self.re_frame.search(line) - if m: - # Skip the first frame that gdb shows, - # which is not part of the backtrace. - if not found_non_bt_frame: - found_non_bt_frame = 1 - continue - - # Get the frame number and make sure it's - # what we expect it should be. - frame_num = int(m.group("num")) - if frame_num != frame_will_be: - sys.exit("Found frame %d instead of %d" % \ - (frame_num, frame_will_be)) - - # Find the function name. XXX - need to handle '???' - n = self.re_func1.search(line) - if not n: - n = self.re_func2.search(line) - - if n: - func = n.group("func") - else: - sys.exit("Function name not found in %s" % (line,)) - - # Save the info - self.frames.append(func) - frame_will_be += 1 - - def Frames(self): - return self.frames - - - def HasFunction(self, func): - return func in self.frames - - def Frame(self, func): - return self.frames.index(func) + re_frame = re.compile(r"^#(?P\d+) ") + re_func1 = re.compile(r"^#\d+\s+(?P\w+) \(") + re_func2 = re.compile(r"^#\d+\s+0x[A-Fa-f\d]+ in (?P\w+) \(") + + def __init__(self, lines): + + # In order; each item is the function name. + self.frames = [] + found_non_bt_frame = 0 + frame_will_be = 0 + + for line in lines: + m = self.re_frame.search(line) + if m: + # Skip the first frame that gdb shows, + # which is not part of the backtrace. + if not found_non_bt_frame: + found_non_bt_frame = 1 + continue + + # Get the frame number and make sure it's + # what we expect it should be. + frame_num = int(m.group("num")) + if frame_num != frame_will_be: + sys.exit("Found frame %d instead of %d" % \ + (frame_num, frame_will_be)) + + # Find the function name. XXX - need to handle '???' + n = self.re_func1.search(line) + if not n: + n = self.re_func2.search(line) + + if n: + func = n.group("func") + else: + sys.exit("Function name not found in %s" % (line,)) + + # Save the info + self.frames.append(func) + frame_will_be += 1 + + def Frames(self): + return self.frames + + + def HasFunction(self, func): + return func in self.frames + + def Frame(self, func): + return self.frames.index(func) # Some values from wiretap; wiretap should be a shared @@ -125,354 +125,366 @@ WTAP_ENCAP_HHDLC = 27 WTAP_NUM_ENCAP_TYPES = 28 wtap_to_pcap_map = { - WTAP_ENCAP_NULL : 0, - WTAP_ENCAP_ETHERNET : 1, - WTAP_ENCAP_TOKEN_RING : 6, - WTAP_ENCAP_ARCNET : 7, - WTAP_ENCAP_SLIP : 8, - WTAP_ENCAP_PPP : 9, - WTAP_ENCAP_FDDI_BITSWAPPED : 10, - WTAP_ENCAP_FDDI : 10, - WTAP_ENCAP_ATM_RFC1483 : 11, - WTAP_ENCAP_RAW_IP : 12, - WTAP_ENCAP_LINUX_ATM_CLIP : 16, # or 18, or 19... - WTAP_ENCAP_CHDLC : 104, - WTAP_ENCAP_IEEE_802_11 : 105, - WTAP_ENCAP_SLL : 113, - WTAP_ENCAP_LOCALTALK : 114, - WTAP_ENCAP_PFLOG : 117, - WTAP_ENCAP_CISCO_IOS : 118, - WTAP_ENCAP_PRISM_HEADER : 119, - WTAP_ENCAP_HHDLC : 121, + WTAP_ENCAP_NULL : 0, + WTAP_ENCAP_ETHERNET : 1, + WTAP_ENCAP_TOKEN_RING : 6, + WTAP_ENCAP_ARCNET : 7, + WTAP_ENCAP_SLIP : 8, + WTAP_ENCAP_PPP : 9, + WTAP_ENCAP_FDDI_BITSWAPPED : 10, + WTAP_ENCAP_FDDI : 10, + WTAP_ENCAP_ATM_RFC1483 : 11, + WTAP_ENCAP_RAW_IP : 12, + WTAP_ENCAP_LINUX_ATM_CLIP : 16, # or 18, or 19... + WTAP_ENCAP_CHDLC : 104, + WTAP_ENCAP_IEEE_802_11 : 105, + WTAP_ENCAP_SLL : 113, + WTAP_ENCAP_LOCALTALK : 114, + WTAP_ENCAP_PFLOG : 117, + WTAP_ENCAP_CISCO_IOS : 118, + WTAP_ENCAP_PRISM_HEADER : 119, + WTAP_ENCAP_HHDLC : 121, } wtap_name = { - WTAP_ENCAP_UNKNOWN : "Unknown", - WTAP_ENCAP_ETHERNET : "Ethernet", - WTAP_ENCAP_TOKEN_RING : "Token-Ring", - WTAP_ENCAP_SLIP : "SLIP", - WTAP_ENCAP_PPP : "PPP", - WTAP_ENCAP_FDDI : "FDDI", - WTAP_ENCAP_FDDI_BITSWAPPED : "FDDI (Bitswapped)", - WTAP_ENCAP_RAW_IP : "Raw IP", - WTAP_ENCAP_ARCNET : "ARCNET", - WTAP_ENCAP_ATM_RFC1483 : "ATM RFC1483", - WTAP_ENCAP_LINUX_ATM_CLIP : "Linux ATM CLIP", - WTAP_ENCAP_LAPB : "LAPB", - WTAP_ENCAP_ATM_SNIFFER : "ATM Sniffer", - WTAP_ENCAP_NULL : "Null", - WTAP_ENCAP_ASCEND : "Ascend", - WTAP_ENCAP_LAPD : "LAPD", - WTAP_ENCAP_V120 : "V.120", - WTAP_ENCAP_PPP_WITH_PHDR : "PPP (with PHDR)", - WTAP_ENCAP_IEEE_802_11 : "IEEE 802.11", - WTAP_ENCAP_SLL : "SLL", - WTAP_ENCAP_FRELAY : "Frame Relay", - WTAP_ENCAP_CHDLC : "Cisco HDLC", - WTAP_ENCAP_CISCO_IOS : "Cisco IOS", - WTAP_ENCAP_LOCALTALK : "LocalTalk", - WTAP_ENCAP_PRISM_HEADER : "Prism Header", - WTAP_ENCAP_PFLOG : "PFLog", - WTAP_ENCAP_AIROPEEK : "AiroPeek", - WTAP_ENCAP_HHDLC : "HHDLC", + WTAP_ENCAP_UNKNOWN : "Unknown", + WTAP_ENCAP_ETHERNET : "Ethernet", + WTAP_ENCAP_TOKEN_RING : "Token-Ring", + WTAP_ENCAP_SLIP : "SLIP", + WTAP_ENCAP_PPP : "PPP", + WTAP_ENCAP_FDDI : "FDDI", + WTAP_ENCAP_FDDI_BITSWAPPED : "FDDI (Bitswapped)", + WTAP_ENCAP_RAW_IP : "Raw IP", + WTAP_ENCAP_ARCNET : "ARCNET", + WTAP_ENCAP_ATM_RFC1483 : "ATM RFC1483", + WTAP_ENCAP_LINUX_ATM_CLIP : "Linux ATM CLIP", + WTAP_ENCAP_LAPB : "LAPB", + WTAP_ENCAP_ATM_SNIFFER : "ATM Sniffer", + WTAP_ENCAP_NULL : "Null", + WTAP_ENCAP_ASCEND : "Ascend", + WTAP_ENCAP_LAPD : "LAPD", + WTAP_ENCAP_V120 : "V.120", + WTAP_ENCAP_PPP_WITH_PHDR : "PPP (with PHDR)", + WTAP_ENCAP_IEEE_802_11 : "IEEE 802.11", + WTAP_ENCAP_SLL : "SLL", + WTAP_ENCAP_FRELAY : "Frame Relay", + WTAP_ENCAP_CHDLC : "Cisco HDLC", + WTAP_ENCAP_CISCO_IOS : "Cisco IOS", + WTAP_ENCAP_LOCALTALK : "LocalTalk", + WTAP_ENCAP_PRISM_HEADER : "Prism Header", + WTAP_ENCAP_PFLOG : "PFLog", + WTAP_ENCAP_AIROPEEK : "AiroPeek", + WTAP_ENCAP_HHDLC : "HHDLC", } def wtap_to_pcap(wtap): - if not wtap_to_pcap_map.has_key(wtap): - sys.exit("Don't know how to convert wiretap encoding %d to libpcap." % \ - (wtap)) + if not wtap_to_pcap_map.has_key(wtap): + sys.exit("Don't know how to convert wiretap encoding %d to libpcap." % \ + (wtap)) - return wtap_to_pcap_map[wtap] + return wtap_to_pcap_map[wtap] def run_gdb(*commands): - if len(commands) == 0: - return [] - - # Create a temporary file - fname = tempfile.mktemp() - try: - fh = open(fname, "w") - except IOError, err: - sys.exit("Cannot open %s for writing: %s" % (fname, err)) - - # Put the commands in it - for cmd in commands: - fh.write(cmd) - fh.write("\n") - - fh.write("quit\n") - try: - fh.close() - except IOError, err: - try: - os.unlink(fname) - except: - pass - sys.exit("Cannot close %s: %s" % (fname, err)) - - - # Run gdb - cmd = "gdb --nw --quiet --command=%s %s %s" % (fname, exec_file, core_file) - if verbose: - print "Invoking %s" % (cmd,) - try: - pipe = os.popen(cmd) - except OSError, err: - try: - os.unlink(fname) - except: - pass - sys.exit("Cannot run gdb: %s" % (err,)) - - # Get gdb's output - result = pipe.readlines() - error = pipe.close() - if error != None: - try: - os.unlink(fname) - except: - pass - sys.exit("gdb returned an exit value of %s" % (error,)) - - - # Remove the temp file and return the results - try: - os.unlink(fname) - except: - pass - return result + if len(commands) == 0: + return [] + + # Create a temporary file + fname = tempfile.mktemp() + try: + fh = open(fname, "w") + except IOError, err: + sys.exit("Cannot open %s for writing: %s" % (fname, err)) + + # Put the commands in it + for cmd in commands: + fh.write(cmd) + fh.write("\n") + + fh.write("quit\n") + try: + fh.close() + except IOError, err: + try: + os.unlink(fname) + except: + pass + sys.exit("Cannot close %s: %s" % (fname, err)) + + + # Run gdb + cmd = "gdb --nw --quiet --command=%s %s %s" % (fname, exec_file, core_file) + if verbose: + print "Invoking %s" % (cmd,) + try: + pipe = os.popen(cmd) + except OSError, err: + try: + os.unlink(fname) + except: + pass + sys.exit("Cannot run gdb: %s" % (err,)) + + # Get gdb's output + result = pipe.readlines() + error = pipe.close() + if error != None: + try: + os.unlink(fname) + except: + pass + sys.exit("gdb returned an exit value of %s" % (error,)) + + + # Remove the temp file and return the results + try: + os.unlink(fname) + except: + pass + return result def get_value_from_frame(frame_num, variable, fmt=""): - cmds = [] - if frame_num > 0: - cmds.append("up %d" % (frame_num,)) - - cmds.append("print %s %s" % (fmt, variable)) - lines = apply(run_gdb, cmds) - - LOOKING_FOR_START = 0 - READING_VALUE = 1 - state = LOOKING_FOR_START - result = "" - for line in lines: - if line[-1] == "\n": - line = line[0:-1] - if line[-1] == "\r": - line = line[0:-1] - - if state == LOOKING_FOR_START: - if len(line) < 4: - continue - else: - if line[0:4] == "$1 =": - result = line[4:] - state = READING_VALUE - - elif state == READING_VALUE: - result += line - - return result + cmds = [] + if frame_num > 0: + cmds.append("up %d" % (frame_num,)) + + cmds.append("print %s %s" % (fmt, variable)) + lines = apply(run_gdb, cmds) + + LOOKING_FOR_START = 0 + READING_VALUE = 1 + state = LOOKING_FOR_START + result = "" + for line in lines: + if line[-1] == "\n": + line = line[0:-1] + if line[-1] == "\r": + line = line[0:-1] + + if state == LOOKING_FOR_START: + if len(line) < 4: + continue + else: + if line[0:4] == "$1 =": + result = line[4:] + state = READING_VALUE + + elif state == READING_VALUE: + result += line + + return result def get_int_from_frame(frame_num, variable): - text = get_value_from_frame(frame_num, variable) - try: - integer = int(text) - except ValueError: - sys.exit("Could not convert '%s' to integer." % (text,)) - return integer + text = get_value_from_frame(frame_num, variable) + try: + integer = int(text) + except ValueError: + sys.exit("Could not convert '%s' to integer." % (text,)) + return integer def get_byte_array_from_frame(frame_num, variable, length): - cmds = [] - if frame_num > 0: - cmds.append("up %d" % (frame_num,)) - - cmds.append("print %s" % (variable,)) - cmds.append("x/%dxb %s" % (length, variable)) - lines = apply(run_gdb, cmds) - if debug: - print lines - - bytes = [] - - LOOKING_FOR_START = 0 - BYTES = 1 - state = LOOKING_FOR_START - - for line in lines: - if state == LOOKING_FOR_START: - if len(line) < 3: - continue - elif line[0:3] == "$1 ": - state = BYTES - elif state == BYTES: - line.rstrip() - fields = line.split('\t') - if fields[0][-1] != ":": - print "Failed to parse byte array from gdb:" - print line - sys.exit(1) - - for field in fields[1:]: - val = int(field, 16) - bytes.append(val) - else: - assert 0 - - return bytes + cmds = [] + if frame_num > 0: + cmds.append("up %d" % (frame_num,)) + + cmds.append("print %s" % (variable,)) + cmds.append("x/%dxb %s" % (length, variable)) + lines = apply(run_gdb, cmds) + if debug: + print lines + + bytes = [] + + LOOKING_FOR_START = 0 + BYTES = 1 + state = LOOKING_FOR_START + + for line in lines: + if state == LOOKING_FOR_START: + if len(line) < 3: + continue + elif line[0:3] == "$1 ": + state = BYTES + elif state == BYTES: + line.rstrip() + fields = line.split('\t') + if fields[0][-1] != ":": + print "Failed to parse byte array from gdb:" + print line + sys.exit(1) + + for field in fields[1:]: + val = int(field, 16) + bytes.append(val) + else: + assert 0 + + return bytes def make_cap_file(pkt_data, lnk_t): - pcap_lnk_t = wtap_to_pcap(lnk_t) - - # Create a temporary file - fname = tempfile.mktemp() - try: - fh = open(fname, "w") - except IOError, err: - sys.exit("Cannot open %s for writing: %s" % (fname, err)) - - print "Packet Data:" - - # Put the hex dump in it - offset = 0 - BYTES_IN_ROW = 16 - for byte in pkt_data: - if (offset % BYTES_IN_ROW) == 0: - print >> fh, "\n%08X " % (offset,), - print "\n%08X " % (offset,), - - print >> fh, "%02X " % (byte,), - print "%02X " % (byte,), - offset += 1 - - print >> fh, "\n" - print "\n" - - try: - fh.close() - except IOError, err: - try: - os.unlink(fname) - except: - pass - sys.exit("Cannot close %s: %s" % (fname, err)) - - - # Run text2pcap - cmd = "text2pcap -q -l %s %s %s" % (pcap_lnk_t, fname, output_file) -# print "Command is %s" % (cmd,) - try: - retval = os.system(cmd) - except OSError, err: - try: - os.unlink(fname) - except: - pass - sys.exit("Cannot run text2pcap: %s" % (err,)) - - # Remove the temp file - try: - os.unlink(fname) - except: - pass - - if retval == 0: - print "%s created with %d bytes in packet, and %s encoding." % \ - (output_file, len(pkt_data), wtap_name[lnk_t]) - else: - sys.exit("text2pcap did not run succesfully.") + pcap_lnk_t = wtap_to_pcap(lnk_t) + + # Create a temporary file + fname = tempfile.mktemp() + try: + fh = open(fname, "w") + except IOError, err: + sys.exit("Cannot open %s for writing: %s" % (fname, err)) + + print "Packet Data:" + + # Put the hex dump in it + offset = 0 + BYTES_IN_ROW = 16 + for byte in pkt_data: + if (offset % BYTES_IN_ROW) == 0: + print >> fh, "\n%08X " % (offset,), + print "\n%08X " % (offset,), + + print >> fh, "%02X " % (byte,), + print "%02X " % (byte,), + offset += 1 + + print >> fh, "\n" + print "\n" + + try: + fh.close() + except IOError, err: + try: + os.unlink(fname) + except: + pass + sys.exit("Cannot close %s: %s" % (fname, err)) + + + # Run text2pcap + cmd = "text2pcap -q -l %s %s %s" % (pcap_lnk_t, fname, output_file) +# print "Command is %s" % (cmd,) + try: + retval = os.system(cmd) + except OSError, err: + try: + os.unlink(fname) + except: + pass + sys.exit("Cannot run text2pcap: %s" % (err,)) + + # Remove the temp file + try: + os.unlink(fname) + except: + pass + + if retval == 0: + print "%s created with %d bytes in packet, and %s encoding." % \ + (output_file, len(pkt_data), wtap_name[lnk_t]) + else: + sys.exit("text2pcap did not run succesfully.") def try_frame(func_text, cap_len_text, lnk_t_text, data_text): - # Get the back trace - bt_text = run_gdb("bt") - bt = BackTrace(bt_text) - if not bt.HasFunction(func_text): - print "%s() not found in backtrace." % (func_text,) - return 0 - else: - print "%s() found in backtrace." % (func_text,) + # Get the back trace + bt_text = run_gdb("bt") + bt = BackTrace(bt_text) + if not bt.HasFunction(func_text): + print "%s() not found in backtrace." % (func_text,) + return 0 + else: + print "%s() found in backtrace." % (func_text,) - # Figure out where the call to epan_dissect_run is. - frame_num = bt.Frame(func_text) + # Figure out where the call to epan_dissect_run is. + frame_num = bt.Frame(func_text) - # Get the capture length - cap_len = get_int_from_frame(frame_num, cap_len_text) + # Get the capture length + cap_len = get_int_from_frame(frame_num, cap_len_text) - # Get the encoding type - lnk_t = get_int_from_frame(frame_num, lnk_t_text) + # Get the encoding type + lnk_t = get_int_from_frame(frame_num, lnk_t_text) - # Get the packet data - pkt_data = get_byte_array_from_frame(frame_num, data_text, cap_len) + # Get the packet data + pkt_data = get_byte_array_from_frame(frame_num, data_text, cap_len) - if verbose: - print "Length=%d" % (cap_len,) - print "Encoding=%d" % (lnk_t,) - print "Data (%d bytes) = %s" % (len(pkt_data), pkt_data) - make_cap_file(pkt_data, lnk_t) - return 1 + if verbose: + print "Length=%d" % (cap_len,) + print "Encoding=%d" % (lnk_t,) + print "Data (%d bytes) = %s" % (len(pkt_data), pkt_data) + make_cap_file(pkt_data, lnk_t) + return 1 def run(): - if try_frame("epan_dissect_run", - "fd->cap_len", "fd->lnk_t", "data"): - return - elif try_frame("add_packet_to_packet_list", - "fdata->cap_len", "fdata->lnk_t", "buf"): - return - else: - sys.exit("A packet cannot be pulled from this core.") + if try_frame("epan_dissect_run", + "fd->cap_len", "fd->lnk_t", "data"): + return + elif try_frame("add_packet_to_packet_list", + "fdata->cap_len", "fdata->lnk_t", "buf"): + return + else: + sys.exit("A packet cannot be pulled from this core.") def usage(): - print "pkt-from-core.py [-v] -w capture_file executable-file (core-file or process-id)" - print "" - print "\tGiven an executable file and a core file, this tool" - print "\tuses gdb to retrieve the packet that was being dissected" - print "\tat the time wireshark/tshark stopped running. The packet" - print "\tis saved in the capture_file specified by the -w option." - print "" - print "\t-v : verbose" - sys.exit(1) + print "pkt-from-core.py [-v] -w capture_file executable-file (core-file or process-id)" + print "" + print "\tGiven an executable file and a core file, this tool" + print "\tuses gdb to retrieve the packet that was being dissected" + print "\tat the time wireshark/tshark stopped running. The packet" + print "\tis saved in the capture_file specified by the -w option." + print "" + print "\t-v : verbose" + sys.exit(1) def main(): - global exec_file - global core_file - global output_file - global verbose - global debug - - optstring = "dvw:" - try: - opts, args = getopt.getopt(sys.argv[1:], optstring) - except getopt.error: - usage() - - for opt, arg in opts: - if opt == "-w": - output_file = arg - elif opt == "-v": - verbose = 1 - elif opt == "-d": - debug = 1 - else: - assert 0 - - if output_file == None: - usage() - - if len(args) != 2: - usage() - - exec_file = args[0] - core_file = args[1] - - run() + global exec_file + global core_file + global output_file + global verbose + global debug + + optstring = "dvw:" + try: + opts, args = getopt.getopt(sys.argv[1:], optstring) + except getopt.error: + usage() + + for opt, arg in opts: + if opt == "-w": + output_file = arg + elif opt == "-v": + verbose = 1 + elif opt == "-d": + debug = 1 + else: + assert 0 + + if output_file == None: + usage() + + if len(args) != 2: + usage() + + exec_file = args[0] + core_file = args[1] + + run() if __name__ == '__main__': - main() + main() + +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# vi: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# diff --git a/tools/rdps.py b/tools/rdps.py index 8f6a958bfc..2de425a62e 100755 --- a/tools/rdps.py +++ b/tools/rdps.py @@ -147,3 +147,14 @@ def main(): if __name__ == "__main__": main() +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# vi: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# diff --git a/tools/wireshark_gen.py b/tools/wireshark_gen.py index 8be4e44a8a..4429a93b4b 100755 --- a/tools/wireshark_gen.py +++ b/tools/wireshark_gen.py @@ -75,7 +75,7 @@ import tempfile # # TODO -- FS # -# 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved] +# 1. generate hf[] data for searchable fields (but what is searchable?) [done, could be improved] # 2. add item instead of add_text() [done] # 3. sequence handling [done] # 4. User Exceptions [done] @@ -217,7 +217,7 @@ class wireshark_gen_C: self.gen_proto_register(oplist, atlist, stlist, unlist) self.gen_proto_reg_handoff(oplist) - # All the dissectors are now built-in + # All the dissectors are now built-in #self.gen_plugin_register() #self.dumpvars() # debug @@ -302,7 +302,7 @@ class wireshark_gen_C: self.st.out(self.template_hf, name=sname + "_return") for p in op.parameters(): - self.st.out(self.template_hf, name=sname + "_" + p.identifier()) + self.st.out(self.template_hf, name=sname + "_" + p.identifier()) # # genAtDeclares() @@ -404,7 +404,7 @@ class wireshark_gen_C: if self.DEBUG: print "XXX genDeclares" - # prototype for operation filters + # prototype for operation filters self.st.out(self.template_hf_operations) #operation specific filters @@ -957,8 +957,8 @@ class wireshark_gen_C: def dumpCvars(self, sname): - for v in self.fn_hash[sname]: - self.st.out(v) + for v in self.fn_hash[sname]: + self.st.out(v) # @@ -1211,7 +1211,7 @@ class wireshark_gen_C: # getCDR_hf() # # This takes a node, and tries to output the appropriate item for the - # hf array. + # hf array. # def getCDR_hf(self,type,desc,filter,hf_name="fred"): @@ -1788,7 +1788,7 @@ class wireshark_gen_C: def gen_proto_register(self, oplist, atlist, stlist, unlist): self.st.out(self.template_proto_register_start, dissector_name=self.dissname) - + #operation specific filters self.st.out(self.template_proto_register_op_filter_comment) for op in oplist: @@ -2001,7 +2001,7 @@ void proto_register_giop_@dissector_name@(void) /* setup list of header fields */ static hf_register_info hf[] = { /* field that indicates the currently ongoing request/reply exchange */ - {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},""" + {&hf_operationrequest, {"Request_Operation","giop-@dissector_name@.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},""" template_proto_register_end = """ }; @@ -2079,7 +2079,7 @@ switch(header->message_type) {""" default: /* Unknown GIOP Message */ expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);""" - + template_helper_switch_msgtype_default_end = """\ break;""" @@ -2111,10 +2111,10 @@ break;""" default: /* Unknown Exception */ expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_exception, "Unknown exception %d", header->rep_status);""" - + template_helper_switch_msgtype_reply_default_end = """\ break;""" - + template_helper_switch_msgtype_reply_end = """\ break;""" @@ -2122,10 +2122,10 @@ break;""" default: /* Unknown GIOP Message */ expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);""" - + template_helper_switch_msgtype_default_end = """\ break;""" - + template_helper_switch_rep_status_start = """\ switch(header->rep_status) {""" @@ -2133,10 +2133,10 @@ switch(header->rep_status) {""" default: /* Unknown Reply Status */ expert_add_info_format(pinfo, item, &ei_@dissector_name@_unknown_reply_status, "Unknown reply status %d", header->rep_status);""" - + template_helper_switch_rep_status_default_end = """\ break;""" - + template_helper_switch_rep_status_end = """\ } /* switch(header->rep_status) */ @@ -2853,3 +2853,14 @@ static void decode_@name@_un(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tr decode_@name@_un(tvb, pinfo, tree, offset, header, operation, stream_is_big_endian); """ +# +# Editor modelines - http://www.wireshark.org/tools/modelines.html +# +# Local variables: +# c-basic-offset: 4 +# indent-tabs-mode: nil +# End: +# +# vi: set shiftwidth=4 expandtab: +# :indentSize=4:noTabs=true: +# -- cgit v1.2.3