From b25439b13d5eaf051ab6f12907b1121927032b68 Mon Sep 17 00:00:00 2001 From: clc5q <clc5q@git.zephyr-software.com> Date: Wed, 20 May 2015 20:51:41 +0000 Subject: [PATCH] Remove IDA Pro header includes from two more files. Former-commit-id: 4e7fc71694815d88dca851e2414f80821b902db2 --- include/interfaces/SMPDBInterface.h | 4 ++ include/interfaces/abstract/STARSInterface.h | 4 ++ include/interfaces/idapro/STARSInterface.h | 4 ++ src/base/ProfilerInformation.cpp | 40 ++++++++--------- src/base/SMPFunction.cpp | 14 ------ src/base/SMPProgram.cpp | 47 ++++++++------------ src/interfaces/idapro/STARSInterface.cpp | 13 ++++++ 7 files changed, 63 insertions(+), 63 deletions(-) diff --git a/include/interfaces/SMPDBInterface.h b/include/interfaces/SMPDBInterface.h index e240c125..73d19ed3 100644 --- a/include/interfaces/SMPDBInterface.h +++ b/include/interfaces/SMPDBInterface.h @@ -175,6 +175,10 @@ extern const char *CallTypeNames[4]; #define SMP_fopen(name, mode) global_stars_interface->STARS_fopen(name, mode) #define SMP_feof(file) feof(file) #define SMP_fclose(file) global_stars_interface->STARS_fclose(file) +#define SMP_ftell(file) global_stars_interface->STARS_ftell(file) +#define SMP_fgetc(file) global_stars_interface->STARS_fgetc(file) +#define SMP_fgets(buffer, buflen, file) global_stars_interface->STARS_fgets(buffer, buflen, file) +#define SMP_fseek(file, offset, whence) global_stars_interface->STARS_fseek(file, offset, whence) #define SMP_getseg(addr) (global_stars_interface->getseg(addr)) #define SMP_getnseg(index) (global_stars_interface->getnseg(index)) diff --git a/include/interfaces/abstract/STARSInterface.h b/include/interfaces/abstract/STARSInterface.h index d3e80020..169bab60 100644 --- a/include/interfaces/abstract/STARSInterface.h +++ b/include/interfaces/abstract/STARSInterface.h @@ -57,6 +57,10 @@ class STARS_Interface_t virtual int STARS_msg(const char *format, ...) = 0; virtual int STARS_fprintf(FILE *fp, const char *format, ...) = 0; virtual int STARS_fscanf(FILE *fp, const char *format, ...) = 0; + virtual long STARS_ftell(FILE *fp) = 0; + virtual int STARS_fgetc(FILE *fp) = 0; + virtual char *STARS_fgets(char *buffer, int buflen, FILE *fp) = 0; + virtual int STARS_fseek(FILE *fp, long offset, int whence) = 0; // String methods virtual char *STARS_strncat(char *dst, const char *src, std::size_t dstsize) = 0; diff --git a/include/interfaces/idapro/STARSInterface.h b/include/interfaces/idapro/STARSInterface.h index 23c0f357..490d0015 100644 --- a/include/interfaces/idapro/STARSInterface.h +++ b/include/interfaces/idapro/STARSInterface.h @@ -82,6 +82,10 @@ public: virtual int STARS_msg(const char *format, ...); virtual int STARS_fprintf(FILE *fp, const char *format, ...); virtual int STARS_fscanf(FILE *fp, const char *format, ...); + virtual long STARS_ftell(FILE *fp); + virtual char *STARS_fgets(char *buffer, int buflen, FILE *fp); + virtual int STARS_fseek(FILE *fp, long offset, int whence); + virtual int STARS_fgetc(FILE *fp) { return qfgetc(fp); }; // String methods virtual char *STARS_strncat(char *dst, const char *src, std::size_t dstsize) { return qstrncat(dst, src, dstsize); }; diff --git a/src/base/ProfilerInformation.cpp b/src/base/ProfilerInformation.cpp index a80e2cbc..b571653c 100644 --- a/src/base/ProfilerInformation.cpp +++ b/src/base/ProfilerInformation.cpp @@ -24,18 +24,13 @@ * URL : http://www.zephyr-software.com/ */ - #include <string> +#include <bitset> + +#include <cassert> #include <cstdlib> #include <ctime> #include <cstring> -#include <bitset> - -#include <pro.h> -#include <assert.h> -#include <ida.hpp> -#include <idp.hpp> -#include <intel.hpp> using namespace std; @@ -131,12 +126,12 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) do { - qfscanf(fin, "%x %d\n", &addr, &(size_type_u.size)); + SMP_fscanf(fin, "%x %d\n", &addr, &(size_type_u.size)); if (SMP_feof(fin)) // deal with blank lines at the EOF break; - qfscanf(fin, "%s%s", type, scope); + SMP_fscanf(fin, "%s%s", type, scope); if (strcmp(type, "FUNC") == 0) { @@ -164,7 +159,7 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) if (strcmp(scope, "INDIRECTCALL")==0) { int target; - qfscanf(fin, "%d", &target); + SMP_fscanf(fin, "%d", &target); indirect_call_map[addr].insert(target); this->ProfilerAnnotsRead++; @@ -173,9 +168,11 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) #if 1 // record the PROF_FIELD into the constant info structure so it's output with the other // profile information. Then rewind and parse out the information correctly. - long pos = qftell(fin); - qfgets(remainder, sizeof(remainder), fin); - qfseek(fin, pos, SEEK_SET); + long pos = SMP_ftell(fin); + char *ResultStr = SMP_fgets(remainder, sizeof(remainder), fin); + assert(NULL != ResultStr); + int ResultCode = SMP_fseek(fin, pos, SEEK_SET); + assert(0 == ResultCode); std::string output_string(remainder); #if 1 SMP_snprintf(remainder, sizeof(remainder), "%x %d %s %s ", addr, size_type_u.size, "INSTR", "PROF_FIELD"); @@ -201,10 +198,10 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) assert(strcmp(scope, "STACK") == 0 || strcmp(scope, "GLOBAL") == 0); /* remaining params are <const> <field> <real_const_if_global> <comment> */ - qfscanf(fin, "%d %s", &the_const, field); + SMP_fscanf(fin, "%d %s", &the_const, field); if (strcmp(type,"PTRIMMEDESP2") == 0 || strcmp(type,"PTRIMMEDABSOLUTE") == 0) - qfscanf(fin, "%x", &real_const); + SMP_fscanf(fin, "%x", &real_const); else real_const = the_const; @@ -257,7 +254,7 @@ ProfilerInformation::ProfilerInformation(const char* fn, SMPProgram *CurrProg) int TempChar; do { - TempChar = qfgetc(fin); + TempChar = SMP_fgetc(fin); } while ((TempChar != '\n') && (TempChar != EOF)); line++; } while (!SMP_feof(fin)); @@ -532,7 +529,7 @@ void MemoryAccessInfo::ProcessMemoryAccessAnnotation(FILE *fin, int addr) { size_t BitVectorSize; // in bits size_t HexGroups; // how many 32-bit hex fields for bit vector - qfscanf(fin, "%s", NameAddrsSize); + SMP_fscanf(fin, "%s", NameAddrsSize); char *EndPtr; // #if defined(WIN32) && (IDA_SDK_VERSION < 640) // Visual Studio has deprecated strtok() and puts out a warning. Disable it @@ -540,8 +537,9 @@ void MemoryAccessInfo::ProcessMemoryAccessAnnotation(FILE *fin, int addr) { // #pragma warning(disable:4996) // #elif (IDA_SDK_VERSION >= 640) // IDA 6.4 and later won't allow strtok, use thread-safe IDA-provided qstrtok + // Better idea: Use the new C++11 strtok_s() when we fully convert to C++11 instead of C++0x char *saveptr; -#define strtok(STR, DELIM) qstrtok(STR, DELIM, &saveptr); +#define strtok(STR, DELIM) strtok_r(STR, DELIM, &saveptr); // #endif char *NamePtr = strtok(NameAddrsSize, ":"); SMP_strncpy(ObjectName, NamePtr, STARS_MAXSTR-1); @@ -570,7 +568,7 @@ void MemoryAccessInfo::ProcessMemoryAccessAnnotation(FILE *fin, int addr) { ObjectSize = (size_t) SignedObjectSize; string ObjectString(ObjectName); - qfscanf(fin, "%d %zu %zu %zu", &ProcessID, &RedundantObjectSize, + SMP_fscanf(fin, "%d %zu %zu %zu", &ProcessID, &RedundantObjectSize, &BitVectorSize, &HexGroups); assert(RedundantObjectSize == ObjectSize); assert(BitVectorSize == (3 * ObjectSize)); @@ -697,7 +695,7 @@ void MemoryAccessInfo::ProcessMemoryAccessAnnotation(FILE *fin, int addr) { break; } - qfscanf(fin, "%x", &CurrHexGroup); + SMP_fscanf(fin, "%x", &CurrHexGroup); if (SMP_feof(fin)) { SMP_msg("ERROR: Premature end of line on memory access annotation for address %lx\n", (unsigned long) InstructionAddress); diff --git a/src/base/SMPFunction.cpp b/src/base/SMPFunction.cpp index f456c959..80d0df31 100644 --- a/src/base/SMPFunction.cpp +++ b/src/base/SMPFunction.cpp @@ -45,20 +45,6 @@ using namespace std; #include <cstdlib> #include <cassert> -// #include <pro.h> -// #include <ua.hpp> -// #include <intel.hpp> - -#if 0 -#include <ida.hpp> -#include <idp.hpp> -#include <auto.hpp> -#include <bytes.hpp> -#include <funcs.hpp> -#include <name.hpp> -#include <struct.hpp> -#endif - #include "interfaces/SMPDBInterface.h" #include "base/SMPDataFlowAnalysis.h" #include "base/SMPFunction.h" diff --git a/src/base/SMPProgram.cpp b/src/base/SMPProgram.cpp index 55726511..080c9026 100644 --- a/src/base/SMPProgram.cpp +++ b/src/base/SMPProgram.cpp @@ -40,23 +40,11 @@ #include <vector> #include <algorithm> +#include <cstdint> #include <cstring> #include <cstdlib> #include <cassert> -#include <pro.h> -#include <ua.hpp> -#include <intel.hpp> - -#if 0 -#include <ida.hpp> -#include <idp.hpp> -#include <auto.hpp> -#include <bytes.hpp> -#include <funcs.hpp> -#include <name.hpp> -#endif - #include "interfaces/SMPDBInterface.h" #include "base/SMPDataFlowAnalysis.h" #include "base/SMPFunction.h" @@ -88,6 +76,9 @@ static const char *DataTypes[] = { "VOID", "NUMHEX", "NUMDEC", "CHAR", "STRUCTOFFSET", "STACKVAR", "NUMFLOAT", "UNKNOWN", "UNKNOWN", "UNKNOWN", 0}; +// Imitate IDA Pro get_optype_flags0() from <bytes.hpp> +#define STARS_get_optype_flags0(flags) (flags & 0x00F00000LU) + #if 0 // Is Address in a data segment? bool IsDataAddress(STARS_ea_t Address) { @@ -676,14 +667,14 @@ void SMPProgram::EmitDataAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { if (TempGlobal.ReadOnly) { SMP_fprintf(AnnotFile, "%10x %6zu DATAREF GLOBAL %8lu %llx PARENT %s %s RO\n", - 0, TempGlobal.size, ParentReferentID, (uint64) TempGlobal.addr, - TempGlobal.name, DataTypes[get_optype_flags0(TempGlobal.flags) >> 20]); + 0, TempGlobal.size, ParentReferentID, (uint64_t) TempGlobal.addr, + TempGlobal.name, DataTypes[STARS_get_optype_flags0(TempGlobal.flags) >> 20]); } else { SMP_fprintf(AnnotFile, "%10x %6zu DATAREF GLOBAL %8lu %llx PARENT %s %s RW\n", - 0, TempGlobal.size, ParentReferentID, (uint64) TempGlobal.addr, - TempGlobal.name, DataTypes[get_optype_flags0(TempGlobal.flags) >> 20]); + 0, TempGlobal.size, ParentReferentID, (uint64_t) TempGlobal.addr, + TempGlobal.name, DataTypes[STARS_get_optype_flags0(TempGlobal.flags) >> 20]); } } else { // structured object with fields @@ -691,14 +682,14 @@ void SMPProgram::EmitDataAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { if (TempGlobal.ReadOnly) { SMP_fprintf(AnnotFile, "%10x %6zu DATAREF GLOBAL %8lu %llx PARENT %s %s RO AGGREGATE\n", - 0, TempGlobal.size, ParentReferentID, (uint64) TempGlobal.addr, - TempGlobal.name, DataTypes[get_optype_flags0(TempGlobal.flags) >> 20]); + 0, TempGlobal.size, ParentReferentID, (uint64_t) TempGlobal.addr, + TempGlobal.name, DataTypes[STARS_get_optype_flags0(TempGlobal.flags) >> 20]); } else { SMP_fprintf(AnnotFile, "%10x %6zu DATAREF GLOBAL %8lu %llx PARENT %s %s RW AGGREGATE\n", - 0, TempGlobal.size, ParentReferentID, (uint64) TempGlobal.addr, - TempGlobal.name, DataTypes[get_optype_flags0(TempGlobal.flags) >> 20]); + 0, TempGlobal.size, ParentReferentID, (uint64_t) TempGlobal.addr, + TempGlobal.name, DataTypes[STARS_get_optype_flags0(TempGlobal.flags) >> 20]); } // Now, emit an annotation for each field offset. set<pair<size_t,bool>, LessOff>::iterator FieldIter, TempIter; @@ -717,7 +708,7 @@ void SMPProgram::EmitDataAnnotations(FILE *AnnotFile, FILE *InfoAnnotFile) { } SMP_fprintf(AnnotFile, "%10x %6zu DATAREF GLOBAL %8lu %llx CHILDOF %lu OFFSET %zu %s + %zu FIELD", - 0, FieldSize, global_STARS_program->GetDataReferentID(), (uint64) TempGlobal.addr, ParentReferentID, + 0, FieldSize, global_STARS_program->GetDataReferentID(), (uint64_t) TempGlobal.addr, ParentReferentID, CurrOffset.first, TempGlobal.name, CurrOffset.first); if (CurrOffset.second) { // indexed accesses to this field SMP_fprintf(AnnotFile, " INDEXED\n"); @@ -829,7 +820,7 @@ FuncType SMPProgram::RecurseAndMarkRetAdd(SMPFunction* FuncAttrib) { #if SMP_DEBUG_FUNC // if a call target is unsafe note it down static char StaticFuncName[MAXSMPSTR]; - qstrncpy(StaticFuncName, ChildInstance->GetFuncName(), (MAXSMPSTR-1)); + SMP_strncpy(StaticFuncName, ChildInstance->GetFuncName(), (MAXSMPSTR-1)); SMP_msg("Function %s marked as unsafe because %s is unsafe.\n", FuncAttrib->GetFuncName(), StaticFuncName); #endif @@ -842,7 +833,7 @@ FuncType SMPProgram::RecurseAndMarkRetAdd(SMPFunction* FuncAttrib) { #if SMP_DEBUG_FUNC // if a call target is unanalyzed, assume it is UNSAFE static char StaticFuncName[MAXSMPSTR]; - qstrncpy(StaticFuncName, ChildInstance->GetFuncName(), (MAXSMPSTR-1)); + SMP_strncpy(StaticFuncName, ChildInstance->GetFuncName(), (MAXSMPSTR-1)); SMP_msg("Function %s marked as unsafe because %s is unanalyzed.\n", FuncAttrib->GetFuncName(), StaticFuncName); #endif @@ -954,7 +945,7 @@ void SMPProgram::PrioritizeCallGraph(void) { while (MapIter != this->TempFuncMap.end()) { CurrFunc = MapIter->second; if (NULL == CurrFunc) { - SMP_msg("ERROR: NULL Func ptr in TempFuncMap for %llx\n", (uint64) MapIter->first); + SMP_msg("ERROR: NULL Func ptr in TempFuncMap for %llx\n", (uint64_t) MapIter->first); ++MapIter; continue; } @@ -988,7 +979,7 @@ void SMPProgram::PrioritizeCallGraph(void) { this->TempFuncMap.erase(NextMapIter); #if STARS_DEBUG_CALL_GRAPH_PRIORITY SMP_msg("INFO: PrioritizeCallGraph selecting unprocessed callee at %llx for func at %llx\n", - (uint64) CalleeAddr, (uint64) BestMapIter->first); + (uint64_t) CalleeAddr, (uint64_t) BestMapIter->first); #endif } else { @@ -996,7 +987,7 @@ void SMPProgram::PrioritizeCallGraph(void) { this->FuncList.push_back(*BestMapIter); #if STARS_DEBUG_CALL_GRAPH_PRIORITY SMP_msg("INFO: PrioritizeCallGraph could not find callee at %llx; had to work on func at %llx\n", - (uint64) CalleeAddr, (uint64) BestMapIter->first); + (uint64_t) CalleeAddr, (uint64_t) BestMapIter->first); #endif this->TempFuncMap.erase(BestMapIter); } @@ -1005,7 +996,7 @@ void SMPProgram::PrioritizeCallGraph(void) { // Work on the BestMapIter function itself. this->FuncList.push_back(*BestMapIter); #if STARS_DEBUG_CALL_GRAPH_PRIORITY - SMP_msg("INFO: PrioritizeCallGraph found STARS_BADADDR for callee; had to work on func at %llx\n", (uint64) BestMapIter->first); + SMP_msg("INFO: PrioritizeCallGraph found STARS_BADADDR for callee; had to work on func at %llx\n", (uint64_t) BestMapIter->first); #endif this->TempFuncMap.erase(BestMapIter); } diff --git a/src/interfaces/idapro/STARSInterface.cpp b/src/interfaces/idapro/STARSInterface.cpp index 9f1f44e8..c90c214e 100644 --- a/src/interfaces/idapro/STARSInterface.cpp +++ b/src/interfaces/idapro/STARSInterface.cpp @@ -33,6 +33,19 @@ int STARS_IDA_Interface_t::STARS_fscanf(FILE *fp, const char *format, ...) { return code; } +long STARS_IDA_Interface_t::STARS_ftell(FILE *fp) { + return (long) qftell(fp); +} + +char * STARS_IDA_Interface_t::STARS_fgets(char *buffer, int buflen, FILE *fp) { + return qfgets(buffer, buflen, fp); +} + +int STARS_IDA_Interface_t::STARS_fseek(FILE *fp, long offset, int whence) { + return qfseek(fp, offset, whence); +} + + int STARS_IDA_Interface_t::STARS_msg(const char *format, ...) { va_list va; va_start(va, format); -- GitLab