#ifndef STARS_IDA_Function_h #define STARS_IDA_Function_h #if __GNUC__ >= 8 #pragma GCC diagnostic ignored "-Wclass-memaccess" #endif #include <pro.h> #include <funcs.hpp> #include <frame.hpp> #if __GNUC__ >= 8 #pragma GCC diagnostic pop #endif #include "interfaces/STARSTypes.h" class SMPFunction; class STARS_IDA_Function_t : public STARS_Function_t { public: // Constructors STARS_IDA_Function_t(func_t* func) : the_func(func), frsize(the_func->frsize), SharedChunks(false), UnsharedChunks(false) {} // Accessor methods #if (IDA_SDK_VERSION < 700) virtual STARS_ea_t get_startEA() { return the_func->startEA; } virtual STARS_ea_t get_endEA() { return the_func->endEA; } #else virtual STARS_ea_t get_startEA() { return the_func->start_ea; } virtual STARS_ea_t get_endEA() { return the_func->end_ea; } #endif virtual STARS_ea_t getFuncID(void) const { return the_func->start_ea; }; virtual std::size_t GetFuncSize() { return (std::size_t) (get_endEA() - get_startEA()); } virtual char* GetFunctionName(char* name, const int len) const { qstring TempName; #if (IDA_SDK_VERSION < 700) STARS_ssize_t NameLen = ::get_func_name2(&TempName, the_func->startEA); #else STARS_ssize_t NameLen = ::get_func_name(&TempName, the_func->start_ea); #endif if (NameLen >= len) { NameLen = len - 1; } return qstrncpy(name, TempName.c_str(), NameLen + 1); }; virtual std::size_t GetFrameSize() { return frsize; } virtual void SetFrameSize(std::size_t fs) { frsize = fs; } virtual std::size_t GetSavedRegSize() { return the_func->frregs; } virtual std::size_t GetIncomingArgumentSize() { return the_func->argsize; } virtual std::size_t GetFrameReturnAddressSize() { return ::get_frame_retsize(the_func); } virtual STARS_sval_t get_spd(STARS_ea_t ea) { return ::get_spd(the_func, ea); } // Mutator methods virtual void SetSharedChunks(bool v) { SharedChunks = v; } // Query methods virtual bool FunctionUsesFP() { return (0 != (the_func->flags & (FUNC_FRAME | FUNC_BOTTOMBP))); } virtual bool HasSharedChunks() const { return SharedChunks; } #if (IDA_SDK_VERSION < 700) virtual bool IsStaticFunction() { return (0 != (the_func->flags & FUNC_STATIC)); } #else virtual bool IsStaticFunction() { return (0 != (the_func->flags & FUNC_STATICDEF)); } #endif virtual bool IsLibraryFunction() { return (0 != (the_func->flags & FUNC_LIB)); } virtual bool IsStackPointerAnalyzed() { return the_func->analyzed_sp(); } virtual bool HasReturnPoints() { return the_func->does_return(); } virtual bool IsMultiEntry(bool HasIndirectJumps); virtual bool IsChunkUnshared(STARS_ea_t ChunkAddr, STARS_ea_t FuncHeadStart, STARS_ea_t FuncHeadEnd); virtual bool IsInstIDInFunc(STARS_ea_t InstID); // Analysis methods virtual void MarkSharedChunks(); virtual void UpdateXrefs(); virtual void BuildFuncIR(SMPFunction *func); virtual void FindFixedCalls(SMPFunction *CurrFunc) { assert(false); }; virtual bool FindDistantCodeFragment(SMPFunction* func, STARS_ea_t TargetAddr); void FillInLocalVarTable(SMPFunction *CurrFunc); // get stack frame fine-grained info virtual void FindEHCatchBlocks(void); virtual bool AnalyzeInstAsCallTarget(SMPFunction *CurrFunc, bool &IsIndirectCallTarget, bool &IsTailCallTarget); // return success or failure of analysis // temporary cast operator for testing operator func_t* () { return the_func; } private: func_t* the_func; std::size_t frsize; bool SharedChunks; bool UnsharedChunks; }; #endif