Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • opensrc/SMPStaticAnalyzer
1 result
Show changes
Commits on Source (7)
scons_build
.sconsign.dblite
build_ida/
build_irdb_lib/
......
......@@ -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",
......
......@@ -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")
......
......@@ -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')
......
......@@ -71,7 +71,7 @@ class STARS_IRDB_Instruction_t : public STARS_Instruction_t
// add rax, rdx (intel) means rax=rax+rdx;
// features = STARS_CF_USE1 | STARS_CF_USE2 | STARS_CF_CHG1
virtual uint32_t GetInstFeatures(void) const { return features; }
virtual uint32_t GetInitialInstFeatures(void) const;
virtual uint32_t GetInitialInstFeatures(bool ShiftOperands = false) const;
// jdh: consider returning by reference?
virtual STARSOpndTypePtr GetOpnd(std::size_t OpndNum) const
......
......@@ -19406,7 +19406,7 @@ bool SMPInstr::BuildUnary2OpndRTL(SMPoperator UnaryOp) {
if (NULL != TempRT)
delete TempRT;
#if SMP_DEBUG_BUILD_RTL
SMP_msg("ERROR: Could not find binary operand at %llx for %s\n",
SMP_msg("ERROR: Could not find unary operand at %llx for %s\n",
(unsigned long long) this->GetAddr(), DisAsmText.GetDisAsm(this->GetAddr()));
#endif
}
......@@ -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()
......
......@@ -1492,7 +1492,7 @@ uint16_t STARS_IRDB_Instruction_t::GetIDAOpcode(void)
// add rax, rdx (intel) means rax=rax+rdx;
// features = STARS_CF_USE1 | STARS_CF_USE2 | STARS_CF_CHG1
inline uint32_t STARS_IRDB_Instruction_t::GetInitialInstFeatures(void) const
inline uint32_t STARS_IRDB_Instruction_t::GetInitialInstFeatures(bool ShiftOperands) const
{
uint32_t my_features=0;
......@@ -1508,10 +1508,21 @@ inline uint32_t STARS_IRDB_Instruction_t::GetInitialInstFeatures(void) const
if(disasm.hasOperand(num) && disasm.getOperand(num).isRead()) my_features|=use; \
if(disasm.hasOperand(num) && disasm.getOperand(num).isWritten()) my_features|=def; \
CHECK_ARG(disasm,0, STARS_CF_USE1, STARS_CF_CHG1);
CHECK_ARG(disasm,1, STARS_CF_USE2, STARS_CF_CHG2);
CHECK_ARG(disasm,2, STARS_CF_USE3, STARS_CF_CHG3);
CHECK_ARG(disasm,3, STARS_CF_USE4, STARS_CF_CHG4);
if (!ShiftOperands) {
CHECK_ARG(disasm, 0, STARS_CF_USE1, STARS_CF_CHG1);
CHECK_ARG(disasm, 1, STARS_CF_USE2, STARS_CF_CHG2);
CHECK_ARG(disasm, 2, STARS_CF_USE3, STARS_CF_CHG3);
CHECK_ARG(disasm, 3, STARS_CF_USE4, STARS_CF_CHG4);
}
else {
// An invisible operands has been inserted, e.g. "div rsi" has rax
// as an invisible operand inserted as the first operand. So, RSI
// gets shifted to the second operand, but the disasm still has it
// as the first operand. Shift the bit masks used in the CHECK_ARG macro.
CHECK_ARG(disasm, 0, STARS_CF_USE2, STARS_CF_CHG2);
CHECK_ARG(disasm, 1, STARS_CF_USE3, STARS_CF_CHG3);
CHECK_ARG(disasm, 2, STARS_CF_USE4, STARS_CF_CHG4);
}
return my_features;
}
......@@ -1669,6 +1680,36 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
break;
}
case STARS_NN_cwd: // AX -> DX:AX (with sign)
case STARS_NN_cdq: // EAX -> EDX:EAX (with sign)
case STARS_NN_cqo: // RAX -> RDX:RAX (with sign)
{
if (!disasm.hasOperand(0)) { // all operands are implicit; create them to match IDA
do_default = false;
const auto p = (std::make_shared<STARS_IRDB_op_t>());
p->MakeRegOpnd(STARS_x86_R_ax);
const auto q = (std::make_shared<STARS_IRDB_op_t>());
q->MakeRegOpnd(STARS_x86_R_dx);
switch (this->GetIDAOpcode())
{
case STARS_NN_cwd: p->SetByteWidth(2); q->SetByteWidth(2); break;
case STARS_NN_cdq: p->SetByteWidth(4); q->SetByteWidth(4); break;
case STARS_NN_cqo: p->SetByteWidth(8); q->SetByteWidth(8); break;
default: assert(0);
}
// IDA Pro puts the source RAX first, destination RDX second, for some reason.
// STARS can build the RTL regardless of order, but might as well match.
Operands[0] = p;
Operands[1] = q;
features = (STARS_CF_CHG2 | STARS_CF_USE1);
break;
}
else {
do_default = true;
}
}
case STARS_NN_div:
case STARS_NN_idiv:
case STARS_NN_mul:
......@@ -1678,7 +1719,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
//if (this->disasm.Argument1.ArgType == REGISTER_TYPE + GENERAL_REG + REG0 + REG2)
// this->disasm.Argument1.ArgType = REGISTER_TYPE + GENERAL_REG + REG0;
// get reg num of reg0+reg2 now returns reg0.
if(!disasm.hasOperand(1))
if(!disasm.hasOperand(1)) // e.g. div rsi or mul rcx; RAX is hidden operand
{
shared_ptr<STARS_IRDB_op_t> p = (std::make_shared<STARS_IRDB_op_t>());
p->MakeRegOpnd(STARS_x86_R_ax);
......@@ -1692,7 +1733,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
else
Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>());
}
features=GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE1);
features=GetInitialInstFeatures(true) | (STARS_CF_CHG1 | STARS_CF_USE1);
}
else
do_default=true;
......@@ -1760,13 +1801,13 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
Operands[i + 1] = (std::make_shared<STARS_IRDB_op_t>());
}
if (FloatingStackLoad)
features = GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE2);
features = GetInitialInstFeatures(true) | (STARS_CF_CHG1 | STARS_CF_USE2);
else if (FloatingImmediateLoad) // e.g. ST0 := 0.0 or ST0 := pi;
features = GetInitialInstFeatures() | (STARS_CF_CHG1);
features = GetInitialInstFeatures(true) | (STARS_CF_CHG1);
else if (FPStore)
features = GetInitialInstFeatures() | (STARS_CF_CHG2 | STARS_CF_USE1);
features = GetInitialInstFeatures(true) | (STARS_CF_CHG2 | STARS_CF_USE1);
else
features = GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE1);
features = GetInitialInstFeatures(true) | (STARS_CF_CHG1 | STARS_CF_USE1);
break;
}
......@@ -1792,7 +1833,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
else
Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>());
}
features=GetInitialInstFeatures() | (STARS_CF_USE1);
features=GetInitialInstFeatures(true) | (STARS_CF_USE1);
break;
}
......@@ -1811,7 +1852,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
Operands[1]=p;
}
features=GetInitialInstFeatures()
features=GetInitialInstFeatures(true)
| (STARS_CF_CHG1 | STARS_CF_USE1)
| (STARS_CF_CHG2 | STARS_CF_USE2);
break;
......@@ -1832,7 +1873,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
p->MakeRegOpnd(STARS_x86_R_st1);
Operands[1]=p;
}
features=GetInitialInstFeatures()
features=GetInitialInstFeatures(true)
| (STARS_CF_USE1)
| (STARS_CF_USE2);
break;
......@@ -1870,7 +1911,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
else
Operands[i+1]=(std::make_shared<STARS_IRDB_op_t>());
}
features=GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE1);
features=GetInitialInstFeatures(true) | (STARS_CF_CHG1 | STARS_CF_USE1);
}
else /// missing st0 and st1
{
......@@ -1885,7 +1926,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
p->MakeRegOpnd(STARS_x86_R_st1);
Operands[1]=p;
features=GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE1 | STARS_CF_USE2);
features=GetInitialInstFeatures(false) | (STARS_CF_CHG1 | STARS_CF_USE1 | STARS_CF_USE2);
}
break;
}
......@@ -1907,7 +1948,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
p->MakeRegOpnd(STARS_x86_R_st1);
Operands[1]=p;
features=GetInitialInstFeatures() | (STARS_CF_CHG1 | STARS_CF_USE1 | STARS_CF_USE2);
features=GetInitialInstFeatures(false) | (STARS_CF_CHG1 | STARS_CF_USE1 | STARS_CF_USE2);
break;
}
......@@ -1955,7 +1996,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
p->MakeRegOpnd(STARS_x86_R_st1);
Operands[1]=p;
features=GetInitialInstFeatures() | (STARS_CF_USE1 | STARS_CF_USE2);
features=GetInitialInstFeatures(false) | (STARS_CF_USE1 | STARS_CF_USE2);
break;
}
......@@ -1976,7 +2017,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
p->MakeRegOpnd(STARS_x86_R_st1);
Operands[1]=p;
features=GetInitialInstFeatures() | (STARS_CF_CHG2 | STARS_CF_USE1 | STARS_CF_USE2);
features=GetInitialInstFeatures(false) | (STARS_CF_CHG2 | STARS_CF_USE1 | STARS_CF_USE2);
break;
}
default:
......@@ -1996,7 +2037,7 @@ bool STARS_IRDB_Instruction_t::STARS_GetCmd(void)
else
Operands[i]=(std::make_shared<STARS_IRDB_op_t>());
}
features=GetInitialInstFeatures();
features=GetInitialInstFeatures(false);
}
// Simplify the operand encoding so that identical operands don't appear to be different.
......