Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#ifndef SMPFUNCTION_H
#define SMPFUNCTION_H 1
// SMPFunction.h
//
// This header defines the interfaces needed for analyzing functions, performing live variable analysis,
// putting code into SSA form, etc.
#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"
using namespace std;
// Class encapsulating all that the SMP static analyzer cares to know
// about a function.
class SMPFunction {
public:
// Constructors
SMPFunction(func_t *Info); // Default constructor
// Get methods
inline const char *GetFuncName(void) const { return FuncName; };
// Set methods
// Query methods
inline bool HasIndirectCalls(void) const { return IndirectCalls; };
inline bool HasSharedChunks(void) const { return SharedChunks; };
// Printing methods
void Dump(void); // debug dump
// Analysis methods
void Analyze(void); // Analyze all instructions in function
void EmitAnnotations(FILE *AnnotFile);
void RPONumberBlocks(void);
void SetLinks(void); // Link basic blocks and map instructions to blocks
void LiveVariableAnalysis(void); // Perform Live Variable Analysis across all blocks
void ComputeSSA(void); // Compute SSA form data structures
private:
// Data
func_t FuncInfo;
char FuncName[MAXSTR];
list<SMPInstr> Instrs;
list<SMPBasicBlock> Blocks;
map<ea_t, list<SMPBasicBlock>::iterator> InstBlockMap;
vector<list<SMPBasicBlock>::iterator> RPOBlocks;
vector<int> IDom; // Immediate dominators, indexed and valued by block RPO numbers
set<op_t, LessOp> GlobalNames; // operands used in more than one block; needed in SSA
vector<list<int> > BlocksDefinedIn; // What blocks DEF each GlobalName; index = op # in GlobalNames
int BlockCount; // number of basic blocks in the function
bool UseFP; // Does function use a frame pointer?
bool StaticFunc; // Is function declared static?
bool IndirectCalls; // Does function make indirect calls?
bool SharedChunks; // Does function share a tail chunk with other functions?
size_t Size; // Function size in code bytes
asize_t LocalVarsSize; // size of local vars region of stack frame
ushort CalleeSavedRegsSize; // stack size of callee pushed regs
int RetAddrSize; // size of return address on stack (4 for most machines)
asize_t IncomingArgsSize; // size of incoming args on stack
ea_t LocalVarsAllocInstr; // address of instr that allocates stack frame
ea_t LocalVarsDeallocInstr; // address of epilogue instr that deallocs frame
// Methods
void SetStackFrameInfo(void);
ea_t FindAllocPoint(asize_t); // Deal with difficult to find stack frame allocations
bool MDFixFrameInfo(void); // Redefine stack regions for our needs
bool MDFixUseFP(void); // Fix IDA errors affecting UseFP
void EmitStackFrameAnnotations(FILE *AnnotFile, list<SMPInstr>::iterator Instr);
void ComputeIDoms(void); // Compute immediate dominators of all blocks into IDom[]
int IntersectDoms(int, int) const; // Find Dom intersection (as IDom[] index) for 2 blocks
void ComputeDomFrontiers(void); // Compute dominance frontiers for all blocks
void ComputeGlobalNames(void); // Compute the GlobalNames set
void ComputeBlocksDefinedIn(void); // Compute the BlocksDefinedIn vector
void InsertPhiFunctions(void); // Insert SSA phi functions at top of each basic block
void SSARenumber(void); // Renumber SSA subscripts for all names
}; // end class SMPFunction
#endif