@@ -947,29 +947,36 @@ pub trait BinaryViewExt: BinaryViewBase {
947947 MemoryMap :: new ( self . as_ref ( ) . to_owned ( ) )
948948 }
949949
950- fn add_auto_function ( & self , plat : & Platform , addr : u64 ) -> Option < Ref < Function > > {
951- unsafe {
952- let handle = BNAddFunctionForAnalysis (
953- self . as_ref ( ) . handle ,
954- plat. handle ,
955- addr,
956- false ,
957- std:: ptr:: null_mut ( ) ,
958- ) ;
959-
960- if handle. is_null ( ) {
961- return None ;
962- }
950+ /// Add an auto function at the given `address` with the views default platform.
951+ ///
952+ /// Use [`BinaryViewExt::add_auto_function_with_platform`] if you wish to specify a platform.
953+ ///
954+ /// NOTE: The default platform **must** be set for this view!
955+ fn add_auto_function ( & self , address : u64 ) -> Option < Ref < Function > > {
956+ let platform = self . default_platform ( ) ?;
957+ self . add_auto_function_with_platform ( address, & platform)
958+ }
963959
964- Some ( Function :: ref_from_raw ( handle) )
965- }
960+ /// Add an auto function at the given `address` with the `platform`.
961+ ///
962+ /// Use [`BinaryViewExt::add_auto_function_ext`] if you wish to specify a function type.
963+ ///
964+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
965+ fn add_auto_function_with_platform (
966+ & self ,
967+ address : u64 ,
968+ platform : & Platform ,
969+ ) -> Option < Ref < Function > > {
970+ self . add_auto_function_ext ( address, platform, None )
966971 }
967972
968- fn add_function_with_type (
973+ /// Add an auto function at the given `address` with the `platform` and function type.
974+ ///
975+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
976+ fn add_auto_function_ext (
969977 & self ,
970- plat : & Platform ,
971- addr : u64 ,
972- auto_discovered : bool ,
978+ address : u64 ,
979+ platform : & Platform ,
973980 func_type : Option < & Type > ,
974981 ) -> Option < Ref < Function > > {
975982 unsafe {
@@ -980,9 +987,9 @@ pub trait BinaryViewExt: BinaryViewBase {
980987
981988 let handle = BNAddFunctionForAnalysis (
982989 self . as_ref ( ) . handle ,
983- plat . handle ,
984- addr ,
985- auto_discovered ,
990+ platform . handle ,
991+ address ,
992+ true ,
986993 func_type,
987994 ) ;
988995
@@ -994,28 +1001,75 @@ pub trait BinaryViewExt: BinaryViewBase {
9941001 }
9951002 }
9961003
997- fn add_entry_point ( & self , plat : & Platform , addr : u64 ) {
1004+ /// Remove an auto function from the view.
1005+ ///
1006+ /// Pass `true` for `update_refs` to update all references of the function.
1007+ ///
1008+ /// NOTE: Unlike [`BinaryViewExt::remove_user_function`], this will NOT prohibit the function from
1009+ /// being re-added in the future, use [`BinaryViewExt::remove_user_function`] to blacklist the
1010+ /// function from being automatically created.
1011+ fn remove_auto_function ( & self , func : & Function , update_refs : bool ) {
9981012 unsafe {
999- BNAddEntryPointForAnalysis ( self . as_ref ( ) . handle , plat . handle , addr ) ;
1013+ BNRemoveAnalysisFunction ( self . as_ref ( ) . handle , func . handle , update_refs ) ;
10001014 }
10011015 }
10021016
1003- fn create_user_function ( & self , plat : & Platform , addr : u64 ) -> Result < Ref < Function > > {
1004- unsafe {
1005- let func = BNCreateUserFunction ( self . as_ref ( ) . handle , plat. handle , addr) ;
1017+ /// Add a user function at the given `address` with the views default platform.
1018+ ///
1019+ /// Use [`BinaryViewExt::add_user_function_with_platform`] if you wish to specify a platform.
1020+ ///
1021+ /// NOTE: The default platform **must** be set for this view!
1022+ fn add_user_function ( & self , addr : u64 ) -> Option < Ref < Function > > {
1023+ let platform = self . default_platform ( ) ?;
1024+ self . add_user_function_with_platform ( addr, & platform)
1025+ }
10061026
1027+ /// Add an auto function at the given `address` with the `platform`.
1028+ ///
1029+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
1030+ fn add_user_function_with_platform (
1031+ & self ,
1032+ addr : u64 ,
1033+ platform : & Platform ,
1034+ ) -> Option < Ref < Function > > {
1035+ unsafe {
1036+ let func = BNCreateUserFunction ( self . as_ref ( ) . handle , platform. handle , addr) ;
10071037 if func. is_null ( ) {
1008- return Err ( ( ) ) ;
1038+ return None ;
10091039 }
1010-
1011- Ok ( Function :: ref_from_raw ( func) )
1040+ Some ( Function :: ref_from_raw ( func) )
10121041 }
10131042 }
10141043
1044+ /// Removes the function from the view and blacklists it from being created automatically.
1045+ ///
1046+ /// NOTE: If you call [`BinaryViewExt::add_user_function`], it will override the blacklist.
1047+ fn remove_user_function ( & self , func : & Function ) {
1048+ unsafe { BNRemoveUserFunction ( self . as_ref ( ) . handle , func. handle ) }
1049+ }
1050+
10151051 fn has_functions ( & self ) -> bool {
10161052 unsafe { BNHasFunctions ( self . as_ref ( ) . handle ) }
10171053 }
10181054
1055+ /// Add an entry point at the given `address` with the view's default platform.
1056+ ///
1057+ /// NOTE: The default platform **must** be set for this view!
1058+ fn add_entry_point ( & self , addr : u64 ) {
1059+ if let Some ( platform) = self . default_platform ( ) {
1060+ self . add_entry_point_with_platform ( addr, & platform) ;
1061+ }
1062+ }
1063+
1064+ /// Add an entry point at the given `address` with the `platform`.
1065+ ///
1066+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
1067+ fn add_entry_point_with_platform ( & self , addr : u64 , platform : & Platform ) {
1068+ unsafe {
1069+ BNAddEntryPointForAnalysis ( self . as_ref ( ) . handle , platform. handle , addr) ;
1070+ }
1071+ }
1072+
10191073 fn entry_point_function ( & self ) -> Option < Ref < Function > > {
10201074 unsafe {
10211075 let raw_func_ptr = BNGetAnalysisEntryPoint ( self . as_ref ( ) . handle ) ;
0 commit comments