simpleelf


Namesimpleelf JSON
Version 1.0.0 PyPI version JSON
download
home_page
SummarySimple ELF parser and builder
upload_time2023-09-19 09:56:21
maintainer
docs_urlNone
author
requires_python>=3.8
license
keywords elf reverse-engineering research
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Python package](https://github.com/doronz88/simpleelf/workflows/Python%20package/badge.svg)

# 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`:

```bash
python3 -m pip install simpleelf
```

Or clone yourself and build:

```bash
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:

```python
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:

```python
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()
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "simpleelf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": "doronz88 <doron88@gmail.com>",
    "keywords": "elf,reverse-engineering,research",
    "author": "",
    "author_email": "doronz88 <doron88@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/2d/30/a017900c02687a0787301013dcdce80210180a5255d713ba0f24340f137f/simpleelf-1.0.0.tar.gz",
    "platform": null,
    "description": "![Python package](https://github.com/doronz88/simpleelf/workflows/Python%20package/badge.svg)\n\n# Introduction\nELF file is not only an executable, but a very convenient way to describe \na program's layout in memory. The original intention of this project is to \nallow an individual to create an ELF file which describes the memory mapping\nused for an embedded program. Especially useful for using together with other \nanalysis tools, such as:\nIDA/Ghidra/etc... They can have all its desired information without the need to\nopen just an ordinary `.bin` file and running several IDAPython scripts\n(I'm sick of `Load additional binary file...` option).\n\nPull Requests are of course more than welcome :smirk:.\n\n# Installation\n\nUse `pip`:\n\n```bash\npython3 -m pip install simpleelf\n```\n\nOr clone yourself and build:\n\n```bash\ngit clone git@github.com:doronz88/simpleelf.git\ncd simpleelf\npython -m pip install -e . -U\n```\n\n# Running\n\nNow you can just import simpleelf and start playing with it.\n\n## Parsing\n\nParsing is easy using `ElfStruct`.\nTry it out:\n\n```python\nfrom simpleelf.elf_structs import ElfStructs\n\nElfStructs('<').Elf32.parse(elf32_buffer) # outputs a constucts' container\nElfStructs('<').Elf64.parse(elf64_buffer) # outputs a constucts' container\n```\n\n## Building from scratch\n\nBuilding is easy using `ElfBuilder`.\nTry it out:\n\n```python\nfrom simpleelf.elf_builder import ElfBuilder\nfrom simpleelf import elf_consts\n\n# can also be used with ELFCLASS64 to create 64bit layouts\ne = ElfBuilder(elf_consts.ELFCLASS32)\ne.set_endianity('<')\ne.set_machine(elf_consts.EM_ARM)\n\ncode = b'CODECODE'\n\n# add a segment\ntext_address = 0x1234\ntext_buffer = b'cybercyberbitimbitim' + code\ne.add_segment(text_address, text_buffer, \n    elf_consts.PF_R | elf_consts.PF_W | elf_consts.PF_X)\n\n# add a second segment\ne.add_segment(0x88771122, b'data in 0x88771122', \n    elf_consts.PF_R | elf_consts.PF_W | elf_consts.PF_X)\n\n# add a code section inside the first segment\ncode_address = text_address + text_buffer.find(code)  # point at CODECODE\ncode_size = len(code)\ne.add_code_section(code_address, code_size, name='.text')\n\n# set entry point\ne.set_entry(code_address)\n\n# add .bss section. not requiring a loaded segment from\n# file\nbss_address = 0x5678\nbss_size = 0x200\ne.add_empty_data_section(bss_address, bss_size, name='.bss')\n\n# get raw elf\ne.build()\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple ELF parser and builder",
    "version": "1.0.0",
    "project_urls": {
        "Bug Reports": "https://github.com/doronz88/simpleelf/issues",
        "Homepage": "https://github.com/doronz88/simpleelf"
    },
    "split_keywords": [
        "elf",
        "reverse-engineering",
        "research"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e221ebe095cb138af8919059eaee3e05a76fd5c79a491eeadc5fdb5f6193da17",
                "md5": "bff61fc9a4d214f6bde9d8794588a34d",
                "sha256": "0669a2180958982c13f6addd17dec9d88bc444bca1f76a87abb6dafeda458616"
            },
            "downloads": -1,
            "filename": "simpleelf-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bff61fc9a4d214f6bde9d8794588a34d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 12494,
            "upload_time": "2023-09-19T09:56:20",
            "upload_time_iso_8601": "2023-09-19T09:56:20.542921Z",
            "url": "https://files.pythonhosted.org/packages/e2/21/ebe095cb138af8919059eaee3e05a76fd5c79a491eeadc5fdb5f6193da17/simpleelf-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d30a017900c02687a0787301013dcdce80210180a5255d713ba0f24340f137f",
                "md5": "137d5788b96587d229b3c94bba982f21",
                "sha256": "4e5143617c59908e27f3b32b50d5595d3c20460ed1f06b450205b7f680e07089"
            },
            "downloads": -1,
            "filename": "simpleelf-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "137d5788b96587d229b3c94bba982f21",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 14075,
            "upload_time": "2023-09-19T09:56:21",
            "upload_time_iso_8601": "2023-09-19T09:56:21.595563Z",
            "url": "https://files.pythonhosted.org/packages/2d/30/a017900c02687a0787301013dcdce80210180a5255d713ba0f24340f137f/simpleelf-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-19 09:56:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "doronz88",
    "github_project": "simpleelf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "simpleelf"
}
        
Elapsed time: 0.13090s