Skip to content
Snippets Groups Projects
STARSFunction.h 3.4 KiB
Newer Older
jdh8d's avatar
jdh8d committed
#ifndef STARS_IDA_Function_h
#define STARS_IDA_Function_h

Jason Hiser's avatar
Jason Hiser committed
#if __GNUC__ >= 8
#pragma GCC diagnostic ignored "-Wclass-memaccess"
#include <funcs.hpp>
#include <frame.hpp>

Jason Hiser's avatar
Jason Hiser committed
#if __GNUC__ >= 8
#include "interfaces/STARSTypes.h"

class SMPFunction;

jdh8d's avatar
jdh8d committed
class STARS_IDA_Function_t : public STARS_Function_t
{
jdh8d's avatar
jdh8d committed

jdh8d's avatar
jdh8d committed
		STARS_IDA_Function_t(func_t* func) : 
			the_func(func), 
			frsize(the_func->frsize),
			SharedChunks(false), 
			UnsharedChunks(false)
		{}
jdh8d's avatar
jdh8d committed

jdh8d's avatar
jdh8d committed

clc5q's avatar
clc5q committed
#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; }
clc5q's avatar
clc5q committed
#else
	virtual STARS_ea_t get_startEA() { return the_func->start_ea; }
	virtual STARS_ea_t get_endEA() { return the_func->end_ea; }
clc5q's avatar
clc5q committed
#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;
clc5q's avatar
clc5q committed
#if (IDA_SDK_VERSION < 700)
		STARS_ssize_t NameLen = ::get_func_name2(&TempName, the_func->startEA);
clc5q's avatar
clc5q committed
#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; }
clc5q's avatar
clc5q committed
#if (IDA_SDK_VERSION < 700)
	virtual bool IsStaticFunction() { return (0 != (the_func->flags & FUNC_STATIC)); }
clc5q's avatar
clc5q committed
#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);
clc5q's avatar
clc5q committed
	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;
	bool SharedChunks;
	bool UnsharedChunks;
jdh8d's avatar
jdh8d committed
};

#endif