pelfy.elf_file#
- class pelfy.elf_file(data)#
Bases:
objectA class for representing data of an ELF file in a structured form
- byteorder#
Byte order of the architecture ‘little’ or ‘big’ (based on e_ident[EI_DATA])
- bit_width#
Bit with of the architecture: 32 or 64 (based on e_ident[EI_CLASS])
- architecture#
Name of the architecture (based on e_machine)
- fields#
All ELF header fields as dict
- sections#
A list of all ELF sections
- symbols#
A list of all ELF symbols
- functions#
A list of all function symbols (STT_FUNC)
- objects#
A list of all variable/object symbols (STT_OBJECT)
- code_relocations#
A list of all code relocations (.rela.text and .rel.text)
- symbol_table_section#
The symbol table section (first section with the type SHT_SYMTAB)
- string_table_section#
The string table section (first section with the name .strtab)
- get_relocations(reloc_section=None)#
List relocations.
- Parameters:
reloc_section (
elf_section|str|list[str] |None) – Specifies the relocation section from which the relocations should be listed. It can be provided as elf_section object or by its name. If not provided (reloc_section=None) relocations from all relocation sections are returned.- Return type:
- Returns:
List of relocations
- list_symbols(section_index=None)#
List ELF symbols.
- Parameters:
section_index (
int|None) – If provided, only symbols from the specified section are returned.- Return type:
Generator[elf_symbol,None,None]- Returns:
List of ELF symbols
- read_bytes(offset, num_bytes)#
Read bytes from ELF file.
- Parameters:
offset (
int) – Specify first byte relative to the start of the ELF file.num_bytes (
int) – Specify the number of bytes to read.
- Return type:
bytes- Returns:
Binary data as bytes
- read_int(offset, num_bytes, signed=False)#
Read an integer from the ELF file. Byte order is selected according to the architecture (e_ident[EI_DATA]).
- Parameters:
offset (
int) – Specify first byte of the integer relative to the start of the ELF file.num_bytes (
int) – Specify the size of the integer in bytes.signed (
bool) – Select if the integer is a signed integer.
- Return type:
int- Returns:
Integer value
- read_string(offset, encoding='utf-8')#
Read a zero-terminated text string from the ELF file.
- Parameters:
offset (
int) – Specify first byte of the string relative to the start of the ELF file.encoding (
str) – Encoding used for text decoding.
- Return type:
str- Returns:
Text string