2011-10-27 02:32:32 +00:00
|
|
|
#!/bin/bash
|
2012-05-01 18:59:12 +00:00
|
|
|
|
|
|
|
# A small script to export some variables and run tshark or wireshark in
|
|
|
|
# valgrind on a given capture file.
|
|
|
|
#
|
|
|
|
# Copyright 2012 Jeff Morriss <jeff.morriss.ws [AT] gmail.com>
|
2011-10-27 02:32:32 +00:00
|
|
|
#
|
2012-05-01 18:59:12 +00:00
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
|
|
|
# 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
|
2012-06-28 23:18:38 +00:00
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2011-10-27 02:32:32 +00:00
|
|
|
|
|
|
|
# Directory containing tshark or wireshark. Default current directory.
|
2015-06-26 06:48:48 +00:00
|
|
|
if [ -z "$WIRESHARK_BIN_DIR" ]; then
|
|
|
|
WIRESHARK_BIN_DIR=.
|
|
|
|
fi
|
2011-10-27 02:32:32 +00:00
|
|
|
|
|
|
|
# Use tshark by default
|
|
|
|
COMMAND=tshark
|
2012-12-02 02:58:29 +00:00
|
|
|
COMMAND_ARGS="-nr"
|
2012-03-16 14:12:01 +00:00
|
|
|
COMMAND_ARGS2=
|
2012-11-09 02:10:48 +00:00
|
|
|
VALID=0
|
|
|
|
PCAP=""
|
2013-09-12 13:45:04 +00:00
|
|
|
TOOL="memcheck"
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2016-02-07 14:01:28 +00:00
|
|
|
while getopts ":2a:b:C:lmnpP:rstTYwcevWdG" OPTCHAR ; do
|
2011-10-27 02:32:32 +00:00
|
|
|
case $OPTCHAR in
|
2012-07-26 02:38:34 +00:00
|
|
|
2) COMMAND_ARGS="-2 $COMMAND_ARGS" ;;
|
2017-01-20 22:27:17 +00:00
|
|
|
a) ADDITIONAL_SUPPRESSION_FILE="$ADDITIONAL_SUPPRESSION_FILE --suppressions=$OPTARG" ;;
|
2015-06-26 06:48:48 +00:00
|
|
|
b) WIRESHARK_BIN_DIR=$OPTARG ;;
|
2012-07-26 02:38:34 +00:00
|
|
|
C) COMMAND_ARGS="-C $OPTARG $COMMAND_ARGS" ;;
|
2011-10-27 02:32:32 +00:00
|
|
|
l) LEAK_CHECK="--leak-check=full" ;;
|
2013-09-12 13:45:04 +00:00
|
|
|
m) TOOL="massif" ;;
|
2012-11-09 02:10:48 +00:00
|
|
|
n) COMMAND_ARGS="-v"
|
|
|
|
VALID=1 ;;
|
2013-09-12 13:45:04 +00:00
|
|
|
p) TOOL="callgrind" ;;
|
2013-11-11 18:44:50 +00:00
|
|
|
P) TOOL="callgrind"
|
|
|
|
CALLGRIND_OUT_FILE="--callgrind-out-file=$OPTARG" ;;
|
2012-12-01 20:51:20 +00:00
|
|
|
r) REACHABLE="--show-reachable=yes" ;;
|
2016-02-07 14:01:28 +00:00
|
|
|
s) GEN_SUPPRESSIONS="--gen-suppressions=yes" ;;
|
2012-04-30 13:20:27 +00:00
|
|
|
t) TRACK_ORIGINS="--track-origins=yes" ;;
|
2012-12-04 00:05:58 +00:00
|
|
|
T) COMMAND_ARGS="-Vx $COMMAND_ARGS" ;; # "build the Tree"
|
2014-05-08 19:25:13 +00:00
|
|
|
Y) COMMAND_ARGS="-Y frame $COMMAND_ARGS" ;; # Run with a read filter (but no tree)
|
2012-07-26 02:38:34 +00:00
|
|
|
w) COMMAND=wireshark
|
|
|
|
COMMAND_ARGS="-nr" ;;
|
|
|
|
c) COMMAND=capinfos
|
|
|
|
COMMAND_ARGS="" ;;
|
|
|
|
e) COMMAND=editcap
|
|
|
|
COMMAND_ARGS="-E 0.02"
|
|
|
|
# We don't care about the output of editcap
|
|
|
|
COMMAND_ARGS2="/dev/null" ;;
|
2017-02-20 15:35:32 +00:00
|
|
|
v) VERBOSE="--num-callers=256 -v" ;;
|
2013-03-15 16:42:05 +00:00
|
|
|
W) COMMAND=wireshark
|
|
|
|
COMMAND_ARGS=""
|
|
|
|
VALID=1 ;;
|
2015-06-26 21:16:47 +00:00
|
|
|
G) COMMAND=wireshark-gtk
|
2014-05-09 12:11:05 +00:00
|
|
|
COMMAND_ARGS=""
|
|
|
|
VALID=1 ;;
|
2014-05-08 19:25:13 +00:00
|
|
|
d) COMMAND=dumpcap
|
2014-05-09 12:11:05 +00:00
|
|
|
COMMAND_ARGS="-i eth1 -c 3000"
|
2014-05-08 19:25:13 +00:00
|
|
|
VALID=1 ;;
|
2012-12-02 02:58:29 +00:00
|
|
|
*) printf "Unknown option -$OPTARG!\n"
|
|
|
|
exit ;;
|
2011-10-27 02:32:32 +00:00
|
|
|
esac
|
|
|
|
done
|
|
|
|
shift $(($OPTIND - 1))
|
|
|
|
|
2017-02-20 15:35:32 +00:00
|
|
|
# Sanitize parameters
|
|
|
|
if [ "$COMMAND" != "tshark" ] && [[ $COMMAND_ARGS =~ Vx ]]
|
|
|
|
then
|
|
|
|
printf "\nYou can't use -T if you're not using tshark\n\n" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2012-11-09 02:10:48 +00:00
|
|
|
if [ $# -ge 1 ]
|
2011-10-27 02:32:32 +00:00
|
|
|
then
|
2012-11-09 02:10:48 +00:00
|
|
|
PCAP=$1
|
|
|
|
VALID=1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ $VALID -eq 0 ]
|
|
|
|
then
|
2017-01-13 09:15:51 +00:00
|
|
|
printf "\nUsage: $(basename $0) [-2] [-a file] [-b bin_dir] [-c] [-e] [-C config_profile] "
|
|
|
|
printf "[-l] [-m] [-n] [-p] [-r] [-s] [-t] [-T] [-w] [-v] /path/to/file.pcap\n"
|
|
|
|
printf "\n"
|
|
|
|
printf "[-2]: run tshark with 2-pass analysis\n"
|
|
|
|
printf "[-a]: additional valgrind suppression file\n"
|
|
|
|
printf "[-b]: tshark binary dir\n"
|
|
|
|
printf "[-e]: use 'editcap -E 0.02' instead of tshark\n"
|
|
|
|
printf "[-c]: use capinfos instead of tshark\n"
|
|
|
|
printf "[-C]: binary profile file\n"
|
|
|
|
printf "[-l]: add valgring option --leak-check=full\n"
|
|
|
|
printf "[-m]: use valgrind massif tool\n"
|
|
|
|
printf "[-n]: print binary version\n"
|
|
|
|
printf "[-p]: use callgrind massif tool\n"
|
|
|
|
printf "[-r]: add valgrind option --show-reachable=yes\n"
|
|
|
|
printf "[-s]: add valgrind option --gen-suppressions=yes\n"
|
|
|
|
printf "[-t]: add valgrind option --track-origins=yes\n"
|
|
|
|
printf "[-T]: build the tshark tree (-Vx)\n"
|
|
|
|
printf "[-w]: use wireshark instead of tshark\n"
|
|
|
|
printf "[-v]: run in verbose mode (--num-callers=256)\n"
|
2012-07-26 02:38:34 +00:00
|
|
|
exit 1
|
2011-10-27 02:32:32 +00:00
|
|
|
fi
|
|
|
|
|
2015-06-26 06:48:48 +00:00
|
|
|
if [ "$WIRESHARK_BIN_DIR" = "." ]; then
|
2011-10-27 02:32:32 +00:00
|
|
|
export WIRESHARK_RUN_FROM_BUILD_DIRECTORY=
|
|
|
|
fi
|
|
|
|
|
2013-09-12 13:45:04 +00:00
|
|
|
if [ "$TOOL" != "callgrind" ]; then
|
|
|
|
export WIRESHARK_DEBUG_WMEM_OVERRIDE=simple
|
|
|
|
export G_SLICE=always-malloc # or debug-blocks
|
|
|
|
fi
|
2011-10-27 02:32:32 +00:00
|
|
|
|
2015-06-26 06:48:48 +00:00
|
|
|
COMMAND="$WIRESHARK_BIN_DIR/$COMMAND"
|
2013-08-16 01:52:51 +00:00
|
|
|
|
|
|
|
if file $COMMAND | grep -q "ASCII text"; then
|
|
|
|
if [ -x "`dirname $0`/../libtool" ]; then
|
|
|
|
LIBTOOL="`dirname $0`/../libtool"
|
|
|
|
else
|
|
|
|
LIBTOOL="libtool"
|
|
|
|
fi
|
|
|
|
LIBTOOL="$LIBTOOL --mode=execute"
|
|
|
|
else
|
|
|
|
LIBTOOL=""
|
|
|
|
fi
|
|
|
|
|
2016-02-07 14:01:28 +00:00
|
|
|
cmdline="$LIBTOOL valgrind --suppressions=`dirname $0`/vg-suppressions $ADDITIONAL_SUPPRESSION_FILE \
|
2017-02-01 20:59:14 +00:00
|
|
|
--suppressions=`dirname $0`/gtk.suppression \
|
2016-02-07 14:01:28 +00:00
|
|
|
--tool=$TOOL $CALLGRIND_OUT_FILE $VERBOSE $LEAK_CHECK $REACHABLE $GEN_SUPPRESSIONS $TRACK_ORIGINS \
|
|
|
|
$COMMAND $COMMAND_ARGS $PCAP $COMMAND_ARGS2"
|
|
|
|
|
2017-02-20 15:35:32 +00:00
|
|
|
if [ "$VERBOSE" != "" ];then
|
2016-02-07 14:01:28 +00:00
|
|
|
echo -e "\n$cmdline\n"
|
|
|
|
fi
|
|
|
|
|
|
|
|
$cmdline > /dev/null
|