From ccec0a10fcc02256ec4b4dfeca8a53d51d8e4c72 Mon Sep 17 00:00:00 2001
From: jdh8d <jdh8d@git.zephyr-software.com>
Date: Fri, 8 Jul 2011 18:41:09 +0000
Subject: [PATCH] First working version of IRDB code integrated.

---
 examples/Makefile          |  2 +-
 tools/db/drop_my_tables.sh | 29 +++++++++++++----------------
 tools/ps_analyze.sh        | 29 +++++++++++++++--------------
 tools/ps_run.sh            | 21 +++++++++------------
 4 files changed, 38 insertions(+), 43 deletions(-)

diff --git a/examples/Makefile b/examples/Makefile
index 56f764b1e..9d8cd4afb 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -63,7 +63,7 @@ clean:
 	rm -Rf peasoup_executable_directory.*
 	rm -f strata.log.*
 	rm -f *.sym
-	# if [ ! "X" = "X"${PGUSER} ]; then sh ../tools/db/drop_my_tables.sh; sh ../tools/db/pdb_setup.sh; fi
+	if [ ! "X" = "X"${PGUSER} ]; then sh ../tools/db/drop_my_tables.sh; sh ../tools/db/pdb_setup.sh; fi
 
 concclean:
 	rm -Rf concolic.files_*
diff --git a/tools/db/drop_my_tables.sh b/tools/db/drop_my_tables.sh
index abd8299f2..1d03212a6 100755
--- a/tools/db/drop_my_tables.sh
+++ b/tools/db/drop_my_tables.sh
@@ -1,19 +1,16 @@
 #!/bin/bash
 
-psql << 'EOF'
-CREATE LANGUAGE plpgsql;
-CREATE OR REPLACE FUNCTION drop_tables(username IN VARCHAR) RETURNS void AS $$
-DECLARE
-    statements CURSOR FOR
-        SELECT tablename FROM pg_tables
-        WHERE tableowner = username;
-BEGIN
-    FOR stmt IN statements LOOP
-        EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(stmt.tablename) || ' CASCADE;';
-    END LOOP;
-END;
-$$
-LANGUAGE plpgsql;
-EOF
 
-psql -c "SELECT drop_tables('$PGUSER');"
+functables=`psql -t -q -c "select function_table_name from variant_info"`
+insntables=`psql -t -q -c "select instruction_table_name from variant_info"`
+addrtables=`psql -t -q -c "select address_table_name from variant_info"`
+othertables="variant_dependency variant_info file_info doip"
+
+for  i in $insntables $addrtables $functables $othertables
+do
+	echo --------------------------------------------------------------------------
+	echo -n Dropping table $i..." "
+	psql -t -q -c "drop table $i cascade;"
+	echo Done.
+	echo --------------------------------------------------------------------------
+done
diff --git a/tools/ps_analyze.sh b/tools/ps_analyze.sh
index 250ab5baf..b292896c9 100755
--- a/tools/ps_analyze.sh
+++ b/tools/ps_analyze.sh
@@ -71,6 +71,16 @@ echo Running IDA Pro static analysis phase ...
 $SMPSA_HOME/SMP-analyze.sh a.ncexe
 echo Done.
 
+#
+# Run concolic engine
+#
+echo Running concolic testing to generate inputs ...
+#$PEASOUP_HOME/tools/do_concolic.sh a  --iterations 25 --logging tracer,instance_times,trace
+$PEASOUP_HOME/tools/do_concolic.sh a  --iterations 25 --logging tracer,trace,inputs 
+# 2>&1 |egrep -e "INPUT VECTOR:" -e "1: argc ="
+# >/dev/null 2>&1 
+echo Done.
+
 
 #
 # Populate IR Database
@@ -99,7 +109,8 @@ if [ ! "X" = "X"$PGUSER ]; then
 			$SECURITY_TRANSFORMS_HOME/libIRDB/test/fill_in_cfg.exe $cloneid		# finish the initial IR 
 			$SECURITY_TRANSFORMS_HOME/libIRDB/test/fix_calls.exe $cloneid		# fix call insns so they are OK for spri emitting
 			$SECURITY_TRANSFORMS_HOME/libIRDB/test/ilr.exe $cloneid			# perform ILR 
-			$SECURITY_TRANSFORMS_HOME/libIRDB/test/generate_spri.exe $cloneid a.ncexe.aspri	# generate the spri code
+			$SECURITY_TRANSFORMS_HOME/libIRDB/test/generate_spri.exe $cloneid a.irdb.aspri	# generate the aspri code
+			$SECURITY_TRANSFORMS_HOME/tools/spasm/spasm a.irdb.aspri a.irdb.bspri	# generate the bspri code
 		fi
 	fi
 	echo	-------------------------------------------------------------------------------
@@ -111,16 +122,6 @@ if [ ! "X" = "X"$PGUSER ]; then
 fi
 
 
-#
-# Run concolic engine
-#
-echo Running concolic testing to generate inputs ...
-#$PEASOUP_HOME/tools/do_concolic.sh a  --iterations 25 --logging tracer,instance_times,trace
-$PEASOUP_HOME/tools/do_concolic.sh a  --iterations 25 --logging tracer,trace,inputs 
-# 2>&1 |egrep -e "INPUT VECTOR:" -e "1: argc ="
-# >/dev/null 2>&1 
-echo Done.
-
 
 #
 # Uncomment this part to test the P1 xform
@@ -132,16 +133,16 @@ echo Done.
 #echo Starting the P1 transform
 #date
 #$PEASOUP_HOME/tools/p1xform.sh $newdir > p1xform.out 2> p1xform.err
-#
+
 #echo $current_dir/$newdir/p1.xform/p1.final
-#
+
 #if [ -f $current_dir/p1.xform/p1.final ]; then
 #  echo List of functions transformed:
 #  cat $current_dir/p1.xform/p1.final
 #else
 #  echo P1 was unable to transform the subject program
 #fi
-#
+
 #date
 #echo Done with the P1 transform
 
diff --git a/tools/ps_run.sh b/tools/ps_run.sh
index 8ecf6e5f9..0ce55fa89 100755
--- a/tools/ps_run.sh
+++ b/tools/ps_run.sh
@@ -10,21 +10,19 @@ datapath=$1
 #
 shift;
 
+#
+# Determine which SPRI file to use;  first priorty goes to one generated from the IRDB.
+#
+if [ -f $datapath/a.irdb.bspri ]; then
+	export STRATA_SPRI_FILE=$datapath/a.irdb.bspri
+elif [ -f $datapath/p1.xform/p1.final.bspri ]; then
+	export STRATA_SPRI_FILE=$datapath/p1.xform/p1.final.bspri 	
+fi
+
 #
 # Run the program with the proper env. vars set., and the arguments to the program specified
 #
 
-if [ -f $datapath/p1.xform/p1.final.bspri ];
-then
-STRATA_DOUBLE_FREE=1 					\
-	STRATA_HEAPRAND=1 				\
-	STRATA_PC_CONFINE=1 				\
-	STRATA_PC_CONFINE_XOR=1				\
-	STRATA_PC_CONFINE_XOR_KEY_LENGTH=1024		\
-	STRATA_ANNOT_FILE=$datapath/a.ncexe.annot 	\
-	STRATA_SPRI_FILE=$datapath/p1.xform/p1.final.bspri 	\
-	$datapath/a.stratafied "$@"
-else
 STRATA_DOUBLE_FREE=1 					\
 	STRATA_HEAPRAND=1 				\
 	STRATA_PC_CONFINE=1 				\
@@ -32,6 +30,5 @@ STRATA_DOUBLE_FREE=1 					\
 	STRATA_PC_CONFINE_XOR_KEY_LENGTH=1024		\
 	STRATA_ANNOT_FILE=$datapath/a.ncexe.annot 	\
 	$datapath/a.stratafied "$@"
-fi
 
 
-- 
GitLab