@@ -924,29 +924,32 @@ pub trait BinaryViewExt: BinaryViewBase {
924924 MemoryMap :: new ( self . as_ref ( ) . to_owned ( ) )
925925 }
926926
927- fn add_auto_function ( & self , plat : & Platform , addr : u64 ) -> Option < Ref < Function > > {
928- unsafe {
929- let handle = BNAddFunctionForAnalysis (
930- self . as_ref ( ) . handle ,
931- plat. handle ,
932- addr,
933- false ,
934- std:: ptr:: null_mut ( ) ,
935- ) ;
936-
937- if handle. is_null ( ) {
938- return None ;
939- }
927+ /// Add an auto function at the given `address` with the views default platform.
928+ ///
929+ /// NOTE: The default platform **must** be set for this view!
930+ fn add_auto_function ( & self , address : u64 ) -> Option < Ref < Function > > {
931+ let platform = self . default_platform ( ) ?;
932+ self . add_auto_function_with_platform ( address, & platform)
933+ }
940934
941- Some ( Function :: ref_from_raw ( handle) )
942- }
935+ /// Add an auto function at the given `address` with the `platform`.
936+ ///
937+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
938+ fn add_auto_function_with_platform (
939+ & self ,
940+ address : u64 ,
941+ platform : & Platform ,
942+ ) -> Option < Ref < Function > > {
943+ self . add_auto_function_ext ( address, platform, None )
943944 }
944945
945- fn add_function_with_type (
946+ /// Add an auto function at the given `address` with the `platform` and function type.
947+ ///
948+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
949+ fn add_auto_function_ext (
946950 & self ,
947- plat : & Platform ,
948- addr : u64 ,
949- auto_discovered : bool ,
951+ address : u64 ,
952+ platform : & Platform ,
950953 func_type : Option < & Type > ,
951954 ) -> Option < Ref < Function > > {
952955 unsafe {
@@ -957,9 +960,9 @@ pub trait BinaryViewExt: BinaryViewBase {
957960
958961 let handle = BNAddFunctionForAnalysis (
959962 self . as_ref ( ) . handle ,
960- plat . handle ,
961- addr ,
962- auto_discovered ,
963+ platform . handle ,
964+ address ,
965+ true ,
963966 func_type,
964967 ) ;
965968
@@ -971,28 +974,73 @@ pub trait BinaryViewExt: BinaryViewBase {
971974 }
972975 }
973976
974- fn add_entry_point ( & self , plat : & Platform , addr : u64 ) {
977+ /// Remove an auto function from the view.
978+ ///
979+ /// Pass `true` for `update_refs` to update all references of the function.
980+ ///
981+ /// NOTE: Unlike [`BinaryViewExt::remove_user_function`], this will NOT prohibit the function from
982+ /// being re-added in the future, use [`BinaryViewExt::remove_user_function`] to blacklist the
983+ /// function from being automatically created.
984+ fn remove_auto_function ( & self , func : & Function , update_refs : bool ) {
975985 unsafe {
976- BNAddEntryPointForAnalysis ( self . as_ref ( ) . handle , plat . handle , addr ) ;
986+ BNRemoveAnalysisFunction ( self . as_ref ( ) . handle , func . handle , update_refs ) ;
977987 }
978988 }
979989
980- fn create_user_function ( & self , plat : & Platform , addr : u64 ) -> Result < Ref < Function > > {
981- unsafe {
982- let func = BNCreateUserFunction ( self . as_ref ( ) . handle , plat. handle , addr) ;
990+ /// Add a user function at the given `address` with the views default platform.
991+ ///
992+ /// NOTE: The default platform **must** be set for this view!
993+ fn add_user_function ( & self , addr : u64 ) -> Option < Ref < Function > > {
994+ let platform = self . default_platform ( ) ?;
995+ self . add_user_function_with_platform ( addr, & platform)
996+ }
983997
998+ /// Add an auto function at the given `address` with the `platform`.
999+ ///
1000+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
1001+ fn add_user_function_with_platform (
1002+ & self ,
1003+ addr : u64 ,
1004+ platform : & Platform ,
1005+ ) -> Option < Ref < Function > > {
1006+ unsafe {
1007+ let func = BNCreateUserFunction ( self . as_ref ( ) . handle , platform. handle , addr) ;
9841008 if func. is_null ( ) {
985- return Err ( ( ) ) ;
1009+ return None ;
9861010 }
987-
988- Ok ( Function :: ref_from_raw ( func) )
1011+ Some ( Function :: ref_from_raw ( func) )
9891012 }
9901013 }
9911014
1015+ /// Removes the function from the view and blacklists it from being created automatically.
1016+ ///
1017+ /// NOTE: If you call [`BinaryViewExt::add_user_function`], it will override the blacklist.
1018+ fn remove_user_function ( & self , func : & Function ) {
1019+ unsafe { BNRemoveUserFunction ( self . as_ref ( ) . handle , func. handle ) }
1020+ }
1021+
9921022 fn has_functions ( & self ) -> bool {
9931023 unsafe { BNHasFunctions ( self . as_ref ( ) . handle ) }
9941024 }
9951025
1026+ /// Add an entry point at the given `address` with the view's default platform.
1027+ ///
1028+ /// NOTE: The default platform **must** be set for this view!
1029+ fn add_entry_point ( & self , addr : u64 ) {
1030+ if let Some ( platform) = self . default_platform ( ) {
1031+ self . add_entry_point_with_platform ( addr, & platform) ;
1032+ }
1033+ }
1034+
1035+ /// Add an entry point at the given `address` with the `platform`.
1036+ ///
1037+ /// NOTE: If the view's default platform is not set, this will set it to `platform`.
1038+ fn add_entry_point_with_platform ( & self , addr : u64 , platform : & Platform ) {
1039+ unsafe {
1040+ BNAddEntryPointForAnalysis ( self . as_ref ( ) . handle , platform. handle , addr) ;
1041+ }
1042+ }
1043+
9961044 fn entry_point_function ( & self ) -> Option < Ref < Function > > {
9971045 unsafe {
9981046 let raw_func_ptr = BNGetAnalysisEntryPoint ( self . as_ref ( ) . handle ) ;
0 commit comments