@@ -649,7 +649,7 @@ uint32_t Parser::nb_dynsym_gnu_hash(void) const {
649
649
const uint32_t nbuckets = header[0 ];
650
650
const uint32_t symndx = header[1 ];
651
651
const uint32_t maskwords = header[2 ];
652
- // const uint32_t shift2 = header[3];
652
+ const uint32_t shift2 = header[3 ];
653
653
654
654
if (maskwords & (maskwords - 1 )) {
655
655
LOG (WARNING) << " maskwords is not a power of 2" ;
@@ -692,21 +692,30 @@ uint32_t Parser::nb_dynsym_gnu_hash(void) const {
692
692
return 0 ;
693
693
}
694
694
695
- nb_symbols = std::max (nb_symbols, symndx) ;
695
+ nb_symbols = symndx;
696
696
697
- const uint32_t * hash_values = reinterpret_cast < const uint32_t *>(
698
- this -> stream_ -> read (current_offset, nb_symbols * sizeof ( uint32_t ))) ;
697
+ GnuHash gnuhash{symndx, shift2, bloom_filters, buckets};
698
+ gnuhash. c_ = sizeof (uint__) * 8 ;
699
699
700
700
701
- // "It is set to 1 when a symbol is the last symbol in a given hash chain"
702
- while (((*hash_values) & 1 ) == 0 ) {
703
- ++nb_symbols;
704
- ++hash_values;
705
- }
701
+ // Register the size of symbols store a the buckets
702
+ std::vector<size_t > nbsym_buckets (nbuckets, 0 );
706
703
707
- return ++nb_symbols;
704
+ for (size_t i = 0 ; i < nbuckets; ++i) {
705
+ uint32_t hash_value = 0 ;
706
+ size_t nsyms = 0 ;
707
+ do {
708
+ hash_value = this ->stream_ ->read_integer <uint32_t >(current_offset);
709
+ current_offset += sizeof (uint32_t );
708
710
711
+ nsyms++;
712
+ } while ((hash_value & 1 ) == 0 ); // "It is set to 1 when a symbol is the last symbol in a given hash bucket"
709
713
714
+ nbsym_buckets[i] = buckets[i] + nsyms;
715
+ }
716
+
717
+ nb_symbols = std::max<uint32_t >(nb_symbols, *std::max_element (std::begin (nbsym_buckets), std::end (nbsym_buckets)));
718
+ return nb_symbols;
710
719
}
711
720
712
721
template <typename ELF_T>
@@ -897,6 +906,7 @@ void Parser::parse_dynamic_symbols(uint64_t offset) {
897
906
VLOG (VDEBUG) << " [+] Parsing dynamics symbols" ;
898
907
899
908
uint32_t nb_symbols = this ->get_numberof_dynamic_symbols <ELF_T>(this ->count_mtd_ );
909
+ VLOG (VDEBUG) << " Number of symbols counted: " << nb_symbols;
900
910
901
911
const Elf_Off dynamic_symbols_offset = offset;
902
912
const Elf_Off string_offset = this ->get_dynamic_string_table ();
@@ -1494,6 +1504,7 @@ void Parser::parse_symbol_gnu_hash(uint64_t offset) {
1494
1504
1495
1505
VLOG (VDEBUG) << " [+] Parser symbol GNU hash" ;
1496
1506
GnuHash gnuhash;
1507
+ gnuhash.c_ = sizeof (uint__) * 8 ;
1497
1508
1498
1509
uint64_t current_offset = offset;
1499
1510
0 commit comments