diff --git a/.gitignore b/.gitignore index 457cca1752daa59a485c4829655c2bdd463358b5..7bbc09abbebe92d9f85110dd49457ab91bae799f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +scons_build .sconsign.dblite build_ida/ build_irdb_lib/ diff --git a/SConscript b/SConscript index fc2c595fceda3aa016252c3c9c8a0ada4783ecc2..d4a6069d08a481247b8077b1ebc00429cfb75089 100644 --- a/SConscript +++ b/SConscript @@ -117,6 +117,7 @@ Export('argenv', 'STARS_CCFLAGS', 'STARS_LDFLAGS', 'STARS_LDPREFIX') installers=[] + if int(argenv['build_ida']) == 1 or int(argenv['build_ida7']) == 1: if argenv['IDASDK'] is None: print 'Cannot proceed without IDASDK set.' @@ -136,16 +137,17 @@ if int(argenv['build_ida']) == 1 or int(argenv['build_ida7']) == 1: if int(argenv['build_ida']) == 1: print "Build IDA Plugin" - lib=SConscript('SConscript.ida', variant_dir='build_ida') + idalib=SConscript('SConscript.ida', variant_dir='build_ida') elif int(argenv['build_ida7']) == 1: print "Build IDA 7.0+ Plugin" - lib=SConscript('SConscript.ida7', variant_dir='build_ida') + idalib=SConscript('SConscript.ida7', variant_dir='build_ida') print "Done build IDA Plugin" - test=argenv.Command(target="./test.log", source=lib, action="IDAROOT=$IDAROOT SMPSA_HOME=$SMPSA_HOME $SMPSA_HOME/tests/scripts/make_baseline.sh 2>&1 |tee ./test.log") - argenv.Depends(test,lib) + test=argenv.Command(target="./test.log", source=idalib, action="IDAROOT=$IDAROOT SMPSA_HOME=$SMPSA_HOME $SMPSA_HOME/tests/scripts/make_baseline.sh 2>&1 |tee ./test.log") + argenv.Depends(test,idalib) ab=argenv.AlwaysBuild(test) argenv.Default(ab) installers=installers+ab + Default(idalib) if int(argenv['build_irdb']) == 1 or int(argenv['build_irdb_driver']) == 1: @@ -153,12 +155,23 @@ if int(argenv['build_irdb']) == 1 or int(argenv['build_irdb_driver']) == 1: print 'Cannot build libstars.a without SECURITY_TRANSFORMS_HOME set. Did you forget the env. var.? Or try setting build_irdb=0. ' exit(1) print "Build IDA/IRDB library" - lib=SConscript('SConscript.irdb_lib', variant_dir='build_irdb_lib') - installers=installers+lib + irdblib=SConscript('SConscript.irdb_lib', variant_dir='build_irdb_lib') + installers=installers+irdblib + Default(irdblib) + +libehp=argenv.SConscript("libehp/SConscript", variant_dir='scons_build/libehp'); +libehp=argenv.Install("$SMPSA_HOME/libehp/lib", libehp); +try: + argenv.Depends(idalib, libehp) +except: + print "Skipping build of ida lib" -Default(lib) +try: + argenv.Depends(irdblib, libehp) +except: + print "Skipping build of irdb lib" if 'PEDI_HOME' in os.environ: pedi = Command( target = "./testoutput", diff --git a/SConscript.ida b/SConscript.ida index a9514f79699c676a8f3cc9d0d47fb04e3abee3a1..c55a1b31222d7e8e374721968557347338f5500d 100644 --- a/SConscript.ida +++ b/SConscript.ida @@ -67,6 +67,7 @@ else: idaenv=idaenv.Clone(CCFLAGS=IDA_CCFLAGS, SHLINKFLAGS=IDA_LDFLAGS, SHLIBSUFFIX=SHLIBSUF, SHLIBPREFIX="", CPPPATH=Split(cpppath)); lib=idaenv.SharedLibrary('SMPStaticAnalyzer', files, LIBPATH="$IDAROOT", libs="ida") +Depends(lib,"$SMPSA_HOME/libehp/lib/libehp.a") install=idaenv.Install("$IDAROOT/idc/", "$SMPSA_HOME/scripts/SMP.idc") diff --git a/SConscript.ida7 b/SConscript.ida7 index c9f87a5fe5c0c7d27cd76d59f45ba81dc1f4671e..2e2d64c3a6cdcdd23a5bae0dcadfd78f17988df2 100644 --- a/SConscript.ida7 +++ b/SConscript.ida7 @@ -23,7 +23,7 @@ cpppath=''' \ $SMPSA_HOME/include/interfaces/abstract \ $IDASDK/include \ $SMPSA_HOME/include/interfaces/idapro \ - $SECURITY_TRANSFORMS_HOME/libehp/include \ + $SMPSA_HOME/libehp/include \ ''' IDA_CCFLAGS=''' -std=c++11 \ @@ -51,10 +51,10 @@ unused_flags=''' if int(idaenv['do_64bit_analysis']) == 1: - IDA_LDFLAGS="-m64 --shared -L$IDAROOT -lida64 \ + IDA_LDFLAGS="-m64 --shared -Wl,--whole-archive $SMPSA_HOME/libehp/lib/libehp.a -Wl,--no-whole-archive -L$IDAROOT -lida64 \ -Wl,--version-script=$SMPSA_HOME/scripts/plugin.script" else: - IDA_LDFLAGS="-m64 --shared -L$IDAROOT -lida \ + IDA_LDFLAGS="-m64 --shared -Wl,--whole-archive $SMPSA_HOME/libehp/lib/libehp.a -Wl,--no-whole-archive -L$IDAROOT -lida \ -Wl,--version-script=$SMPSA_HOME/scripts/plugin.script" IDA_LDFLAGS+=STARS_LDFLAGS @@ -78,7 +78,6 @@ if int(idaenv['do_64bit_analysis']) == 1: else: lib=idaenv.SharedLibrary('SMPStaticAnalyzer', files, LIBPATH="$IDAROOT", libs="ida") - install=idaenv.Install("$IDAROOT/idc/", "$SMPSA_HOME/scripts/SMP.idc") Default(install) @@ -102,7 +101,7 @@ Default(install) install=idaenv.Install("$IDAROOT/plugins/", lib) Default(install) -Return('install') +Return('lib') diff --git a/src/interfaces/idapro/STARSInterface.cpp b/src/interfaces/idapro/STARSInterface.cpp index 272edc7bb6e77e6ac63fd673e36472b0126b39ec..a449ce5f45ed4fca84211ce8e5247c75eaa0b930 100644 --- a/src/interfaces/idapro/STARSInterface.cpp +++ b/src/interfaces/idapro/STARSInterface.cpp @@ -11,7 +11,9 @@ #define STARS_USE_EHP_LIB 0 #if STARS_USE_EHP_LIB -#include <ehp.hpp> // security_transforms/libehp/include/ehp.hpp +#ifdef __X64__ +#include <ehp.hpp> // SMPStaticAnalyzer/libehp/include/ehp.hpp +#endif #endif #if 0 @@ -36,8 +38,10 @@ using namespace std; #if STARS_USE_EHP_LIB +#ifdef __X64__ using namespace EHP; #endif +#endif int STARS_IDA_Interface_t::STARS_fprintf(FILE *fp, const char *format, ...) { va_list va; va_start(va, format); @@ -454,9 +458,11 @@ bool STARS_IDA_Interface_t::AuditFunctionBoundaries(const STARS_ea_t startEA, co bool STARS_IDA_Interface_t::AuditEHFunctionBoundaries(void) const { bool ProblemFound = false; #if STARS_USE_EHP_LIB +#ifdef __X64__ // stub out for 32-bit plugins; libehp is 64 bits // Use the FDEs (Frame Descriptor Entries) from the eh_frame section // to perform the same algorithm as above: an FDE should contain only one func. - const auto & EHParser = EHFrameParser_t::factory(global_STARS_program->GetRootFileName()); + const string ExeFileName = global_STARS_program->GetRootFileName(); + auto EHParser = EHP::EHFrameParser_t::factory(ExeFileName); const auto FDEvecptr = EHParser->getFDEs(); for (const auto FDEveciter : *FDEvecptr) { uint64_t startAddr = FDEveciter->getStartAddress(); @@ -474,8 +480,9 @@ bool STARS_IDA_Interface_t::AuditEHFunctionBoundaries(void) const { (uint64_t) CurrStartEA, (uint64_t) (CurrEndEA - 1)); } } // end for (const auto FDEveciter : *FDEvecptr) - -#endif + +#endif // __X64__ +#endif // STARS_USE_EHP_LIB return ProblemFound; } // end of STARS_IDA_Interface_t::AuditEHFunctionBoundaries()