@@ -37,71 +37,15 @@ pub fn get_image_base(data: &[u8]) -> Option<usize> {
3737
3838impl < ' a > Object < ' a > {
3939 fn parse ( data : & ' a [ u8 ] ) -> Option < Object < ' a > > {
40- let dos_header = ImageDosHeader :: parse ( data) . ok ( ) ?;
41- let mut offset = dos_header. nt_headers_offset ( ) . into ( ) ;
42- let ( nt_headers, _) = Pe :: parse ( data, & mut offset) . ok ( ) ?;
43- let sections = nt_headers. sections ( data, offset) . ok ( ) ?;
44- let symtab = nt_headers. symbols ( data) . ok ( ) ?;
45- let strings = symtab. strings ( ) ;
46- let image_base = usize:: try_from ( nt_headers. optional_header ( ) . image_base ( ) ) . ok ( ) ?;
47-
48- // Collect all the symbols into a local vector which is sorted
49- // by address and contains enough data to learn about the symbol
50- // name. Note that we only look at function symbols and also
51- // note that the sections are 1-indexed because the zero section
52- // is special (apparently).
53- let mut symbols = Vec :: new ( ) ;
54- let mut i = 0 ;
55- let len = symtab. len ( ) ;
56- while i < len {
57- let sym = symtab. symbol ( i) . ok ( ) ?;
58- i += 1 + sym. number_of_aux_symbols as usize ;
59- let section_number = sym. section_number . get ( LE ) ;
60- if sym. derived_type ( ) != object:: pe:: IMAGE_SYM_DTYPE_FUNCTION || section_number == 0 {
61- continue ;
62- }
63- let addr = usize:: try_from ( sym. value . get ( LE ) ) . ok ( ) ?;
64- let section = sections
65- . section ( usize:: try_from ( section_number) . ok ( ) ?)
66- . ok ( ) ?;
67- let va = usize:: try_from ( section. virtual_address . get ( LE ) ) . ok ( ) ?;
68- symbols. push ( ( addr + va + image_base, sym) ) ;
69- }
70- symbols. sort_unstable_by_key ( |x| x. 0 ) ;
71- Some ( Object {
72- data,
73- sections,
74- strings,
75- symbols,
76- } )
40+ None
7741 }
7842
7943 pub fn section ( & self , _: & Stash , name : & str ) -> Option < & ' a [ u8 ] > {
80- Some (
81- self . sections
82- . section_by_name ( self . strings , name. as_bytes ( ) ) ?
83- . 1
84- . pe_data ( self . data )
85- . ok ( ) ?,
86- )
44+ None
8745 }
8846
8947 pub fn search_symtab < ' b > ( & ' b self , addr : u64 ) -> Option < & ' b [ u8 ] > {
90- // Note that unlike other formats COFF doesn't embed the size of
91- // each symbol. As a last ditch effort search for the *closest*
92- // symbol to a particular address and return that one. This gets
93- // really wonky once symbols start getting removed because the
94- // symbols returned here can be totally incorrect, but we have
95- // no idea of knowing how to detect that.
96- let addr = usize:: try_from ( addr) . ok ( ) ?;
97- let i = match self . symbols . binary_search_by_key ( & addr, |p| p. 0 ) {
98- Ok ( i) => i,
99- // typically `addr` isn't in the array, but `i` is where
100- // we'd insert it, so the previous position must be the
101- // greatest less than `addr`
102- Err ( i) => i. checked_sub ( 1 ) ?,
103- } ;
104- self . symbols [ i] . 1 . name ( self . strings ) . ok ( )
48+ None
10549 }
10650
10751 pub ( super ) fn search_object_map ( & self , _addr : u64 ) -> Option < ( & Context < ' _ > , u64 ) > {
0 commit comments