@@ -76,6 +76,7 @@ pub type Result<R> = result::Result<R, ()>;
7676pub type BinaryViewEventType = BNBinaryViewEventType ;
7777pub type AnalysisState = BNAnalysisState ;
7878pub type ModificationStatus = BNModificationStatus ;
79+ pub type StringType = BNStringType ;
7980
8081#[ allow( clippy:: len_without_is_empty) ]
8182pub trait BinaryViewBase : AsRef < BinaryView > {
@@ -1905,6 +1906,38 @@ pub trait BinaryViewExt: BinaryViewBase {
19051906 let name = QualifiedName :: from_owned_raw ( result_name) ;
19061907 Some ( ( lib, name) )
19071908 }
1909+
1910+ /// Retrieve all known strings in the binary.
1911+ ///
1912+ /// NOTE: This returns a list of [`StringReference`] as strings may not be representable
1913+ /// as a [`String`] or even a [`BnString`]. It is the caller's responsibility to read the underlying
1914+ /// data and convert it to a representable form.
1915+ fn strings ( & self ) -> Array < StringReference > {
1916+ unsafe {
1917+ let mut count = 0 ;
1918+ let strings = BNGetStrings ( self . as_ref ( ) . handle , & mut count) ;
1919+ Array :: new ( strings, count, ( ) )
1920+ }
1921+ }
1922+
1923+ /// Retrieve all known strings within the provided `range`.
1924+ ///
1925+ /// NOTE: This returns a list of [`StringReference`] as strings may not be representable
1926+ /// as a [`String`] or even a [`BnString`]. It is the caller's responsibility to read the underlying
1927+ /// data and convert it to a representable form.
1928+ fn strings_in_range ( & self , range : Range < u64 > ) -> Array < StringReference > {
1929+ unsafe {
1930+ let mut count = 0 ;
1931+ let strings = BNGetStringsInRange (
1932+ self . as_ref ( ) . handle ,
1933+ range. start ,
1934+ range. end - range. start ,
1935+ & mut count,
1936+ ) ;
1937+ Array :: new ( strings, count, ( ) )
1938+ }
1939+ }
1940+
19081941 //
19091942 // fn type_archives(&self) -> Array<TypeArchive> {
19101943 // let mut ids: *mut *mut c_char = std::ptr::null_mut();
@@ -2190,3 +2223,46 @@ where
21902223 ) ;
21912224 }
21922225}
2226+
2227+ #[ derive( Debug , Copy , Clone , PartialEq , Eq , Hash ) ]
2228+ pub struct StringReference {
2229+ pub ty : StringType ,
2230+ pub start : u64 ,
2231+ pub length : usize ,
2232+ }
2233+
2234+ impl From < BNStringReference > for StringReference {
2235+ fn from ( raw : BNStringReference ) -> Self {
2236+ Self {
2237+ ty : raw. type_ ,
2238+ start : raw. start ,
2239+ length : raw. length ,
2240+ }
2241+ }
2242+ }
2243+
2244+ impl From < StringReference > for BNStringReference {
2245+ fn from ( raw : StringReference ) -> Self {
2246+ Self {
2247+ type_ : raw. ty ,
2248+ start : raw. start ,
2249+ length : raw. length ,
2250+ }
2251+ }
2252+ }
2253+
2254+ impl CoreArrayProvider for StringReference {
2255+ type Raw = BNStringReference ;
2256+ type Context = ( ) ;
2257+ type Wrapped < ' a > = Self ;
2258+ }
2259+
2260+ unsafe impl CoreArrayProviderInner for StringReference {
2261+ unsafe fn free ( raw : * mut Self :: Raw , _count : usize , _context : & Self :: Context ) {
2262+ BNFreeStringReferenceList ( raw)
2263+ }
2264+
2265+ unsafe fn wrap_raw < ' a > ( raw : & ' a Self :: Raw , _context : & ' a Self :: Context ) -> Self :: Wrapped < ' a > {
2266+ Self :: from ( * raw)
2267+ }
2268+ }
0 commit comments