11use binaryninjacore_sys:: * ;
2- use std:: ffi:: { c_char , CStr } ;
2+ use std:: ffi:: CStr ;
33
44use crate :: architecture:: CoreArchitecture ;
55use crate :: rc:: { Array , CoreArrayProvider , CoreArrayProviderInner } ;
6+ use crate :: string:: IntoCStr ;
67use std:: num:: NonZeroU32 ;
78use std:: ptr:: NonNull ;
89
@@ -11,7 +12,7 @@ pub type BaseAddressDetectionConfidence = BNBaseAddressDetectionConfidence;
1112pub type BaseAddressDetectionPOIType = BNBaseAddressDetectionPOIType ;
1213
1314/// This is the architecture name used to use the architecture auto-detection feature.
14- const BASE_ADDRESS_AUTO_DETECTION_ARCH : & CStr = c "auto detect";
15+ const BASE_ADDRESS_AUTO_DETECTION_ARCH : & str = "auto detect" ;
1516
1617pub enum BaseAddressDetectionAnalysis {
1718 Basic ,
@@ -149,34 +150,34 @@ impl Drop for BaseAddressDetection {
149150 }
150151}
151152
152- /// Build the initial analysis.
153- ///
154- /// * `analysis` - analysis mode
155- /// * `min_strlen` - minimum length of a string to be considered a point-of-interest
156- /// * `alignment` - byte boundary to align the base address to while brute-forcing
157- /// * `low_boundary` - lower boundary of the base address range to test
158- /// * `high_boundary` - upper boundary of the base address range to test
159- /// * `poi_analysis` - specifies types of points-of-interest to use for analysis
160- /// * `max_pointers` - maximum number of candidate pointers to collect per pointer cluster
153+ /// Builds the initial analysis settings for base address detection.
161154pub struct BaseAddressDetectionSettings {
162155 arch : Option < CoreArchitecture > ,
156+ /// Analysis mode to use
163157 analysis : BaseAddressDetectionAnalysis ,
158+ /// Minimum length of a string to be considered a point-of-interest
164159 min_string_len : u32 ,
160+ /// Byte boundary to align the base address to while brute-forcing
165161 alignment : NonZeroU32 ,
162+ /// Lower boundary of the base address range to test
166163 lower_boundary : u64 ,
164+ /// Upper boundary of the base address range to test
167165 upper_boundary : u64 ,
166+ /// Specifies types of points-of-interest to use for analysis
168167 poi_analysis : BaseAddressDetectionPOISetting ,
168+ /// Maximum number of candidate pointers to collect per pointer cluster
169169 max_pointers : u32 ,
170170}
171171
172172impl BaseAddressDetectionSettings {
173173 pub ( crate ) fn into_raw ( value : & Self ) -> BNBaseAddressDetectionSettings {
174174 let arch_name = value
175175 . arch
176- . map ( |a| a. name ( ) . as_ptr ( ) )
177- . unwrap_or ( BASE_ADDRESS_AUTO_DETECTION_ARCH . as_ptr ( ) as * const u8 ) ;
176+ . map ( |a| a. name ( ) )
177+ . unwrap_or ( BASE_ADDRESS_AUTO_DETECTION_ARCH . to_string ( ) ) ;
178+ let c_arch_name = arch_name. to_cstr ( ) ;
178179 BNBaseAddressDetectionSettings {
179- Architecture : arch_name as * const c_char ,
180+ Architecture : c_arch_name . into_raw ( ) ,
180181 Analysis : value. analysis . as_raw ( ) . as_ptr ( ) ,
181182 MinStrlen : value. min_string_len ,
182183 Alignment : value. alignment . get ( ) ,
@@ -207,6 +208,9 @@ impl BaseAddressDetectionSettings {
207208 self
208209 }
209210
211+ /// Specify the lower boundary of the base address range to test.
212+ ///
213+ /// NOTE: The passed `value` **must** be less than the upper boundary.
210214 pub fn low_boundary ( mut self , value : u64 ) -> Self {
211215 assert ! (
212216 self . upper_boundary >= value,
@@ -216,6 +220,9 @@ impl BaseAddressDetectionSettings {
216220 self
217221 }
218222
223+ /// Specify the upper boundary of the base address range to test.
224+ ///
225+ /// NOTE: The passed `value` **must** be greater than the lower boundary.
219226 pub fn high_boundary ( mut self , value : u64 ) -> Self {
220227 assert ! (
221228 self . lower_boundary <= value,
@@ -230,6 +237,9 @@ impl BaseAddressDetectionSettings {
230237 self
231238 }
232239
240+ /// Specify the maximum number of candidate pointers to collect per pointer cluster.
241+ ///
242+ /// NOTE: The passed `value` **must** be at least 2.
233243 pub fn max_pointers ( mut self , value : u32 ) -> Self {
234244 assert ! ( value > 2 , "max pointers must be at least 2" ) ;
235245 self . max_pointers = value;
0 commit comments