From 279bd14608484abd117662bbe35b8485d61f9a58 Mon Sep 17 00:00:00 2001 From: Chloe Fortuna Date: Mon, 28 Nov 2022 19:07:47 +0000 Subject: [PATCH] Add option to print diagnostics --- wp/scripts/run.bash | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/wp/scripts/run.bash b/wp/scripts/run.bash index 3211207f..23500237 100755 --- a/wp/scripts/run.bash +++ b/wp/scripts/run.bash @@ -11,6 +11,10 @@ JOBS=1 # Default timeout in seconds TIMEOUT=1000 +# By default, don't print any diagnostics +DIAGNOSTICS=false +RESULTS="/dev/null" + BINARIES=() # Prints out the help/usage message. @@ -26,11 +30,12 @@ function print_help() { printf '\t%-3s%s\n' " " "the original binary, checks if that same address is" printf '\t%-3s%s\n' " " "at a valid location in the modified binary." printf '\nUsage:\n%s ' "$(basename $0)" - printf '%s\n' "[-j|--jobs] [-t|--timeout] [-o|--output] -- " + printf '%s\n' "[-j|--jobs] [-t|--timeout] [-o|--output] [-d|--diagnostics] -- " printf '\t%s\n' "- jobs: How many jobs to run in parallel (default: 1)" printf '\t%s\n' "- timeout: Timeout for each job (default: 1000s)" printf '\t%s\n' "- output: Location of logs and results of each subroutine" printf '\t%-10s%s\n' " " "(default: output-)" + printf '\t%s\n' "- diagnostics: If set, stores the diagnostics of each WP run." } # Parse CLI for overriding default options. @@ -52,6 +57,10 @@ function parse_command_line() { shift shift ;; + -d | --diagnostics) + DIAGNOSTICS=true + shift + ;; -h | --help) print_help exit 0 @@ -86,6 +95,15 @@ function check_binaries() { fi } +# Checks if the user wants to output diagnostics +function check_diagnostics() { + if $DIAGNOSTICS; then + RESULTS_DIR=$OUTPUT/diagnostics + RESULTS="$RESULTS_DIR/{}" + mkdir $RESULTS_DIR + fi +} + # Generate a list of all subroutines in the original binary # (except those of the form sub_* and %abcd1234). function get_all_subs() { @@ -94,12 +112,6 @@ function get_all_subs() { > $NAMES } -# Looks at the results from the previous run and creates a list of subroutines -# that resulted in SAT or UNKNOWN. -function get_sats_and_unknowns() { - grep -L '^UNSAT!$' $RESULTS/* | xargs -L 1 basename -} - # Run WP on the first subroutine of the binaries to prime the cache. Note there # is no timeout on this run. function prime_cache() { @@ -124,7 +136,7 @@ function run() { --compare-post-reg-values=R12,R13,R14,R15,RBX,RSP,RBP,RAX \ --rewrite-addresses \ --check-invalid-derefs \ - ${BINARIES[0]} ${BINARIES[1]} > $RESULTS/{} 2>&1" + ${BINARIES[0]} ${BINARIES[1]} > $RESULTS 2>&1" } # Prints out the number of each result from the run. @@ -165,10 +177,11 @@ check_binaries NAMES=$OUTPUT/names.txt LOGS=$OUTPUT/logs -RESULTS=$OUTPUT/results STATS=$OUTPUT/stats.txt -mkdir -p $OUTPUT $LOGS $RESULTS +mkdir -p $OUTPUT $LOGS + +check_diagnostics echo "Comparing '${BINARIES[0]}' and '${BINARIES[1]}'." | tee -a $STATS