Skip to content

Commit

Permalink
Don't skip over symbol at start of file in _populate_symbols
Browse files Browse the repository at this point in the history
Lets say we have an ELF with the following symbols

```
Symbol table '.symtab' contains 5 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND
     1: 0000000000000035     0 NOTYPE  LOCAL  DEFAULT    2 aaaa
     2: 0000000000000022     0 NOTYPE  LOCAL  DEFAULT    2 bbbb
     3: 0000000000000000     0 NOTYPE  GLOBAL DEFAULT    2 cccc
     4: 0000000000000054     0 NOTYPE  GLOBAL DEFAULT    2 dddd
```

Then pwnlib's ELF(binary).symbols will be `{'aaaa': 53, 'bbbb': 34, 'dddd': 84}`.
This is missing the symbol `cccc`, because it's value is 0.

This change checks the name instead of the value, because the value can
be 0 if the symbol points to the beginning.

The new and correct value of pwnlib's ELF(binary).symbols will be
`{'aaaa': 53, 'cccc': 0, 'bbbb': 34, 'dddd': 84}`.
  • Loading branch information
ThijsRay committed Aug 28, 2024
1 parent dbb034a commit 9e00ad7
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pwnlib/elf/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -908,10 +908,9 @@ def _populate_symbols(self):
continue

for symbol in _iter_symbols(section):
value = symbol.entry.st_value
if not value:
if not symbol.name:
continue
self.symbols[symbol.name] = value
self.symbols[symbol.name] = symbol.entry.st_value

def _populate_synthetic_symbols(self):
"""Adds symbols from the GOT and PLT to the symbols dictionary.
Expand Down

0 comments on commit 9e00ad7

Please sign in to comment.