@@ -4,9 +4,33 @@ use crate::convert::{to_bn_symbol_at_address, to_bn_type};
44use crate :: plugin:: ffi:: { BNWARPFunction , BNWARPFunctionGUID , BNWarpConstraint } ;
55use binaryninja:: function:: Function ;
66use binaryninja:: rc:: Ref ;
7+ use binaryninja:: string:: BnString ;
78use binaryninjacore_sys:: { BNFunction , BNSymbol , BNType } ;
9+ use std:: ffi:: c_char;
810use std:: mem:: ManuallyDrop ;
911use std:: sync:: Arc ;
12+ use warp:: signature:: comment:: FunctionComment ;
13+
14+ #[ repr( C ) ]
15+ pub struct BNWarpFunctionComment {
16+ pub text : * mut c_char ,
17+ pub offset : i64 ,
18+ }
19+
20+ impl BNWarpFunctionComment {
21+ /// Leaks the text string to be freed with BNWARPFreeFunctionComment
22+ pub fn from_owned ( value : & FunctionComment ) -> Self {
23+ let text = BnString :: into_raw ( BnString :: new ( & value. text ) ) ;
24+ Self {
25+ text,
26+ offset : value. offset ,
27+ }
28+ }
29+
30+ pub fn free_raw ( value : & Self ) {
31+ unsafe { BnString :: free_raw ( value. text ) }
32+ }
33+ }
1034
1135#[ no_mangle]
1236pub unsafe extern "C" fn BNWARPGetFunction (
@@ -119,6 +143,23 @@ pub unsafe extern "C" fn BNWARPFunctionGetConstraints(
119143 raw_constraints_ptr as * mut * mut BNWarpConstraint
120144}
121145
146+ #[ no_mangle]
147+ pub unsafe extern "C" fn BNWARPFunctionGetComments (
148+ function : * mut BNWARPFunction ,
149+ count : * mut usize ,
150+ ) -> * mut BNWarpFunctionComment {
151+ // We do not own function so we should not drop.
152+ let function = ManuallyDrop :: new ( Arc :: from_raw ( function) ) ;
153+ let raw_comments: Box < [ _ ] > = function
154+ . comments
155+ . iter ( )
156+ . map ( BNWarpFunctionComment :: from_owned)
157+ . collect ( ) ;
158+ * count = raw_comments. len ( ) ;
159+ let raw_comments_ptr = Box :: into_raw ( raw_comments) ;
160+ raw_comments_ptr as * mut BNWarpFunctionComment
161+ }
162+
122163#[ no_mangle]
123164pub unsafe extern "C" fn BNWARPFunctionsEqual (
124165 function_a : * mut BNWARPFunction ,
@@ -156,3 +197,11 @@ pub unsafe extern "C" fn BNWARPFreeFunctionList(functions: *mut *mut BNWARPFunct
156197 BNWARPFreeFunctionReference ( function) ;
157198 }
158199}
200+
201+ #[ no_mangle]
202+ pub unsafe extern "C" fn BNWARPFreeFunctionComment ( comment : * mut BNWarpFunctionComment ) {
203+ if comment. is_null ( ) {
204+ return ;
205+ }
206+ BNWarpFunctionComment :: free_raw ( & * comment) ;
207+ }
0 commit comments