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
use il::*;
#[derive(Clone, Debug, Deserialize, Hash, Eq, PartialEq, Serialize)]
pub struct Function {
address: u64,
control_flow_graph: ControlFlowGraph,
name: Option<String>,
index: Option<usize>
}
impl Function {
pub fn new(address: u64, control_flow_graph: ControlFlowGraph) -> Function {
Function {
address: address,
control_flow_graph: control_flow_graph,
name: None,
index: None
}
}
pub fn locations(&self) -> Vec<RefFunctionLocation> {
let mut locations = Vec::new();
for block in self.blocks() {
let instructions = block.instructions();
if instructions.is_empty() {
locations.push(RefFunctionLocation::EmptyBlock(block));
}
else {
for instruction in instructions {
locations.push(RefFunctionLocation::Instruction(block, instruction));
}
}
}
for edge in self.edges() {
locations.push(RefFunctionLocation::Edge(edge))
}
locations
}
pub fn address(&self) -> u64 {
self.address
}
pub fn block(&self, index: usize) -> Result<&Block> {
self.control_flow_graph.block(index)
}
pub fn block_mut(&mut self, index: usize) -> Result<&mut Block> {
self.control_flow_graph.block_mut(index)
}
pub fn blocks(&self) -> Vec<&Block> {
self.control_flow_graph.blocks()
}
pub fn blocks_mut(&mut self) -> Vec<&mut Block> {
self.control_flow_graph.blocks_mut()
}
pub fn edge(&self, head: usize, tail: usize) -> Result<&Edge> {
self.control_flow_graph.edge(head, tail)
}
pub fn edges(&self) -> Vec<&Edge> {
self.control_flow_graph.edges()
}
pub fn control_flow_graph(&self) -> &ControlFlowGraph {
&self.control_flow_graph
}
pub fn control_flow_graph_mut(&mut self) -> &mut ControlFlowGraph {
&mut self.control_flow_graph
}
pub fn name(&self) -> String {
match self.name {
Some(ref name) => name.to_string(),
None => format!("unknown@{:08X}", self.address)
}
}
pub fn set_name(&mut self, name: Option<String>) {
self.name = name;
}
pub fn index(&self) -> Option<usize> {
self.index
}
pub fn set_index(&mut self, index: Option<usize>) {
self.index = index;
}
}