@@ -39,28 +39,28 @@ use crate::function::{Function, NativeBlock};
3939use crate :: linearview:: { LinearDisassemblyLine , LinearViewCursor } ;
4040use crate :: metadata:: Metadata ;
4141use crate :: platform:: Platform ;
42+ use crate :: rc:: * ;
43+ use crate :: references:: { CodeReference , DataReference } ;
4244use crate :: relocation:: Relocation ;
4345use crate :: section:: { Section , SectionBuilder } ;
4446use crate :: segment:: { Segment , SegmentBuilder } ;
4547use crate :: settings:: Settings ;
48+ use crate :: string:: * ;
4649use crate :: symbol:: { Symbol , SymbolType } ;
4750use crate :: tags:: { Tag , TagType } ;
51+ use crate :: typecontainer:: TypeContainer ;
4852use crate :: typelibrary:: TypeLibrary ;
4953use crate :: types:: {
5054 NamedTypeReference , QualifiedName , QualifiedNameAndType , QualifiedNameTypeAndId , Type ,
5155} ;
56+ use crate :: variable:: DataVariable ;
5257use crate :: Endianness ;
5358use std:: collections:: HashMap ;
5459use std:: ffi:: { c_char, c_void} ;
5560use std:: ops:: Range ;
61+ use std:: path:: Path ;
5662use std:: ptr:: NonNull ;
5763use std:: { ops, result, slice} ;
58-
59- use crate :: rc:: * ;
60- use crate :: references:: { CodeReference , DataReference } ;
61- use crate :: string:: * ;
62- use crate :: typecontainer:: TypeContainer ;
63- use crate :: variable:: DataVariable ;
6464// TODO : general reorg of modules related to bv
6565
6666pub type Result < R > = result:: Result < R , ( ) > ;
@@ -190,7 +190,6 @@ pub trait BinaryViewExt: BinaryViewBase {
190190 fn file ( & self ) -> Ref < FileMetadata > {
191191 unsafe {
192192 let raw = BNGetFileForView ( self . as_ref ( ) . handle ) ;
193-
194193 Ref :: new ( FileMetadata :: from_raw ( raw) )
195194 }
196195 }
@@ -1774,15 +1773,10 @@ impl BinaryView {
17741773 Ref :: new ( Self { handle } )
17751774 }
17761775
1777- pub fn from_filename < S : BnStrCompatible > (
1778- meta : & mut FileMetadata ,
1779- filename : S ,
1780- ) -> Result < Ref < Self > > {
1781- let file = filename. into_bytes_with_nul ( ) ;
1782-
1783- let handle = unsafe {
1784- BNCreateBinaryDataViewFromFilename ( meta. handle , file. as_ref ( ) . as_ptr ( ) as * mut _ )
1785- } ;
1776+ pub fn from_path ( meta : & mut FileMetadata , file_path : impl AsRef < Path > ) -> Result < Ref < Self > > {
1777+ let file = file_path. as_ref ( ) . into_bytes_with_nul ( ) ;
1778+ let handle =
1779+ unsafe { BNCreateBinaryDataViewFromFilename ( meta. handle , file. as_ptr ( ) as * mut _ ) } ;
17861780
17871781 if handle. is_null ( ) {
17881782 return Err ( ( ) ) ;
@@ -1920,13 +1914,25 @@ unsafe impl Sync for BinaryView {}
19201914
19211915impl std:: fmt:: Debug for BinaryView {
19221916 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1923- write ! (
1924- f,
1925- "BinaryView (type: `{}`): '{}', len {:#x}" ,
1926- self . view_type( ) ,
1927- self . file( ) . filename( ) ,
1928- self . len( )
1929- )
1917+ f. debug_struct ( "BinaryView" )
1918+ . field ( "type_name" , & self . type_name ( ) )
1919+ . field ( "file" , & self . file ( ) )
1920+ . field ( "original_image_base" , & self . original_image_base ( ) )
1921+ . field ( "start" , & self . start ( ) )
1922+ . field ( "end" , & self . end ( ) )
1923+ . field ( "len" , & self . len ( ) )
1924+ . field ( "default_platform" , & self . default_platform ( ) )
1925+ . field ( "default_arch" , & self . default_arch ( ) )
1926+ . field ( "default_endianness" , & self . default_endianness ( ) )
1927+ . field ( "entry_point" , & self . entry_point ( ) )
1928+ . field (
1929+ "entry_point_functions" ,
1930+ & self . entry_point_functions ( ) . to_vec ( ) ,
1931+ )
1932+ . field ( "address_size" , & self . address_size ( ) )
1933+ . field ( "sections" , & self . sections ( ) . to_vec ( ) )
1934+ . field ( "segments" , & self . segments ( ) . to_vec ( ) )
1935+ . finish ( )
19301936 }
19311937}
19321938
0 commit comments