From d4c68c8e422d94c076dba32134a837a1fb339d05 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 28 Feb 2025 15:42:38 +0100 Subject: [PATCH] Output readability improved --- src/pelfy/__init__.py | 6 +++--- src/pelfy/fields_data.py | 25 +++++++++++++++++-------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/pelfy/__init__.py b/src/pelfy/__init__.py index cd8db68..d47f1ce 100644 --- a/src/pelfy/__init__.py +++ b/src/pelfy/__init__.py @@ -112,7 +112,7 @@ class elf_symbol(): f'name {self.name}\n' +\ f'stb {self.stb} ({self.stb_description})\n' +\ f'info {self.info} ({self.description})\n' +\ - '\n'.join(f'{k:18} {v:4}' for k, v in self.fields.items()) + '\n' + '\n'.join(f"{k:18} {v:4} {fdat.symbol_fields[k]}" for k, v in self.fields.items()) + '\n' class elf_section(): @@ -338,9 +338,9 @@ class symbol_list(elf_list[elf_symbol]): """A class for representing a list of ELF symbols """ def _compact_table(self) -> tuple[list[str], list[list[int | str]], list[str]]: - columns = ['index', 'name', 'info', 'size', 'stb', 'description'] + columns = ['index', 'name', 'info', 'size', 'stb', 'section', 'description'] data: list[list[str | int]] = [[item.index, item.name, item.info, item.fields['st_size'], - item.stb, item.description] for item in self] + item.stb, item.section.name if item.section else '', item.description] for item in self] return columns, data, ['index', 'size'] diff --git a/src/pelfy/fields_data.py b/src/pelfy/fields_data.py index afea548..45fee34 100644 --- a/src/pelfy/fields_data.py +++ b/src/pelfy/fields_data.py @@ -316,16 +316,25 @@ section_header_types_ex = {0x60000000: 'OS-specific', 0x70000000: 'Processor-specific', 0x80000000: 'Application-specific'} +symbol_fields = { + "st_name": "Index into the string table for the symbol's name", + "st_info": "Encodes the symbol's type and its binding attribute", + "st_other": "Defines symbol visibility within and outside the object file", + "st_shndx": "Specifies which section this symbol is associated with", + "st_value": "Holds the symbol's address or offset, depending on context", + "st_size": "Specifies the size of the symbol (e.g., function length or variable size)" +} + st_info_values = { - 0: ("STT_NOTYPE", "Symbol type is unspecified"), - 1: ("STT_OBJECT", "Symbol is a data object"), - 2: ("STT_FUNC", "Symbol is a code object"), - 3: ("STT_SECTION", "Symbol associated with a section"), - 4: ("STT_FILE", "Symbol's name is file name"), - 5: ("STT_COMMON", "Symbol is a common data object"), - 6: ("STT_TLS", "Symbol is thread-local data object"), + 0: ("STT_NOTYPE", "Type is unspecified"), + 1: ("STT_OBJECT", "Data object"), + 2: ("STT_FUNC", "Code object"), + 3: ("STT_SECTION", "Section associated"), + 4: ("STT_FILE", "File name"), + 5: ("STT_COMMON", "Common data object"), + 6: ("STT_TLS", "Thread-local data object"), 7: ("STT_NUM", "Number of defined types"), - 10: ("STT_GNU_IFUNC", "Symbol is indirect code object") + 10: ("STT_GNU_IFUNC", "Indirect code object") } stb_values = {