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

#include <funcs.hpp>
#include <frame.hpp>

#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

	virtual STARS_ea_t get_startEA() { return the_func->startEA; }
	virtual STARS_ea_t get_endEA() { return the_func->endEA; }
	virtual char* GetFunctionName(const char* name, const int len) const { return ::get_func_name(the_func->startEA, (char *) name, len); };
	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; }
	virtual bool IsStaticFunction() { return (0 != (the_func->flags & FUNC_STATIC)); }
	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();
	virtual bool IsChunkUnshared(STARS_ea_t ChunkAddr, STARS_ea_t FuncHeadStart, STARS_ea_t FuncHeadEnd);

	// Analysis methods
	virtual void MarkSharedChunks();
	virtual void UpdateXrefs();
	virtual void BuildFuncIR(SMPFunction *func);
	virtual bool FindDistantCodeFragment(SMPFunction* func, STARS_ea_t TargetAddr);
	void FillInLocalVarTable(SMPFunction *CurrFunc); // get stack frame fine-grained info
	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;
	std::size_t frsize;
jdh8d's avatar
jdh8d committed
};

#endif