@@ -37,7 +37,6 @@ use crate::{
3737 platform:: Platform ,
3838 rc:: * ,
3939 relocation:: CoreRelocationHandler ,
40- string:: BnStrCompatible ,
4140 string:: * ,
4241 types:: { Conf , NameAndType , Type } ,
4342 { BranchType , Endianness } ,
@@ -1085,8 +1084,8 @@ impl CoreArchitecture {
10851084 CoreArchitectureList ( archs, count)
10861085 }
10871086
1088- pub fn by_name ( name : & str ) -> Option < Self > {
1089- let res = unsafe { BNGetArchitectureByName ( name. into_bytes_with_nul ( ) . as_ptr ( ) as * mut _ ) } ;
1087+ pub fn by_name ( name : impl AsCStr ) -> Option < Self > {
1088+ let res = unsafe { BNGetArchitectureByName ( name. as_cstr ( ) . as_ptr ( ) ) } ;
10901089
10911090 match res. is_null ( ) {
10921091 false => Some ( CoreArchitecture ( res) ) ,
@@ -1607,12 +1606,8 @@ macro_rules! cc_func {
16071606
16081607/// Contains helper methods for all types implementing 'Architecture'
16091608pub trait ArchitectureExt : Architecture {
1610- fn register_by_name < S : BnStrCompatible > ( & self , name : S ) -> Option < Self :: Register > {
1611- let name = name. into_bytes_with_nul ( ) ;
1612-
1613- match unsafe {
1614- BNGetArchitectureRegisterByName ( self . as_ref ( ) . 0 , name. as_ref ( ) . as_ptr ( ) as * mut _ )
1615- } {
1609+ fn register_by_name ( & self , name : impl AsCStr ) -> Option < Self :: Register > {
1610+ match unsafe { BNGetArchitectureRegisterByName ( self . as_ref ( ) . 0 , name. as_cstr ( ) . as_ptr ( ) ) } {
16161611 0xffff_ffff => None ,
16171612 reg => self . register_from_id ( reg) ,
16181613 }
@@ -1677,7 +1672,7 @@ pub trait ArchitectureExt: Architecture {
16771672
16781673 fn register_relocation_handler < S , R , F > ( & self , name : S , func : F )
16791674 where
1680- S : BnStrCompatible ,
1675+ S : AsCStr ,
16811676 R : ' static
16821677 + RelocationHandler < Handle = CustomRelocationHandlerHandle < R > >
16831678 + Send
@@ -1700,7 +1695,7 @@ impl<T: Architecture> ArchitectureExt for T {}
17001695
17011696pub fn register_architecture < S , A , F > ( name : S , func : F ) -> & ' static A
17021697where
1703- S : BnStrCompatible ,
1698+ S : AsCStr ,
17041699 A : ' static + Architecture < Handle = CustomArchitectureHandle < A > > + Send + Sync + Sized ,
17051700 F : FnOnce ( CustomArchitectureHandle < A > , CoreArchitecture ) -> A ,
17061701{
@@ -1889,7 +1884,7 @@ where
18891884 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
18901885
18911886 match custom_arch. register_from_id ( reg) {
1892- Some ( reg) => BnString :: new ( reg. name ( ) . as_ref ( ) ) . into_raw ( ) ,
1887+ Some ( reg) => BnString :: new ( reg. name ( ) ) . into_raw ( ) ,
18931888 None => BnString :: new ( "invalid_reg" ) . into_raw ( ) ,
18941889 }
18951890 }
@@ -1901,7 +1896,7 @@ where
19011896 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
19021897
19031898 match custom_arch. flag_from_id ( flag) {
1904- Some ( flag) => BnString :: new ( flag. name ( ) . as_ref ( ) ) . into_raw ( ) ,
1899+ Some ( flag) => BnString :: new ( flag. name ( ) ) . into_raw ( ) ,
19051900 None => BnString :: new ( "invalid_flag" ) . into_raw ( ) ,
19061901 }
19071902 }
@@ -1913,7 +1908,7 @@ where
19131908 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
19141909
19151910 match custom_arch. flag_write_from_id ( flag_write) {
1916- Some ( flag_write) => BnString :: new ( flag_write. name ( ) . as_ref ( ) ) . into_raw ( ) ,
1911+ Some ( flag_write) => BnString :: new ( flag_write. name ( ) ) . into_raw ( ) ,
19171912 None => BnString :: new ( "invalid_flag_write" ) . into_raw ( ) ,
19181913 }
19191914 }
@@ -1925,7 +1920,7 @@ where
19251920 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
19261921
19271922 match custom_arch. flag_class_from_id ( class) {
1928- Some ( class) => BnString :: new ( class. name ( ) . as_ref ( ) ) . into_raw ( ) ,
1923+ Some ( class) => BnString :: new ( class. name ( ) ) . into_raw ( ) ,
19291924 None => BnString :: new ( "invalid_flag_class" ) . into_raw ( ) ,
19301925 }
19311926 }
@@ -1937,7 +1932,7 @@ where
19371932 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
19381933
19391934 match custom_arch. flag_group_from_id ( group) {
1940- Some ( group) => BnString :: new ( group. name ( ) . as_ref ( ) ) . into_raw ( ) ,
1935+ Some ( group) => BnString :: new ( group. name ( ) ) . into_raw ( ) ,
19411936 None => BnString :: new ( "invalid_flag_group" ) . into_raw ( ) ,
19421937 }
19431938 }
@@ -2400,7 +2395,7 @@ where
24002395 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
24012396
24022397 match custom_arch. register_stack_from_id ( stack) {
2403- Some ( stack) => BnString :: new ( stack. name ( ) . as_ref ( ) ) . into_raw ( ) ,
2398+ Some ( stack) => BnString :: new ( stack. name ( ) ) . into_raw ( ) ,
24042399 None => BnString :: new ( "invalid_reg_stack" ) . into_raw ( ) ,
24052400 }
24062401 }
@@ -2466,7 +2461,7 @@ where
24662461 {
24672462 let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
24682463 match custom_arch. intrinsic_from_id ( intrinsic) {
2469- Some ( intrinsic) => BnString :: new ( intrinsic. name ( ) . as_ref ( ) ) . into_raw ( ) ,
2464+ Some ( intrinsic) => BnString :: new ( intrinsic. name ( ) ) . into_raw ( ) ,
24702465 None => BnString :: new ( "invalid_intrinsic" ) . into_raw ( ) ,
24712466 }
24722467 }
@@ -2752,8 +2747,6 @@ where
27522747 custom_arch. skip_and_return_value ( data, addr, val)
27532748 }
27542749
2755- let name = name. into_bytes_with_nul ( ) ;
2756-
27572750 let uninit_arch = ArchitectureBuilder {
27582751 arch : MaybeUninit :: zeroed ( ) ,
27592752 func : Some ( func) ,
@@ -2841,8 +2834,7 @@ where
28412834 } ;
28422835
28432836 unsafe {
2844- let res =
2845- BNRegisterArchitecture ( name. as_ref ( ) . as_ptr ( ) as * mut _ , & mut custom_arch as * mut _ ) ;
2837+ let res = BNRegisterArchitecture ( name. as_cstr ( ) . as_ptr ( ) , & mut custom_arch as * mut _ ) ;
28462838
28472839 assert ! ( !res. is_null( ) ) ;
28482840
0 commit comments