elf ¤
This file declares types and methods useful for enumerating all of the address spaces and permissions of an ELF file in memory.
This is necessary for when access to /proc is restricted, or when working on a BSD system which simply does not have /proc.
Classes:
-
ELFInfo–ELF metadata and structures.
Functions:
-
update– -
read– -
get_elf_info–Parse and return ELFInfo.
-
get_elf_info_rebased–Parse and return ELFInfo with all virtual addresses rebased to vaddr
-
get_containing_segments– -
get_containing_sections– -
get_vmlinux_unrand_base– -
section_by_name–Return the content of a section from an ELF file, as a (start address, size, content) tuple.
-
relocations_by_section_name–Return the relocation entries of a section from an ELF file as a (possibly empty)
-
exe–Return a loaded ELF header object pointing to the Ehdr of the
-
entry–Return the address of the entry point for the main executable.
-
load– -
reset_ehdr_type_loaded– -
get_ehdr–Returns an ehdr object for the ELF pointer points into.
-
get_phdrs–Returns a tuple containing (phnum, phentsize, gdb.Value),
-
iter_phdrs– -
map–Given a pointer into an ELF module, return a list of all loaded
-
map_inner– -
compile_with_flags–Compile a C program.
Attributes:
-
module– -
Ehdr(TypeAlias) – -
Phdr(TypeAlias) – -
T– -
ehdr_type_loaded– -
gcc_compiler_path–
gcc_compiler_path module-attribute ¤
gcc_compiler_path = add_param(
"gcc-compiler-path",
"",
"path to the gcc/g++ toolchain for generating imported symbols",
param_class=PARAM_OPTIONAL_FILENAME,
)
ELFInfo ¤
Bases: NamedTuple
ELF metadata and structures.
Attributes:
get_elf_info ¤
get_elf_info(filepath: str) -> ELFInfo
Parse and return ELFInfo.
Adds various calculated properties to the ELF header, segments and sections. Such added properties are those with prefix 'x_' in the returned dicts.
get_elf_info_rebased ¤
get_elf_info_rebased(filepath: str, vaddr: int) -> ELFInfo
Parse and return ELFInfo with all virtual addresses rebased to vaddr
section_by_name ¤
section_by_name(
filepath: str, section_name: str, try_local_path: bool = False
) -> tuple[int, int, bytes] | None
Return the content of a section from an ELF file, as a (start address, size, content) tuple.
relocations_by_section_name ¤
relocations_by_section_name(
filepath: str, section_name: str, try_local_path: bool = False
) -> tuple[Relocation, ...]
Return the relocation entries of a section from an ELF file as a (possibly empty) tuple of Relocation objects.
exe ¤
exe() -> Ehdr | None
Return a loaded ELF header object pointing to the Ehdr of the main executable.
get_ehdr ¤
get_ehdr(pointer: int) -> tuple[int | None, Ehdr | None]
Returns an ehdr object for the ELF pointer points into.
We expect the pointer to be an address from the binary.
get_phdrs ¤
Returns a tuple containing (phnum, phentsize, gdb.Value), where the gdb.Value object is an ELF Program Header with the architecture-appropriate structure type.
map ¤
map(pointer: int, objfile: str = '') -> tuple[Page, ...]
Given a pointer into an ELF module, return a list of all loaded sections in the ELF.
Returns:
-
tuple[Page, ...]–A sorted list of pwndbg.lib.memory.Page objects
Example:
>>> pwndbg.aglib.elf.load(pwndbg.aglib.regs.pc)
[Page('400000-4ef000 r-xp 0'),
Page('6ef000-6f0000 r--p ef000'),
Page('6f0000-6ff000 rw-p f0000')]
>>> pwndbg.aglib.elf.load(0x7ffff77a2000)
[Page('7ffff75e7000-7ffff77a2000 r-xp 0x1bb000 0'),
Page('7ffff77a2000-7ffff79a2000 ---p 0x200000 1bb000'),
Page('7ffff79a2000-7ffff79a6000 r--p 0x4000 1bb000'),
Page('7ffff79a6000-7ffff79ad000 rw-p 0x7000 1bf000')]
compile_with_flags ¤
compile_with_flags(compiler_flags: list[str]) -> Status
Compile a C program.
If the gcc_compiler_path argument is set, gcc will be used, otherwise zig (the python package) will be used.
Parameters:
-
compiler_flags(list[str]) –The flags to pass to the compiler, including the input and output files.
Returns:
-
Status–A status object carrying an error message if compilation failed.