Skip to main content

Python package

Introduction

ELF file is not only an executable, but a very convenient way to describe a program's layout in memory. The original intention of this project is to allow an individual to create an ELF file which describes the memory mapping used for an embedded program. Especially useful for using together with other analysis tools, such as: IDA/Ghidra/etc... They can have all its desired information without the need to open just an ordinary .bin file and running several IDAPython scripts (I'm sick of Load additional binary file... option).

Pull Requests are of course more than welcome :smirk:.

Installation

Use pip:

python3 -m pip install simpleelf

Or clone yourself and build:

git clone git@github.com:doronz88/simpleelf.git
cd simpleelf
python -m pip install -e . -U

Running

Now you can just import simpleelf and start playing with it.

Parsing

Parsing is easy using ElfStruct. Try it out:

from simpleelf.elf_structs import ElfStructs

ElfStructs('<').Elf32.parse(elf32_buffer) # outputs a constucts' container
ElfStructs('<').Elf64.parse(elf64_buffer) # outputs a constucts' container

Building from scratch

Building is easy using ElfBuilder. Try it out:

from simpleelf.elf_builder import ElfBuilder
from simpleelf import elf_consts

# can also be used with ELFCLASS64 to create 64bit layouts
e = ElfBuilder(elf_consts.ELFCLASS32)
e.set_endianity('<')
e.set_machine(elf_consts.EM_ARM)

code = b'CODECODE'

# add a segment
text_address = 0x1234
text_buffer = b'cybercyberbitimbitim' + code
e.add_segment(text_address, text_buffer, 
    elf_consts.PF_R | elf_consts.PF_W | elf_consts.PF_X)

# add a second segment
e.add_segment(0x88771122, b'data in 0x88771122', 
    elf_consts.PF_R | elf_consts.PF_W | elf_consts.PF_X)

# add a code section inside the first segment
code_address = text_address + text_buffer.find(code)  # point at CODECODE
code_size = len(code)
e.add_code_section(code_address, code_size, name='.text')

# set entry point
e.set_entry(code_address)

# add .bss section. not requiring a loaded segment from
# file
bss_address = 0x5678
bss_size = 0x200
e.add_empty_data_section(bss_address, bss_size, name='.bss')

# get raw elf
e.build()

Metadata

Release files for simpleelf 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for simpleelf 1.0.0
File Size Uploaded
simpleelf-1.0.0.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for simpleelf 1.0.0
File Interpreter ABI Platform
simpleelf-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 26.6 kB

Release files / simpleelf-1.0.0.tar.gz

Download URL simpleelf-1.0.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
4e5143617c59908e27f3b32b50d5595d3c20460ed1f06b450205b7f680e07089
BLAKE2b-256 checksum
How to use checksums
2d30a017900c02687a0787301013dcdce80210180a5255d713ba0f24340f137f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / simpleelf-1.0.0-py3-none-any.whl

Download URL simpleelf-1.0.0-py3-none-any.whl
Size 12.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0669a2180958982c13f6addd17dec9d88bc444bca1f76a87abb6dafeda458616
BLAKE2b-256 checksum
How to use checksums
e221ebe095cb138af8919059eaee3e05a76fd5c79a491eeadc5fdb5f6193da17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.12

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.4

2 release files

0.1.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page