Skip to main content

Pure Python ELF file parser

Project description

woodelf

Pure-Python ELF file parser and editor. Reads, mutates, and writes 32/64-bit ELF binaries with transactional edits — every change is staged on an Editor, then committed in one atomic write.

Requires hexdump, sh. Python ≥ 3.9.

Install

pip install -e .

Quick start

import woodelf

elf = woodelf.parse("/path/to/binary")

# Inspect
print(elf.header)
for sh in elf.section_headers:
    print(sh.name, hex(sh.addr), sh.size)

# Edit symbols transactionally
with woodelf.transaction(elf) as tx:
    sym = elf.symbols.find("main")
    sym.value = 0x401234

elf.save("/path/to/output")

API

from woodelf import parse, Elf, transaction, Transaction

parse(path, toolchain_path=None, prefix='') -> Elf | None

Open and parse an ELF file. toolchain_path / prefix let woodelf shell out to a cross-toolchain (readelf, objdump, …) when needed.

Elf

Top-level handle to a parsed ELF. Exposes the structural elements as attributes you can iterate and edit:

Attribute Type
header ElfHeader
e_ident E_Ident
section_headers SectionHeaderTable[SectionHeader]
program_headers iterable of ProgramHeader
symbols SymbolTable[Symbol]
dynamic_entries iterable of DynamicEntry
versions VersionTable (Verdef/Verneed/…)

Class methods:

  • Elf.from_path(path, toolchain_path=None, prefix='') — same as parse.
  • Elf.save(out_path) — serialise the (possibly edited) ELF.

Editors

Each Editor stages mutations against a portion of the ELF. The element classes wrap editors so you can use attribute assignment directly; reach for the raw editors only when you need explicit control.

Editor Edits
ElfHeaderEditor Elf.header fields
SectionHeaderEditor Section header table
ProgramHeaderEditor Program header table
SymbolEditor .symtab / .dynsym entries
StrTabEditor .strtab / .dynstr strings
DynamicEntryEditor .dynamic entries
SymbolVersionEditor .gnu.version, .gnu.version_d/r

Transaction / transaction(elf)

Context manager that batches edits across multiple editors. Changes are applied on __exit__ — exit with an exception and nothing is written. Use it when an edit touches several tables (e.g. adding a symbol that needs a new name in .dynstr and a new version mapping).

Elements

Concrete types exposed by the package (see woodelf.elements):

  • Header: ElfHeader, E_Ident
  • Sections / segments: SectionHeader, SectionHeaderTable, ProgramHeader
  • Symbols: Symbol, SymbolTable
  • Dynamic linker: DynamicEntry
  • Symbol versioning: Verdef, Verdaux, Verneed, Vernaux, Version, VerdefTable, VerneedTable, VerauxTable, VersionTable
  • Hashing: GNU hash via woodelf.gnu_hash(name)

Errors

MalformedElfError — raised when the file fails structural validation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

woodelf-0.1.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

woodelf-0.1.1-py3-none-any.whl (39.2 kB view details)

Uploaded Python 3

File details

Details for the file woodelf-0.1.1.tar.gz.

File metadata

  • Download URL: woodelf-0.1.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for woodelf-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e997e24d81e8e84d2583318f614b2bcfc1414c348cf16fcd67d0671c3351fa89
MD5 24a4b3be7e850dfad4a4979a95971238
BLAKE2b-256 c6c96fdab85e14bdab0259280b469bd1ea1515875a36ec9a5f95178b47e75066

See more details on using hashes here.

File details

Details for the file woodelf-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: woodelf-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 39.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for woodelf-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5fb93fabb4478d98c33e93ab30ee1b56d140b293f53195c6578dea0529ef0c27
MD5 8b42f62164ebf9660e78b3be559a59b2
BLAKE2b-256 bba3fa3e6903f378747dd0e17b7c5af68a3efdb9ee6ced121eac4c45af6228ff

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page