Newer
Older
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
unsigned int HighestBitSetInUint(uint32_t UintVal) {
unsigned int RetVal = 0;
unsigned char Byte0 = UintVal & 0xff;
unsigned char Byte1 = UintVal & 0xff00;
unsigned char Byte2 = UintVal & 0xff0000;
unsigned char Byte3 = UintVal & 0xff000000;
if (Byte3 > 0) {
RetVal = HighestBitSet(Byte3) + 24;
}
else if (Byte2 > 0) {
RetVal = HighestBitSet(Byte2) + 16;
}
else if (Byte1 > 0) {
RetVal = HighestBitSet(Byte1) + 8;
}
else if (Byte0 > 0) {
RetVal = HighestBitSet(Byte0);
}
return RetVal;
}
// Initialize the FG info for the return register from any library function
// whose name implies that we know certain return values (e.g. atoi() returns
// a signed integer, while strtoul() returns an unsigned long).
void GetLibFuncFGInfo(string FuncName, struct FineGrainedInfo &InitFGInfo) {
map<string, struct FineGrainedInfo>::iterator FindIter;
FindIter = ReturnRegisterTypeMap.find(FuncName);
if (FindIter == ReturnRegisterTypeMap.end()) { // not found
InitFGInfo.SignMiscInfo = 0;
InitFGInfo.SizeInfo = 0;
}
else { // found
InitFGInfo = FindIter->second;
}
return;
} // end of GetLibFuncFGInfo()
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
// Is FuncName a standard library function name?
bool IsLibFuncName(std::string CalleeName) {
// Return true if we find the name in any of our function type maps.
map<string, struct FineGrainedInfo>::iterator RetTypeIter = ReturnRegisterTypeMap.find(CalleeName);
if (RetTypeIter != ReturnRegisterTypeMap.end()) { // found
return true;
}
map<string, unsigned int>::iterator PtrArgIter = PointerArgPositionMap.find(CalleeName);
if (PtrArgIter != PointerArgPositionMap.end()) { // found it
return true;
}
map<string, unsigned int>::iterator TaintIter = TaintWarningArgPositionMap.find(CalleeName);
if (TaintIter != TaintWarningArgPositionMap.end()) { // found it
return true;
}
map<string, unsigned int>::iterator UnsignedIter = UnsignedArgPositionMap.find(CalleeName);
if (UnsignedIter != UnsignedArgPositionMap.end()) { // found it
return true;
}
map<string, string>::iterator SinkIter = IntegerErrorCallSinkMap.find(CalleeName);
if (SinkIter != IntegerErrorCallSinkMap.end()) { // found it
return true;
}
// Put searches for additional library function names here.
if (0 == CalleeName.compare("setuid")) {
return true;
}
else if (IsStdioLibraryFunc(CalleeName)) {
return true;
}
else if (IsMathLibraryFunc(CalleeName)) {
return true;
}
else if (IsStdlibLibraryFunc(CalleeName)) {
return true;
}
return false;
} // end of IsLibFuncName()
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
// Is FuncName a startup func called before main(), or a wrapup function called by the system?
bool IsStartupFuncName(const std::string FuncName) {
bool NameMatched = false;
char IDA_func_name[STARS_MAXSTR];
std::size_t SkipCount;
SkipCount = strspn(FuncName.c_str(), "._");
std::string TempFuncName = FuncName.substr(SkipCount); // remove leading periods and underscores
if (0 == TempFuncName.compare("init_proc")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("init")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("start")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("gmon_start")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("call_gmon_start")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("libc_start_main")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("call_gmon_start__")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("libc_start_main__")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("libc_csu_init")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("libc_csu_fini")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("do_global_dtors_aux")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("term_proc")) {
NameMatched = true;
}
clc5q
committed
else if (0 == TempFuncName.compare("fini")) {
NameMatched = true;
}
else if (0 == TempFuncName.compare("frame_dummy")) {
NameMatched = true;
}
return NameMatched;
}