16
16
17
17
use crate :: disassembly:: DisassemblyTextLine ;
18
18
use binaryninjacore_sys:: * ;
19
- use std:: slice;
20
19
21
20
use crate :: rc:: * ;
22
21
23
22
use crate :: basic_block:: { BasicBlock , BlockContext } ;
24
23
use crate :: function:: HighlightColor ;
25
24
use crate :: render_layer:: CoreRenderLayer ;
26
- use std:: marker:: PhantomData ;
27
25
28
26
pub type BranchType = BNBranchType ;
29
27
pub type EdgePenStyle = BNEdgePenStyle ;
@@ -48,30 +46,18 @@ impl FlowGraph {
48
46
unsafe { FlowGraph :: ref_from_raw ( BNCreateFlowGraph ( ) ) }
49
47
}
50
48
51
- pub fn nodes < ' a > ( & self ) -> Vec < Ref < FlowGraphNode < ' a > > > {
49
+ pub fn nodes ( & self ) -> Array < FlowGraphNode > {
52
50
let mut count: usize = 0 ;
53
51
let nodes_ptr = unsafe { BNGetFlowGraphNodes ( self . handle , & mut count as * mut usize ) } ;
54
-
55
- let nodes = unsafe { slice:: from_raw_parts_mut ( nodes_ptr, count) } ;
56
-
57
- let mut result = vec ! [ ] ;
58
- result. reserve ( count) ;
59
-
60
- for i in 0 ..count {
61
- result. push ( unsafe { RefCountable :: inc_ref ( & FlowGraphNode :: from_raw ( nodes[ i] ) ) } ) ;
62
- }
63
-
64
- unsafe { BNFreeFlowGraphNodeList ( nodes_ptr, count) } ;
65
-
66
- result
52
+ unsafe { Array :: new ( nodes_ptr, count, ( ) ) }
67
53
}
68
54
69
- pub fn get_node < ' a > ( & self , i : usize ) -> Option < Ref < FlowGraphNode < ' a > > > {
55
+ pub fn get_node ( & self , i : usize ) -> Option < Ref < FlowGraphNode > > {
70
56
let node_ptr = unsafe { BNGetFlowGraphNode ( self . handle , i) } ;
71
57
if node_ptr. is_null ( ) {
72
58
None
73
59
} else {
74
- Some ( unsafe { Ref :: new ( FlowGraphNode :: from_raw ( node_ptr) ) } )
60
+ Some ( unsafe { FlowGraphNode :: ref_from_raw ( node_ptr) } )
75
61
}
76
62
}
77
63
@@ -146,24 +132,17 @@ impl ToOwned for FlowGraph {
146
132
}
147
133
148
134
#[ derive( PartialEq , Eq , Hash ) ]
149
- pub struct FlowGraphNode < ' a > {
135
+ pub struct FlowGraphNode {
150
136
pub ( crate ) handle : * mut BNFlowGraphNode ,
151
- _data : PhantomData < & ' a ( ) > ,
152
137
}
153
138
154
- impl < ' a > FlowGraphNode < ' a > {
139
+ impl FlowGraphNode {
155
140
pub ( crate ) unsafe fn from_raw ( raw : * mut BNFlowGraphNode ) -> Self {
156
- Self {
157
- handle : raw,
158
- _data : PhantomData ,
159
- }
141
+ Self { handle : raw }
160
142
}
161
143
162
144
pub ( crate ) unsafe fn ref_from_raw ( raw : * mut BNFlowGraphNode ) -> Ref < Self > {
163
- Ref :: new ( Self {
164
- handle : raw,
165
- _data : PhantomData ,
166
- } )
145
+ Ref :: new ( Self { handle : raw } )
167
146
}
168
147
169
148
pub fn new ( graph : & FlowGraph ) -> Ref < Self > {
@@ -233,7 +212,7 @@ impl<'a> FlowGraphNode<'a> {
233
212
pub fn add_outgoing_edge (
234
213
& self ,
235
214
type_ : BranchType ,
236
- target : & ' a FlowGraphNode ,
215
+ target : & FlowGraphNode ,
237
216
edge_style : EdgeStyle ,
238
217
) {
239
218
unsafe {
@@ -242,11 +221,10 @@ impl<'a> FlowGraphNode<'a> {
242
221
}
243
222
}
244
223
245
- unsafe impl RefCountable for FlowGraphNode < ' _ > {
224
+ unsafe impl RefCountable for FlowGraphNode {
246
225
unsafe fn inc_ref ( handle : & Self ) -> Ref < Self > {
247
226
Ref :: new ( Self {
248
227
handle : BNNewFlowGraphNodeReference ( handle. handle ) ,
249
- _data : PhantomData ,
250
228
} )
251
229
}
252
230
@@ -255,14 +233,30 @@ unsafe impl RefCountable for FlowGraphNode<'_> {
255
233
}
256
234
}
257
235
258
- impl ToOwned for FlowGraphNode < ' _ > {
236
+ impl ToOwned for FlowGraphNode {
259
237
type Owned = Ref < Self > ;
260
238
261
239
fn to_owned ( & self ) -> Self :: Owned {
262
240
unsafe { RefCountable :: inc_ref ( self ) }
263
241
}
264
242
}
265
243
244
+ impl CoreArrayProvider for FlowGraphNode {
245
+ type Raw = * mut BNFlowGraphNode ;
246
+ type Context = ( ) ;
247
+ type Wrapped < ' a > = Guard < ' a , FlowGraphNode > ;
248
+ }
249
+
250
+ unsafe impl CoreArrayProviderInner for FlowGraphNode {
251
+ unsafe fn free ( raw : * mut Self :: Raw , count : usize , _: & Self :: Context ) {
252
+ BNFreeFlowGraphNodeList ( raw, count) ;
253
+ }
254
+
255
+ unsafe fn wrap_raw < ' a > ( raw : & ' a Self :: Raw , context : & ' a Self :: Context ) -> Self :: Wrapped < ' a > {
256
+ Guard :: new ( Self :: from_raw ( * raw) , context)
257
+ }
258
+ }
259
+
266
260
#[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
267
261
pub struct EdgeStyle {
268
262
style : EdgePenStyle ,
0 commit comments