forked from osmocom/wireshark
Add ability to pull packet from add_packet_to_packet_list() frame.
svn path=/trunk/; revision=4881
This commit is contained in:
parent
7150369e1a
commit
736ac33a0c
|
@ -14,6 +14,8 @@ exec_file = None
|
||||||
core_file = None
|
core_file = None
|
||||||
output_file = None
|
output_file = None
|
||||||
|
|
||||||
|
verbose = 0
|
||||||
|
|
||||||
class BackTrace:
|
class BackTrace:
|
||||||
re_frame = re.compile(r"^#(?P<num>\d+) ")
|
re_frame = re.compile(r"^#(?P<num>\d+) ")
|
||||||
re_func1 = re.compile(r"^#\d+\s+(?P<func>\w+) \(")
|
re_func1 = re.compile(r"^#\d+\s+(?P<func>\w+) \(")
|
||||||
|
@ -193,7 +195,8 @@ def run_gdb(*commands):
|
||||||
|
|
||||||
# Run gdb
|
# Run gdb
|
||||||
cmd = "gdb --nw --quiet --command=%s %s %s" % (fname, exec_file, core_file)
|
cmd = "gdb --nw --quiet --command=%s %s %s" % (fname, exec_file, core_file)
|
||||||
# print "Command is %s" % (cmd,)
|
if verbose:
|
||||||
|
print "Invoking %s" % (cmd,)
|
||||||
try:
|
try:
|
||||||
pipe = os.popen(cmd)
|
pipe = os.popen(cmd)
|
||||||
except OSError, err:
|
except OSError, err:
|
||||||
|
@ -346,49 +349,67 @@ def make_cap_file(pkt_data, lnk_t):
|
||||||
sys.exit("text2pcap did not run succesfully.")
|
sys.exit("text2pcap did not run succesfully.")
|
||||||
|
|
||||||
|
|
||||||
def run():
|
|
||||||
|
|
||||||
|
def try_frame(func_text, cap_len_text, lnk_t_text, data_text):
|
||||||
|
|
||||||
# Get the back trace
|
# Get the back trace
|
||||||
bt_text = run_gdb("bt")
|
bt_text = run_gdb("bt")
|
||||||
bt = BackTrace(bt_text)
|
bt = BackTrace(bt_text)
|
||||||
if not bt.HasFunction("epan_dissect_run"):
|
if not bt.HasFunction(func_text):
|
||||||
print "epan_dissect_run() not found in backtrace."
|
print "%s() not found in backtrace." % (func_text,)
|
||||||
print "A packet cannot be pulled from this core."
|
return 0
|
||||||
sys.exit(1)
|
else:
|
||||||
|
print "%s() found in backtrace." % (func_text,)
|
||||||
|
|
||||||
# Figure out where the call to epan_dissect_run is.
|
# Figure out where the call to epan_dissect_run is.
|
||||||
frame_num = bt.Frame("epan_dissect_run")
|
frame_num = bt.Frame(func_text)
|
||||||
|
|
||||||
# Get the capture length
|
# Get the capture length
|
||||||
cap_len = get_int_from_frame(frame_num, "fd->cap_len")
|
cap_len = get_int_from_frame(frame_num, cap_len_text)
|
||||||
|
|
||||||
# Get the encoding type
|
# Get the encoding type
|
||||||
lnk_t = get_int_from_frame(frame_num, "fd->lnk_t")
|
lnk_t = get_int_from_frame(frame_num, lnk_t_text)
|
||||||
|
|
||||||
# Get the packet data
|
# Get the packet data
|
||||||
pkt_data = get_byte_array_from_frame(frame_num, "data", cap_len)
|
pkt_data = get_byte_array_from_frame(frame_num, data_text, cap_len)
|
||||||
|
|
||||||
# print "Length=%d" % (cap_len,)
|
if verbose:
|
||||||
# print "Encoding=%d" % (lnk_t,)
|
print "Length=%d" % (cap_len,)
|
||||||
# print "Data (%d bytes) = %s" % (len(pkt_data), pkt_data)
|
print "Encoding=%d" % (lnk_t,)
|
||||||
|
print "Data (%d bytes) = %s" % (len(pkt_data), pkt_data)
|
||||||
make_cap_file(pkt_data, lnk_t)
|
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.")
|
||||||
|
|
||||||
|
|
||||||
def usage():
|
def usage():
|
||||||
print "pkt-from-core.py -w capture_file executable-file (core-file or process-id)"
|
print "pkt-from-core.py [-v] -w capture_file executable-file (core-file or process-id)"
|
||||||
print ""
|
print ""
|
||||||
print "\tGiven an executable file and a core file, this tool"
|
print "\tGiven an executable file and a core file, this tool"
|
||||||
print "\tuses gdb to retrieve the packet that was being dissected"
|
print "\tuses gdb to retrieve the packet that was being dissected"
|
||||||
print "\tat the time ethereal/tethereal stopped running. The packet"
|
print "\tat the time ethereal/tethereal stopped running. The packet"
|
||||||
print "\tis saved in the capture_file specified by the -w option."
|
print "\tis saved in the capture_file specified by the -w option."
|
||||||
|
print ""
|
||||||
|
print "\t-v : verbose"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
global exec_file
|
global exec_file
|
||||||
global core_file
|
global core_file
|
||||||
global output_file
|
global output_file
|
||||||
|
global verbose
|
||||||
|
|
||||||
optstring = "w:"
|
optstring = "vw:"
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], optstring)
|
opts, args = getopt.getopt(sys.argv[1:], optstring)
|
||||||
except getopt.error:
|
except getopt.error:
|
||||||
|
@ -397,6 +418,8 @@ def main():
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt == "-w":
|
if opt == "-w":
|
||||||
output_file = arg
|
output_file = arg
|
||||||
|
elif opt == "-v":
|
||||||
|
verbose = 1
|
||||||
else:
|
else:
|
||||||
assert 0
|
assert 0
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue