Skip to content
Snippets Groups Projects
SMPProgram.h 2.56 KiB
Newer Older
clc5q's avatar
clc5q committed
#ifndef SMPPROGRAM_H
#define SMPPROGRAM_H 1

// SMPProgram.h
//
// This header defines the interfaces needed for analyzing whole programs.

#include <utility>
#include <list>
#include <vector>
#include <map>
#include <set>

#include <cstddef>

#include <pro.h>
#include <ida.hpp>
#include <ua.hpp>

#include "SMPDataFlowAnalysis.h"
#include "SMPInstr.h"
#include "SMPBasicBlock.h"
#include "SMPFunction.h"
#include "ProfilerInformation.h"
clc5q's avatar
clc5q committed

using namespace std;

extern ea_t LowestGlobalVarAddress;
extern ea_t HighestGlobalVarAddress;
extern ea_t LowestCodeAddress;
extern ea_t HighestCodeAddress;

inline bool IsImmedGlobalAddress(ea_t ImmedValue) {
	return ((ImmedValue >= LowestGlobalVarAddress) && (ImmedValue <= HighestGlobalVarAddress));
}

// NOTE: Change this when we do targets with data (ither than switch tables) in code
inline bool IsImmedCodeAddress(ea_t ImmedValue) {
	return ((ImmedValue >= LowestCodeAddress) && (ImmedValue <= HighestCodeAddress));
}

inline bool IsImmedNumeric(ea_t ImmedValue) {
	return (!(IsImmedGlobalAddress(ImmedValue) || IsImmedCodeAddress(ImmedValue)));
}

class LessOff {
public:
	bool operator()(const pair<size_t, bool> &Off1, const pair<size_t, bool> &Off2) const {
		return (Off1.first < Off2.first);
	} // end operator
}; // end class LessOff

clc5q's avatar
clc5q committed
struct GlobalVar {
	ea_t addr;
	size_t size;
	char name[MAXSTR];
	bool ReadOnly;  // came from read-only data segment type
clc5q's avatar
clc5q committed
	flags_t flags;
	set<pair<size_t, bool>, LessOff> FieldOffsets; // bool = accessed through index register by any instruction?
clc5q's avatar
clc5q committed
};

class LtStr{
	public:
	bool operator() (const char* c1, const char* c2) const {
		return strcmp(c1, c2) < 0;
	}
};


clc5q's avatar
clc5q committed
// Class encapsulating all that the SMP static analyzer cares to know
//  about a whole program.
class SMPProgram {
public:
	// Constructors
	SMPProgram(void);  // Default constructor
	~SMPProgram(void); // Destructor
	// Get methods
	// Set methods
	// Query methods
	// Printing methods
	void Dump(void); // debug dump
	// Analysis methods
	void Analyze(ProfilerInformation* pi);  // Analyze all functions in the program
clc5q's avatar
clc5q committed
	void EmitAnnotations(FILE *AnnotFile); // Emit annotations for all functions
private:
	// Data
	map<ea_t, SMPFunction *> FuncMap; // all functions in the program
	map<ea_t, struct GlobalVar> GlobalVarTable; // all global static variables
	set<const char*, LtStr> FuncNameSet;	
clc5q's avatar
clc5q committed

	// Methods
	void InitStaticDataTable(void); // Gather info about global static data locations
	void ComputeGlobalFieldOffsets(struct GlobalVar &CurrGlobal);
	FuncType RecurseAndMarkRetAdd(SMPFunction *);
clc5q's avatar
clc5q committed
}; // end class SMPProgram

#endif