Skip to content

ELF API - #282

Open
Frank01001 wants to merge 66 commits into
mainfrom
sections
Open

ELF API#282
Frank01001 wants to merge 66 commits into
mainfrom
sections

Conversation

@Frank01001

@Frank01001 Frank01001 commented Sep 26, 2025

Copy link
Copy Markdown
Member

This draft PR introduces an API to inspect ELF files associated with the traced process — both the main binary and its libraries.
Libraries are parsed when loaded by the OS interpreter at process start, as well as when dynamically loaded at runtime via dlopen.

The new ELF inspection API provides access to detailed information such as:

  • Build ID
  • Sections and dynamic sections
  • Symbols
  • Program headers
  • GNU Properties
  • Runtime security mitigations (work in progress)

Current Status

✅ Python objects for relevant ELF structures
✅ Nanobind implementation for parsing ELF objects
✅ Parsing of libraries
✅ Parsing of security mitigations
✅ Reorganization into a single nanobind module (excluding symbols, which are to be kept separate)
✅ Documentation
✅ Test suite

Notes

This PR is still in draft form — many features and improvements are ongoing.

This pr addresses #188 and #287.

@Frank01001 Frank01001 self-assigned this Sep 26, 2025
@Frank01001 Frank01001 added the enhancement New feature or request label Sep 26, 2025
@Frank01001

Copy link
Copy Markdown
Member Author

I don't know why my PRs are always enormous, but I think I finally finished. Mitigation parsing of ARM took a long time. This PR is finally ready for review.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR introduces a comprehensive ELF API for inspecting traced process binaries and their libraries. The implementation provides access to build IDs, sections, dynamic sections, symbols, program headers, GNU properties, and runtime security mitigations.

Key changes:

  • New ELF inspection API with Python objects for ELF structures
  • Nanobind implementation for parsing ELF objects
  • Support for parsing libraries (both at load and dlopen time)
  • Runtime security mitigations analysis
  • Comprehensive test suite across amd64, i386, and aarch64 architectures

Reviewed Changes

Copilot reviewed 34 out of 66 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
test/utils/binary_utils.py Added RESOLVE_EXE_CROSS utility for cross-platform binary resolution
test/srcs/sections_test.c Comprehensive C test file exercising various ELF sections and features
test/srcs/mitigations.c Test binary for security mitigation detection across platforms
test/srcs/dynamic_lib_load.c Test case for dynamic library loading via dlopen
test/scripts/elf_api_test.py Extensive test suite validating ELF API functionality
test/scripts/init.py Added ElfApiTest to test exports
test/run_suite.py Integrated ElfApiTest into test suite
test/binaries/* Pre-compiled test binaries for multiple platforms
pyproject.toml Moved 'rich' from optional to core dependencies
mkdocs.yml Reorganized QoL documentation with new ELF API section
libdebug/utils/pprint_primitives.py Added pprint_mitigations function for pretty printing security mitigations
libdebug/native/utils/binary_utils.{h,cpp} Binary utility functions for ELF parsing (byte swapping, file I/O)
Comments suppressed due to low confidence (1)

test/srcs/mitigations.c:1

  • The build command on line 22 outputs to '../binaries/amd64/mitigationsv1' but is documented as building for AMD64 with 32-bit flag '-m32', which is contradictory. The correct output path should likely be '../binaries/i386/mitigationsv1' or the '-m32' flag should be removed.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/scripts/__init__.py Outdated
Comment thread test/scripts/elf_api_test.py Outdated
Comment thread test/srcs/mitigations.c Outdated
Comment thread libdebug/utils/pprint_primitives.py Outdated
Comment thread libdebug/native/utils/binary_utils.h Outdated
Comment thread test/scripts/__init__.py Outdated
@Frank01001

Frank01001 commented Nov 20, 2025

Copy link
Copy Markdown
Member Author

One test that I should actually add is for the dynamic parsing of libraries when the binary calls dlopen.

EDIT: done

@MrIndeciso MrIndeciso left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few small comments for consistency, everything else looks good

Comment thread libdebug/data/elf/dynamic_section.py Outdated
Comment thread libdebug/data/elf/elf.py
Comment thread libdebug/data/elf/elf.py Outdated
Comment thread libdebug/data/elf/gnu_property.py Outdated
Comment thread libdebug/data/elf/linux_runtime_mitigations.py Outdated
Comment thread libdebug/data/elf/program_header.py Outdated
Comment thread libdebug/data/elf/section.py
MrIndeciso
MrIndeciso previously approved these changes Jan 22, 2026
MrIndeciso
MrIndeciso previously approved these changes Apr 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux Runtime Mitigation parsing Section Accessors and file API

4 participants