-
Notifications
You must be signed in to change notification settings - Fork 2
/
dm_cfg.h
165 lines (148 loc) · 4.06 KB
/
dm_cfg.h
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* Copyright (c) 2011, Ed Robbins <[email protected]>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef __CFG_H
#define __CFG_H
#include "common.h"
#include "dm_dis.h"
struct dm_instruction_se {
enum ud_mnemonic_code instruction;
int write;
int jump;
int ret;
int disjunctive;
};
struct dm_cfg_node {
NADDR start;
NADDR end;
struct dm_cfg_node **children;
struct dm_cfg_node **parents;
int c_count;
int p_count;
int nonlocal;
int visited;
int pre; /* Pre-order position */
int post; /* Post-order position */
int rpost; /* Reverse Post-order position */
struct dm_cfg_node *idom; /* Immediate dominator of node */
struct dm_cfg_node **df_set; /* Dominance frontier set of node */
int df_count;
enum ud_type *def_vars;/* Vars defined in this node */
int dv_count;
struct phi_function *phi_functions;/* Vars requiring phi funcs */
int pf_count;
struct instruction **instructions; /* Instructions in this node */
int i_count;
};
struct phi_function {
enum ud_type var;
int arguments;
int index;
int *indexes;
struct type_constraint ***constraints;
int *c_counts;
int d_count;
};
struct instruction {
struct ud ud;
int index[3][2];
int cast[3];
struct type_constraint ***constraints; /* Constraints */
int *c_counts; /*# conjunctions */
int d_count; /*# disjunctions */
};
enum type_class {
T_REGISTER,
T_PTR,
T_BASIC,
T_ALPHA,
T_ARRAY,
T_STRUCT
};
enum basic_type {
BT_CHAR = 8, /* 8 bit */
BT_SHORT = 16, /* 16 bit */
BT_INT = 32, /* 32 bit */
BT_LONG = 64 /* 64 bit */
};
struct lval {
int _signed;
int size;
union {
int8_t sbyte;
uint8_t ubyte;
int16_t sword;
uint16_t uword;
int32_t sdword;
uint32_t udword;
int64_t sqword;
uint64_t uqword;
} lval_u;
};
struct type_descriptor {
enum type_class c_type;
/* If register */
enum ud_mnemonic_code reg;
int r_index;
/* If ptr */
struct type_descriptor *p_type;
/* If struct */
struct type_descriptor **types;
struct lval *offsets;
int t_count;
/* If basic type */
enum basic_type b_type;
/* If alpha */
int a_index;
/* If array */
struct type_descriptor *a_type;
/* */
struct type_descriptor *set;
struct type_constraint *def;
};
struct type_constraint {
struct type_descriptor *left;
struct type_descriptor *right;
};
/*
* A linked list of all the CFG blocks so we can free them at the end.
* XXX queue.h
*/
struct ptrs {
void *ptr;
struct ptrs *next;
};
void dm_check_cfg_consistency();
void dm_instruction_se_init();
int dm_cmd_cfg(char **args);
int dm_is_target_in_text(NADDR addr);
struct dm_cfg_node* dm_recover_cfg();
void dm_init_cfg();
struct dm_cfg_node* dm_new_cfg_node(NADDR nstart, NADDR nend);
void dm_print_cfg();
void dm_graph_cfg();
void dm_free_cfg();
struct dm_cfg_node* dm_gen_cfg_block(struct dm_cfg_node *node);
void dm_dfw(struct dm_cfg_node *node);
struct dm_cfg_node* dm_get_unvisited_node();
void dm_depth_first_walk(struct dm_cfg_node *cfg);
void dm_add_parent(struct dm_cfg_node *node,
struct dm_cfg_node *parent);
struct dm_cfg_node* dm_split_cfg_block(struct dm_cfg_node *node,
NADDR addr);
struct dm_cfg_node* dm_find_cfg_node_starting(NADDR addr);
struct dm_cfg_node* dm_find_cfg_node_ending(NADDR addr);
struct dm_cfg_node* dm_find_cfg_node_containing(NADDR addr);
#endif