diff --git a/.gitattributes b/.gitattributes index 0d8e67553c302508ae9467564004076e131b0eae..9fcbea59fb188b5f72016182965609e091b73cae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1058,6 +1058,12 @@ tools/inferfn/SConstruct -text tools/inferfn/inferfn.cpp -text tools/inferfn/inferfn.hpp -text tools/inferfn/inferfn_driver.cpp -text +tools/kill_deads/Makefile.in -text +tools/kill_deads/SConscript -text +tools/kill_deads/SConstruct -text +tools/kill_deads/kill_deads.cpp -text +tools/kill_deads/kill_deads.hpp -text +tools/kill_deads/kill_deads_driver.cpp -text tools/meds2pdb/Makefile.in -text tools/meds2pdb/SConscript -text tools/meds2pdb/SConstruct -text diff --git a/SConscript b/SConscript index 4c3b86e710caa7eba39ffc7a7b425640a81f1aea..0dd6c291a38defd4810f55708da5875a3adce354 100644 --- a/SConscript +++ b/SConscript @@ -80,6 +80,13 @@ libxform=SConscript("xform/SConscript", variant_dir='scons_build/libxform') libtransform=SConscript("libtransform/SConscript", variant_dir='scons_build/libtransform') libIRDB=SConscript("libIRDB/SConscript", variant_dir='scons_build/libIRDB') +if 'build_stars' in env and int(env['build_stars']) == 1: + stars_path=os.environ['SMPSA_HOME'] + stars_sconscript=os.path.join(stars_path,"SConscript"); + argenv=env.Clone() + Export('argenv') + libstars=SConscript(stars_sconscript, variant_dir='scons_build/stars') + if 'build_tools' not in env or env['build_tools'] is None or int(env['build_tools']) == 1: SConscript("tools/SConscript", variant_dir='scons_build/tools') diff --git a/SConstruct b/SConstruct index 3aed6cd6ba3fc769c966a980b8e8b68cabd02e10..4c1df6d025611750ca6462447d73f01b990e4405 100644 --- a/SConstruct +++ b/SConstruct @@ -15,10 +15,12 @@ env.Replace(LINKFLAGS="-fPIC -w ") # parse arguments env.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME']) +env.Replace(SMPSA_HOME=os.environ['SMPSA_HOME']) env.Replace(do_64bit_build=ARGUMENTS.get("do_64bit_build",None)) env.Replace(debug=ARGUMENTS.get("debug",0)) env.Replace(build_appfw=ARGUMENTS.get("build_appfw", 1)) env.Replace(build_tools=ARGUMENTS.get("build_tools", 1)) +env.Replace(build_stars=ARGUMENTS.get("build_stars", 1)) env.Replace(build_cgc=ARGUMENTS.get("build_cgc", 0)) diff --git a/tools/SConscript b/tools/SConscript index 5276aefda5a579e0783e61235b48744f6433a6f6..9e93ff61889ddee3bde04d343283fc049957bbc7 100644 --- a/tools/SConscript +++ b/tools/SConscript @@ -17,6 +17,7 @@ dirs=''' watch_syscall cookbook dump_map + kill_deads ''' cgc_dirs=''' c2e diff --git a/tools/kill_deads/Makefile.in b/tools/kill_deads/Makefile.in new file mode 100644 index 0000000000000000000000000000000000000000..521dc2c07323f832d457aae0085a8e59c89f1858 --- /dev/null +++ b/tools/kill_deads/Makefile.in @@ -0,0 +1,42 @@ + + +PROGS=fix_rets.exe + +CXX=@CXX@ +CXXFLAGS= +INCLUDE=-I. -I../include -I../xform -I../../beaengine/include -I../../libIRDB/include/ -I../../libMEDSannotation/include/ -I../libtransform/include/ -I../transforms +CXXFLAGS= @EXTRA_CXXFLAGS@ $(INCLUDE) -Wall +LIBS=-L../../lib -lxform -lIRDB-core -lIRDB-cfg -lBeaEngine_s_d -lpqxx -lMEDSannotation -ltransform -lpq + + +OBJS=fix_rets.o fix_rets_driver.o +programs=fix_rets.exe + +.SUFFIXES: .o .c .exe .cpp .hpp + +all: $(programs) + @echo "---------------------------------------------" + @echo "- Fix Rets directory -- Build complete -" + @echo "---------------------------------------------" + + +-include $(OBJS:.o=.d) + +%.o: %.cpp + $(CXX) -c $(CXXFLAGS) $*.cpp + @# + @# build dependencies -- http://scottmcpeak.com/autodepend/autodepend.html + @# + @cpp -M $(CXXFLAGS) $*.cpp > $*.d || true + @cp -f $*.d $*.d.tmp + @sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $*.d + @rm -f $*.d.tmp + +clean: + rm -f *.o core *.exe + +$(programs): ../../lib/*.a + +fix_rets.exe: $(OBJS) + $(CXX) $(CXXFLAGS) $^ $(INCLUDE) $(LIBS) -o $@ + diff --git a/tools/kill_deads/SConscript b/tools/kill_deads/SConscript new file mode 100644 index 0000000000000000000000000000000000000000..64026bcbc3a321885ba46a03e020dc4fd24b5e9d --- /dev/null +++ b/tools/kill_deads/SConscript @@ -0,0 +1,33 @@ +import os + + + +Import('env') +myenv=env.Clone() +myenv.Replace(SECURITY_TRANSFORMS_HOME=os.environ['SECURITY_TRANSFORMS_HOME']) + +cpppath=''' + $SECURITY_TRANSFORMS_HOME/include + $SECURITY_TRANSFORMS_HOME/libIRDB/include + $SECURITY_TRANSFORMS_HOME/libMEDSannotation/include + $SECURITY_TRANSFORMS_HOME/beaengine/include + $SECURITY_TRANSFORMS_HOME/tools/transforms + $SMPSA_HOME/include + ''' + + +files=Glob( Dir('.').srcnode().abspath+"/*.cpp") + + +pgm="kill_deads.exe" + +LIBPATH="$SECURITY_TRANSFORMS_HOME/lib" +LIBS=Split("stars "+ env.subst('$BASE_IRDB_LIBS')+ " IRDB-cfg IRDB-util transform rewrite MEDSannotation ") +myenv=myenv.Clone(CPPPATH=Split(cpppath)) +pgm=myenv.Program(pgm, files, LIBPATH=LIBPATH, LIBS=LIBS) +#install=myenv.Install("$SECURITY_TRANSFORMS_HOME/bin/", pgm) +install=myenv.Install("$SECURITY_TRANSFORMS_HOME/plugins_install/", pgm) +Default(install) + + + diff --git a/tools/kill_deads/SConstruct b/tools/kill_deads/SConstruct new file mode 100644 index 0000000000000000000000000000000000000000..c96332f0422ad5df0853931209219d9a2e20bc17 --- /dev/null +++ b/tools/kill_deads/SConstruct @@ -0,0 +1,6 @@ + + + +env=Environment() +Export('env') +lib=SConscript("SConscript") diff --git a/tools/kill_deads/kill_deads.cpp b/tools/kill_deads/kill_deads.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99c04ff76d5dd224d9067be699d1aa3a3fba84b9 --- /dev/null +++ b/tools/kill_deads/kill_deads.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2014, 2015 - University of Virginia + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from the University + * of Virginia. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: University of Virginia + * e-mail: jwd@virginia.com + * URL : http://www.cs.virginia.edu/ + * + */ + +#include "kill_deads.hpp" + +#include <assert.h> +#include <stars.h> + +using namespace libTransform; +using namespace libIRDB; +using namespace STARS; +using namespace std; + +KillDeads::KillDeads(FileIR_t *p_variantIR, pqxxDB_t& p_dbinterface) + : + Transform(NULL, p_variantIR, NULL), + dbinterface(p_dbinterface) +{ + +} + +int KillDeads::execute() +{ + IRDB_Interface_t stars_analysis_engine(dbinterface); + stars_analysis_engine.do_STARS(getFileIR()); + +} diff --git a/tools/kill_deads/kill_deads.hpp b/tools/kill_deads/kill_deads.hpp new file mode 100644 index 0000000000000000000000000000000000000000..1622418117b5f21af962ff3dba47e97845e96e06 --- /dev/null +++ b/tools/kill_deads/kill_deads.hpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2014, 2015 - University of Virginia + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from the University + * of Virginia. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: University of Virginia + * e-mail: jwd@virginia.com + * URL : http://www.cs.virginia.edu/ + * + */ + +#ifndef _LIBTRANSFORM_KILL_DEADS_H +#define _LIBTRANSFORM_KILL_DEADS_H + +#include <libIRDB-core.hpp> +#include "../../libtransform/include/transform.hpp" +#include "../../libMEDSannotation/include/VirtualOffset.hpp" + +class KillDeads : public libTransform::Transform +{ + public: + KillDeads(libIRDB::FileIR_t *p_variantIR, libIRDB::pqxxDB_t &p_dbinterface); + int execute(); + + private: + libIRDB::pqxxDB_t &dbinterface; +}; +#endif diff --git a/tools/kill_deads/kill_deads_driver.cpp b/tools/kill_deads/kill_deads_driver.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a2f3e696ac67ec4c727763d570412f5d2f47923 --- /dev/null +++ b/tools/kill_deads/kill_deads_driver.cpp @@ -0,0 +1,108 @@ +/* + * Copyright (c) 2014, 2015 - University of Virginia + * + * This file may be used and modified for non-commercial purposes as long as + * all copyright, permission, and nonwarranty notices are preserved. + * Redistribution is prohibited without prior written consent from the University + * of Virginia. + * + * Please contact the authors for restrictions applying to commercial use. + * + * THIS SOURCE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF + * MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + * + * Author: University of Virginia + * e-mail: jwd@virginia.com + * URL : http://www.cs.virginia.edu/ + * + */ + +#include <stdlib.h> +#include <fstream> +#include <libIRDB-core.hpp> +#include <libgen.h> + +#include "kill_deads.hpp" + +using namespace std; +using namespace libIRDB; + +void usage(char* name) +{ + cerr<<"Usage: "<<name<<" <variant_id>\n"; +} + +int main(int argc, char **argv) +{ + if(argc != 2) + { + usage(argv[0]); + exit(1); + } + + string programName(argv[0]); + int variantID = atoi(argv[1]); + + VariantID_t *pidp=NULL; + + /* setup the interface to the sql server */ + pqxxDB_t pqxx_interface; + BaseObj_t::SetInterface(&pqxx_interface); + + pidp=new VariantID_t(variantID); + assert(pidp->IsRegistered()==true); + + cout<<"ret_shadow_stack.exe started\n"; + + bool one_success = false; + for(set<File_t*>::iterator it=pidp->GetFiles().begin(); + it!=pidp->GetFiles().end(); + ++it) + { + File_t* this_file = *it; + FileIR_t *firp = new FileIR_t(*pidp, this_file); + + cout<<"Transforming "<<this_file->GetURL()<<endl; + + assert(firp && pidp); + + try + { + KillDeads kill_deads(firp, pqxx_interface); + + + int success=kill_deads.execute(); + + if (success) + { + cout<<"Writing changes for "<<this_file->GetURL()<<endl; + one_success = true; + firp->WriteToDB(); + delete firp; + } + else + { + cout<<"Skipping (no changes) "<<this_file->GetURL()<<endl; + } + } + catch (DatabaseError_t pnide) + { + cerr << programName << ": Unexpected database error: " << pnide << "file url: " << this_file->GetURL() << endl; + } + catch (...) + { + cerr << programName << ": Unexpected error file url: " << this_file->GetURL() << endl; + } + } // end file iterator + + // if any integer transforms for any files succeeded, we commit + if (one_success) + { + cout<<"Commiting changes...\n"; + pqxx_interface.Commit(); + } + + return 0; +} +