@@ -37,7 +37,7 @@ use crate::function::{Function, NativeBlock};
3737use crate :: linear_view:: { LinearDisassemblyLine , LinearViewCursor } ;
3838use crate :: metadata:: Metadata ;
3939use crate :: platform:: Platform ;
40- use crate :: progress:: ProgressExecutor ;
40+ use crate :: progress:: { NoProgressCallback , ProgressCallback } ;
4141use crate :: project:: file:: ProjectFile ;
4242use crate :: rc:: * ;
4343use crate :: references:: { CodeReference , DataReference } ;
@@ -145,11 +145,10 @@ pub trait BinaryViewBase: AsRef<BinaryView> {
145145 fn default_endianness ( & self ) -> Endianness ;
146146 fn address_size ( & self ) -> usize ;
147147
148- // TODO saving fileaccessor
149148 fn save ( & self ) -> bool {
150149 self . as_ref ( )
151150 . parent_view ( )
152- . map ( |bv| bv . save ( ) )
151+ . map ( |view| view . save ( ) )
153152 . unwrap_or ( false )
154153 }
155154}
@@ -627,38 +626,37 @@ pub trait BinaryViewExt: BinaryViewBase {
627626 T : Iterator < Item = I > ,
628627 I : Into < QualifiedNameTypeAndId > ,
629628 {
630- self . define_auto_types_with_progress ( names_sources_and_types, ProgressExecutor :: default ( ) )
629+ self . define_auto_types_with_progress ( names_sources_and_types, NoProgressCallback )
631630 }
632631
633- fn define_auto_types_with_progress < T , I > (
632+ fn define_auto_types_with_progress < T , I , P > (
634633 & self ,
635634 names_sources_and_types : T ,
636- progress : impl Into < ProgressExecutor > ,
635+ mut progress : P ,
637636 ) -> HashMap < String , QualifiedName >
638637 where
639638 T : Iterator < Item = I > ,
640639 I : Into < QualifiedNameTypeAndId > ,
640+ P : ProgressCallback ,
641641 {
642642 let mut types: Vec < BNQualifiedNameTypeAndId > = names_sources_and_types
643643 . map ( Into :: into)
644644 . map ( QualifiedNameTypeAndId :: into_raw)
645645 . collect ( ) ;
646646 let mut result_ids: * mut * mut c_char = std:: ptr:: null_mut ( ) ;
647647 let mut result_names: * mut BNQualifiedName = std:: ptr:: null_mut ( ) ;
648- let boxed_progress = Box :: new ( progress. into ( ) ) ;
649- let leaked_boxed_progress = Box :: into_raw ( boxed_progress) ;
648+
650649 let result_count = unsafe {
651650 BNDefineAnalysisTypes (
652651 self . as_ref ( ) . handle ,
653652 types. as_mut_ptr ( ) ,
654653 types. len ( ) ,
655- Some ( ProgressExecutor :: cb_execute ) ,
656- leaked_boxed_progress as * mut c_void ,
654+ Some ( P :: cb_progress_callback ) ,
655+ & mut progress as * mut P as * mut c_void ,
657656 & mut result_ids as * mut _ ,
658657 & mut result_names as * mut _ ,
659658 )
660659 } ;
661- let _ = unsafe { Box :: from_raw ( leaked_boxed_progress) } ;
662660
663661 for ty in types {
664662 QualifiedNameTypeAndId :: free_raw ( ty) ;
@@ -678,33 +676,30 @@ pub trait BinaryViewExt: BinaryViewBase {
678676 T : Iterator < Item = I > ,
679677 I : Into < QualifiedNameAndType > ,
680678 {
681- self . define_user_types_with_progress ( names_and_types, ProgressExecutor :: default ( ) ) ;
679+ self . define_user_types_with_progress ( names_and_types, NoProgressCallback ) ;
682680 }
683681
684- fn define_user_types_with_progress < T , I > (
685- & self ,
686- names_and_types : T ,
687- progress : impl Into < ProgressExecutor > ,
688- ) where
682+ fn define_user_types_with_progress < T , I , P > ( & self , names_and_types : T , mut progress : P )
683+ where
689684 T : Iterator < Item = I > ,
690685 I : Into < QualifiedNameAndType > ,
686+ P : ProgressCallback ,
691687 {
692688 let mut types: Vec < BNQualifiedNameAndType > = names_and_types
693689 . map ( Into :: into)
694690 . map ( QualifiedNameAndType :: into_raw)
695691 . collect ( ) ;
696- let boxed_progress = Box :: new ( progress. into ( ) ) ;
697- let leaked_boxed_progress = Box :: into_raw ( boxed_progress) ;
692+
698693 unsafe {
699694 BNDefineUserAnalysisTypes (
700695 self . as_ref ( ) . handle ,
701696 types. as_mut_ptr ( ) ,
702697 types. len ( ) ,
703- Some ( ProgressExecutor :: cb_execute ) ,
704- leaked_boxed_progress as * mut c_void ,
698+ Some ( P :: cb_progress_callback ) ,
699+ & mut progress as * mut P as * mut c_void ,
705700 )
706701 } ;
707- let _ = unsafe { Box :: from_raw ( leaked_boxed_progress ) } ;
702+
708703 for ty in types {
709704 QualifiedNameAndType :: free_raw ( ty) ;
710705 }
@@ -1865,8 +1860,7 @@ impl BinaryView {
18651860 }
18661861
18671862 pub fn from_accessor ( meta : & FileMetadata , file : & mut FileAccessor ) -> Result < Ref < Self > > {
1868- let handle =
1869- unsafe { BNCreateBinaryDataViewFromFile ( meta. handle , & mut file. api_object as * mut _ ) } ;
1863+ let handle = unsafe { BNCreateBinaryDataViewFromFile ( meta. handle , & mut file. api_object ) } ;
18701864
18711865 if handle. is_null ( ) {
18721866 return Err ( ( ) ) ;
@@ -1886,6 +1880,17 @@ impl BinaryView {
18861880
18871881 unsafe { Ok ( Ref :: new ( Self { handle } ) ) }
18881882 }
1883+
1884+ /// Save the original binary file to the provided `file_path` along with any modifications.
1885+ pub fn save_to_path ( & self , file_path : impl AsRef < Path > ) -> bool {
1886+ let file = file_path. as_ref ( ) . into_bytes_with_nul ( ) ;
1887+ unsafe { BNSaveToFilename ( self . handle , file. as_ptr ( ) as * mut _ ) }
1888+ }
1889+
1890+ /// Save the original binary file to the provided [`FileAccessor`] along with any modifications.
1891+ pub fn save_to_accessor ( & self , file : & mut FileAccessor ) -> bool {
1892+ unsafe { BNSaveToFile ( self . handle , & mut file. api_object ) }
1893+ }
18891894}
18901895
18911896impl BinaryViewBase for BinaryView {
0 commit comments