Smart-Contract-Vulnerabilities-DB / run_on_database.sh
run_on_database.sh
Raw
#!/bin/bash

usage() { 
	echo "$(basename "$0") [-c command -o out_dir -j] -- How to run a vulnerability detection tool on the database automatically

	-h  show this help text
	-c  command line
	-o output directory
	-j use JSON for output, instead of the default TXT"
	exit;
}

out_file_type="txt"
while getopts c:o:j flag; do
    case "${flag}" in
        c) command=${OPTARG};;
        o) outdir=${OPTARG};;
		j) out_file_type="json";;
		?) usage;;
    esac
done
if [ -z "${command}" ] || [ -z "${outdir}" ]; then
	usage
fi

if [ ! -d "saida" ]; then
	mkdir saida
fi

vulnerabilities=$(ls Base)
for vulnerability in $vulnerabilities; do
	printf "\nAnalyzing files on vulnerability: $vulnerability\n"
	development_types=$(ls Base/$vulnerability)
	for development_type in $development_types; do
		contracts=$(ls Base/$vulnerability/$development_type)
			for contract in $contracts; do
				out_file_name=${vulnerability}_${development_type}_${contract%.*}.${out_file_type}
				run_instruction=$(echo $command | sed "s/%sc/Base\/${vulnerability}\/${development_type}\/${contract}/g")
				run_instruction="$run_instruction"
				echo "Analyzing contract $contract with command: $run_instruction"
				$run_instruction > ${outdir}/${out_file_name} 2> /dev/null
			done
	done
done