read data for SHT_NOBITS sections fixed

This commit is contained in:
Nicolas 2025-02-28 15:26:37 +01:00
parent 675146e744
commit 553355cc12
1 changed files with 9 additions and 3 deletions

View File

@ -73,6 +73,9 @@ class elf_symbol():
Symbol data Symbol data
""" """
assert self.section, 'This symbol is not associated to a data section' assert self.section, 'This symbol is not associated to a data section'
if self.section.type == 'SHT_NOBITS':
return b'\x00' * self['sh_size']
else:
offset = self.section['sh_offset'] + self['st_value'] offset = self.section['sh_offset'] + self['st_value']
return self.file.read_bytes(offset, self['st_size']) return self.file.read_bytes(offset, self['st_size'])
@ -160,6 +163,9 @@ class elf_section():
Returns: Returns:
Data of the section Data of the section
""" """
if self.type == 'SHT_NOBITS':
return b'\x00' * self['sh_size']
else:
return self.file.read_bytes(self['sh_offset'], self['sh_size']) return self.file.read_bytes(self['sh_offset'], self['sh_size'])
def get_symbols(self) -> 'symbol_list': def get_symbols(self) -> 'symbol_list':