@@ -37,7 +37,6 @@ use crate::{
37
37
platform:: Platform ,
38
38
rc:: * ,
39
39
relocation:: CoreRelocationHandler ,
40
- string:: BnStrCompatible ,
41
40
string:: * ,
42
41
types:: { Conf , NameAndType , Type } ,
43
42
{ BranchType , Endianness } ,
@@ -1077,8 +1076,8 @@ impl CoreArchitecture {
1077
1076
CoreArchitectureList ( archs, count)
1078
1077
}
1079
1078
1080
- pub fn by_name ( name : & str ) -> Option < Self > {
1081
- let res = unsafe { BNGetArchitectureByName ( name. into_bytes_with_nul ( ) . as_ptr ( ) as * mut _ ) } ;
1079
+ pub fn by_name ( name : impl AsCStr ) -> Option < Self > {
1080
+ let res = unsafe { BNGetArchitectureByName ( name. as_cstr ( ) . as_ptr ( ) ) } ;
1082
1081
1083
1082
match res. is_null ( ) {
1084
1083
false => Some ( CoreArchitecture ( res) ) ,
@@ -1599,12 +1598,8 @@ macro_rules! cc_func {
1599
1598
1600
1599
/// Contains helper methods for all types implementing 'Architecture'
1601
1600
pub trait ArchitectureExt : Architecture {
1602
- fn register_by_name < S : BnStrCompatible > ( & self , name : S ) -> Option < Self :: Register > {
1603
- let name = name. into_bytes_with_nul ( ) ;
1604
-
1605
- match unsafe {
1606
- BNGetArchitectureRegisterByName ( self . as_ref ( ) . 0 , name. as_ref ( ) . as_ptr ( ) as * mut _ )
1607
- } {
1601
+ fn register_by_name ( & self , name : impl AsCStr ) -> Option < Self :: Register > {
1602
+ match unsafe { BNGetArchitectureRegisterByName ( self . as_ref ( ) . 0 , name. as_cstr ( ) . as_ptr ( ) ) } {
1608
1603
0xffff_ffff => None ,
1609
1604
reg => self . register_from_id ( reg) ,
1610
1605
}
@@ -1677,7 +1672,7 @@ pub trait ArchitectureExt: Architecture {
1677
1672
1678
1673
fn register_relocation_handler < S , R , F > ( & self , name : S , func : F )
1679
1674
where
1680
- S : BnStrCompatible ,
1675
+ S : AsCStr ,
1681
1676
R : ' static
1682
1677
+ RelocationHandler < Handle = CustomRelocationHandlerHandle < R > >
1683
1678
+ Send
@@ -1700,7 +1695,7 @@ impl<T: Architecture> ArchitectureExt for T {}
1700
1695
1701
1696
pub fn register_architecture < S , A , F > ( name : S , func : F ) -> & ' static A
1702
1697
where
1703
- S : BnStrCompatible ,
1698
+ S : AsCStr ,
1704
1699
A : ' static + Architecture < Handle = CustomArchitectureHandle < A > > + Send + Sync + Sized ,
1705
1700
F : FnOnce ( CustomArchitectureHandle < A > , CoreArchitecture ) -> A ,
1706
1701
{
@@ -1889,7 +1884,7 @@ where
1889
1884
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
1890
1885
1891
1886
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 ( ) ,
1893
1888
None => BnString :: new ( "invalid_reg" ) . into_raw ( ) ,
1894
1889
}
1895
1890
}
@@ -1901,7 +1896,7 @@ where
1901
1896
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
1902
1897
1903
1898
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 ( ) ,
1905
1900
None => BnString :: new ( "invalid_flag" ) . into_raw ( ) ,
1906
1901
}
1907
1902
}
@@ -1913,7 +1908,7 @@ where
1913
1908
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
1914
1909
1915
1910
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 ( ) ,
1917
1912
None => BnString :: new ( "invalid_flag_write" ) . into_raw ( ) ,
1918
1913
}
1919
1914
}
@@ -1925,7 +1920,7 @@ where
1925
1920
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
1926
1921
1927
1922
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 ( ) ,
1929
1924
None => BnString :: new ( "invalid_flag_class" ) . into_raw ( ) ,
1930
1925
}
1931
1926
}
@@ -1937,7 +1932,7 @@ where
1937
1932
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
1938
1933
1939
1934
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 ( ) ,
1941
1936
None => BnString :: new ( "invalid_flag_group" ) . into_raw ( ) ,
1942
1937
}
1943
1938
}
@@ -2400,7 +2395,7 @@ where
2400
2395
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
2401
2396
2402
2397
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 ( ) ,
2404
2399
None => BnString :: new ( "invalid_reg_stack" ) . into_raw ( ) ,
2405
2400
}
2406
2401
}
@@ -2466,7 +2461,7 @@ where
2466
2461
{
2467
2462
let custom_arch = unsafe { & * ( ctxt as * mut A ) } ;
2468
2463
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 ( ) ,
2470
2465
None => BnString :: new ( "invalid_intrinsic" ) . into_raw ( ) ,
2471
2466
}
2472
2467
}
@@ -2752,8 +2747,6 @@ where
2752
2747
custom_arch. skip_and_return_value ( data, addr, val)
2753
2748
}
2754
2749
2755
- let name = name. into_bytes_with_nul ( ) ;
2756
-
2757
2750
let uninit_arch = ArchitectureBuilder {
2758
2751
arch : MaybeUninit :: zeroed ( ) ,
2759
2752
func : Some ( func) ,
@@ -2841,8 +2834,7 @@ where
2841
2834
} ;
2842
2835
2843
2836
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 _ ) ;
2846
2838
2847
2839
assert ! ( !res. is_null( ) ) ;
2848
2840
0 commit comments