From 082937118a8a250b866dce07f5b1921227e5c722 Mon Sep 17 00:00:00 2001 From: Thijs Raymakers Date: Wed, 28 Aug 2024 23:51:53 +0200 Subject: [PATCH] Don't skip over symbol at start of file in _populate_symbols 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 its 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}`. --- pwnlib/elf/elf.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pwnlib/elf/elf.py b/pwnlib/elf/elf.py index acb0a2d7a..5188003e9 100644 --- a/pwnlib/elf/elf.py +++ b/pwnlib/elf/elf.py @@ -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.