11//! Support for parsing MachO files
22
3- use crate :: { Process , string :: ArrayCString } ;
3+ use crate :: Process ;
44
55use core:: mem;
66
@@ -57,9 +57,10 @@ pub fn is_64_bit(process: &Process) -> Option<bool> {
5757}
5858
5959/// Finds the offset of a function in the bytes of a MachO file.
60- pub fn get_function_offset < const N : usize > ( macho_bytes : & [ u8 ] , function_name : & str ) -> Option < u32 > {
60+ pub fn get_function_offset ( macho_bytes : & [ u8 ] , function_name : & [ u8 ] ) -> Option < u32 > {
6161 let macho_offsets = MachOFormatOffsets :: new ( ) ;
6262 let number_of_commands: u32 = slice_read ( macho_bytes, macho_offsets. number_of_commands ) . ok ( ) ?;
63+ let function_name_len = function_name. len ( ) ;
6364
6465 let mut offset_to_next_command: usize = macho_offsets. load_commands as usize ;
6566 for _i in 0 ..number_of_commands {
@@ -72,9 +73,10 @@ pub fn get_function_offset<const N: usize>(macho_bytes: &[u8], function_name: &s
7273
7374 for j in 0 ..( number_of_symbols as usize ) {
7475 let symbol_name_offset: u32 = slice_read ( macho_bytes, symbol_table_offset as usize + ( j * macho_offsets. size_of_nlist_item ) ) . ok ( ) ?;
75- let symbol_name: ArrayCString < N > = slice_read ( macho_bytes, ( string_table_offset + symbol_name_offset) as usize ) . ok ( ) ?;
76+ let string_offset = string_table_offset as usize + symbol_name_offset as usize ;
77+ let symbol_name: & [ u8 ] = & macho_bytes[ string_offset..( string_offset + function_name_len + 1 ) ] ;
7678
77- if symbol_name. matches ( function_name) {
79+ if symbol_name[ function_name_len ] == 0 && symbol_name . starts_with ( function_name) {
7880 return Some ( slice_read ( macho_bytes, symbol_table_offset as usize + ( j * macho_offsets. size_of_nlist_item ) + macho_offsets. nlist_value ) . ok ( ) ?) ;
7981 }
8082 }
0 commit comments