cle


Namecle JSON
Version 9.2.168 PyPI version JSON
download
home_pageNone
SummaryCLE Loads Everything (at least, many binary formats!) and provides a pythonic interface to analyze what they are and what they would look like in memory.
upload_time2025-07-29 18:18:48
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseBSD-2-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # CLE
[![Latest Release](https://img.shields.io/pypi/v/cle.svg)](https://pypi.python.org/pypi/cle/)
[![Python Version](https://img.shields.io/pypi/pyversions/cle)](https://pypi.python.org/pypi/cle/)
[![PyPI Statistics](https://img.shields.io/pypi/dm/cle.svg)](https://pypistats.org/packages/cle)
[![License](https://img.shields.io/github/license/angr/cle.svg)](https://github.com/angr/cle/blob/master/LICENSE)

CLE loads binaries and their associated libraries, resolves imports and
provides an abstraction of process memory the same way as if it was loader by
the OS's loader.

## Project Links
Project repository: https://github.com/angr/cle

Documentation: https://api.angr.io/projects/cle/en/latest/

## Installation

```sh
pip install cle
```

## Usage example

```python
>>> import cle
>>> ld = cle.Loader("/bin/ls")
>>> hex(ld.main_object.entry)
'0x4048d0'
>>> ld.shared_objects
{'ld-linux-x86-64.so.2': <ELF Object ld-2.21.so, maps [0x5000000:0x522312f]>,
 'libacl.so.1': <ELF Object libacl.so.1.1.0, maps [0x2000000:0x220829f]>,
 'libattr.so.1': <ELF Object libattr.so.1.1.0, maps [0x4000000:0x4204177]>,
 'libc.so.6': <ELF Object libc-2.21.so, maps [0x3000000:0x33a1a0f]>,
 'libcap.so.2': <ELF Object libcap.so.2.24, maps [0x1000000:0x1203c37]>}
>>> ld.addr_belongs_to_object(0x5000000)
<ELF Object ld-2.21.so, maps [0x5000000:0x522312f]>
>>> libc_main_reloc = ld.main_object.imports['__libc_start_main']
>>> hex(libc_main_reloc.addr)       # Address of GOT entry for libc_start_main
'0x61c1c0'
>>> import pyvex
>>> some_text_data = ld.memory.load(ld.main_object.entry, 0x100)
>>> irsb = pyvex.lift(some_text_data, ld.main_object.entry, ld.main_object.arch)
>>> irsb.pp()
IRSB {
   t0:Ity_I32 t1:Ity_I32 t2:Ity_I32 t3:Ity_I64 t4:Ity_I64 t5:Ity_I64 t6:Ity_I32 t7:Ity_I64 t8:Ity_I32 t9:Ity_I64 t10:Ity_I64 t11:Ity_I64 t12:Ity_I64 t13:Ity_I64 t14:Ity_I64

   15 | ------ IMark(0x4048d0, 2, 0) ------
   16 | t5 = 32Uto64(0x00000000)
   17 | PUT(rbp) = t5
   18 | t7 = GET:I64(rbp)
   19 | t6 = 64to32(t7)
   20 | t2 = t6
   21 | t9 = GET:I64(rbp)
   22 | t8 = 64to32(t9)
   23 | t1 = t8
   24 | t0 = Xor32(t2,t1)
   25 | PUT(cc_op) = 0x0000000000000013
   26 | t10 = 32Uto64(t0)
   27 | PUT(cc_dep1) = t10
   28 | PUT(cc_dep2) = 0x0000000000000000
   29 | t11 = 32Uto64(t0)
   30 | PUT(rbp) = t11
   31 | PUT(rip) = 0x00000000004048d2
   32 | ------ IMark(0x4048d2, 3, 0) ------
   33 | t12 = GET:I64(rdx)
   34 | PUT(r9) = t12
   35 | PUT(rip) = 0x00000000004048d5
   36 | ------ IMark(0x4048d5, 1, 0) ------
   37 | t4 = GET:I64(rsp)
   38 | t3 = LDle:I64(t4)
   39 | t13 = Add64(t4,0x0000000000000008)
   40 | PUT(rsp) = t13
   41 | PUT(rsi) = t3
   42 | PUT(rip) = 0x00000000004048d6
   43 | t14 = GET:I64(rip)
   NEXT: PUT(rip) = t14; Ijk_Boring
}
```

## Valid options

For a full listing and description of the options that can be provided to the
loader and the methods it provides, please examine the docstrings in
`cle/loader.py`. If anything is unclear or poorly documented (there is much)
please complain through whatever channel you feel appropriate.

## Loading Backends

CLE's loader is implemented in the Loader class.
There are several backends that can be used to load a single file:

  - ELF, as its name says, loads ELF binaries. ELF files loaded this way are
    statically parsed using PyElfTools.

  - PE is a backend to load Microsoft's Portable Executable format,
    effectively Windows binaries. It uses the (optional) `pefile` module.

  - Mach-O is a backend to load, you guessed it, Mach-O binaries. Support is
    limited for this backend.

  - Blob is a backend to load unknown data. It requires that you specify
    the architecture it would be run on, in the form of a class from
    ArchInfo.

Which backend you use can be specified as an argument to Loader. If left
unspecified, the loader will pick a reasonable default.

## Finding shared libraries

- If the `auto_load_libs` option is set to False, the Loader will not
  automatically load libraries requested by loaded objects. Otherwise...
- The loader determines which shared objects are needed when loading
  binaries, and searches for them in the following order:
    - in the current working directory
    - in folders specified in the `ld_path` option
    - in the same folder as the main binary
    - in the system (in the corresponding library path for the architecture
      of the binary, e.g., /usr/arm-linux-gnueabi/lib for ARM, note that
      you need to install cross libraries for this, e.g.,
      libc6-powerpc-cross on Debian - needs emdebian repos)
    - in the system, but with mismatched version numbers from what is specified
      as a dependency, if the `ignore_import_version_numbers` option is True

- If no binary is found with the correct architecture, the loader raises an
  exception if `except_missing_libs` option is True. Otherwise it simply
  leaves the dependencies unresolved.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "cle",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/49/fb/fbad59d8dbc633595ad825ce9f0f8a49cadda94d948c3343442a52736db5/cle-9.2.168.tar.gz",
    "platform": null,
    "description": "# CLE\n[![Latest Release](https://img.shields.io/pypi/v/cle.svg)](https://pypi.python.org/pypi/cle/)\n[![Python Version](https://img.shields.io/pypi/pyversions/cle)](https://pypi.python.org/pypi/cle/)\n[![PyPI Statistics](https://img.shields.io/pypi/dm/cle.svg)](https://pypistats.org/packages/cle)\n[![License](https://img.shields.io/github/license/angr/cle.svg)](https://github.com/angr/cle/blob/master/LICENSE)\n\nCLE loads binaries and their associated libraries, resolves imports and\nprovides an abstraction of process memory the same way as if it was loader by\nthe OS's loader.\n\n## Project Links\nProject repository: https://github.com/angr/cle\n\nDocumentation: https://api.angr.io/projects/cle/en/latest/\n\n## Installation\n\n```sh\npip install cle\n```\n\n## Usage example\n\n```python\n>>> import cle\n>>> ld = cle.Loader(\"/bin/ls\")\n>>> hex(ld.main_object.entry)\n'0x4048d0'\n>>> ld.shared_objects\n{'ld-linux-x86-64.so.2': <ELF Object ld-2.21.so, maps [0x5000000:0x522312f]>,\n 'libacl.so.1': <ELF Object libacl.so.1.1.0, maps [0x2000000:0x220829f]>,\n 'libattr.so.1': <ELF Object libattr.so.1.1.0, maps [0x4000000:0x4204177]>,\n 'libc.so.6': <ELF Object libc-2.21.so, maps [0x3000000:0x33a1a0f]>,\n 'libcap.so.2': <ELF Object libcap.so.2.24, maps [0x1000000:0x1203c37]>}\n>>> ld.addr_belongs_to_object(0x5000000)\n<ELF Object ld-2.21.so, maps [0x5000000:0x522312f]>\n>>> libc_main_reloc = ld.main_object.imports['__libc_start_main']\n>>> hex(libc_main_reloc.addr)       # Address of GOT entry for libc_start_main\n'0x61c1c0'\n>>> import pyvex\n>>> some_text_data = ld.memory.load(ld.main_object.entry, 0x100)\n>>> irsb = pyvex.lift(some_text_data, ld.main_object.entry, ld.main_object.arch)\n>>> irsb.pp()\nIRSB {\n   t0:Ity_I32 t1:Ity_I32 t2:Ity_I32 t3:Ity_I64 t4:Ity_I64 t5:Ity_I64 t6:Ity_I32 t7:Ity_I64 t8:Ity_I32 t9:Ity_I64 t10:Ity_I64 t11:Ity_I64 t12:Ity_I64 t13:Ity_I64 t14:Ity_I64\n\n   15 | ------ IMark(0x4048d0, 2, 0) ------\n   16 | t5 = 32Uto64(0x00000000)\n   17 | PUT(rbp) = t5\n   18 | t7 = GET:I64(rbp)\n   19 | t6 = 64to32(t7)\n   20 | t2 = t6\n   21 | t9 = GET:I64(rbp)\n   22 | t8 = 64to32(t9)\n   23 | t1 = t8\n   24 | t0 = Xor32(t2,t1)\n   25 | PUT(cc_op) = 0x0000000000000013\n   26 | t10 = 32Uto64(t0)\n   27 | PUT(cc_dep1) = t10\n   28 | PUT(cc_dep2) = 0x0000000000000000\n   29 | t11 = 32Uto64(t0)\n   30 | PUT(rbp) = t11\n   31 | PUT(rip) = 0x00000000004048d2\n   32 | ------ IMark(0x4048d2, 3, 0) ------\n   33 | t12 = GET:I64(rdx)\n   34 | PUT(r9) = t12\n   35 | PUT(rip) = 0x00000000004048d5\n   36 | ------ IMark(0x4048d5, 1, 0) ------\n   37 | t4 = GET:I64(rsp)\n   38 | t3 = LDle:I64(t4)\n   39 | t13 = Add64(t4,0x0000000000000008)\n   40 | PUT(rsp) = t13\n   41 | PUT(rsi) = t3\n   42 | PUT(rip) = 0x00000000004048d6\n   43 | t14 = GET:I64(rip)\n   NEXT: PUT(rip) = t14; Ijk_Boring\n}\n```\n\n## Valid options\n\nFor a full listing and description of the options that can be provided to the\nloader and the methods it provides, please examine the docstrings in\n`cle/loader.py`. If anything is unclear or poorly documented (there is much)\nplease complain through whatever channel you feel appropriate.\n\n## Loading Backends\n\nCLE's loader is implemented in the Loader class.\nThere are several backends that can be used to load a single file:\n\n  - ELF, as its name says, loads ELF binaries. ELF files loaded this way are\n    statically parsed using PyElfTools.\n\n  - PE is a backend to load Microsoft's Portable Executable format,\n    effectively Windows binaries. It uses the (optional) `pefile` module.\n\n  - Mach-O is a backend to load, you guessed it, Mach-O binaries. Support is\n    limited for this backend.\n\n  - Blob is a backend to load unknown data. It requires that you specify\n    the architecture it would be run on, in the form of a class from\n    ArchInfo.\n\nWhich backend you use can be specified as an argument to Loader. If left\nunspecified, the loader will pick a reasonable default.\n\n## Finding shared libraries\n\n- If the `auto_load_libs` option is set to False, the Loader will not\n  automatically load libraries requested by loaded objects. Otherwise...\n- The loader determines which shared objects are needed when loading\n  binaries, and searches for them in the following order:\n    - in the current working directory\n    - in folders specified in the `ld_path` option\n    - in the same folder as the main binary\n    - in the system (in the corresponding library path for the architecture\n      of the binary, e.g., /usr/arm-linux-gnueabi/lib for ARM, note that\n      you need to install cross libraries for this, e.g.,\n      libc6-powerpc-cross on Debian - needs emdebian repos)\n    - in the system, but with mismatched version numbers from what is specified\n      as a dependency, if the `ignore_import_version_numbers` option is True\n\n- If no binary is found with the correct architecture, the loader raises an\n  exception if `except_missing_libs` option is True. Otherwise it simply\n  leaves the dependencies unresolved.\n",
    "bugtrack_url": null,
    "license": "BSD-2-Clause",
    "summary": "CLE Loads Everything (at least, many binary formats!) and provides a pythonic interface to analyze what they are and what they would look like in memory.",
    "version": "9.2.168",
    "project_urls": {
        "Homepage": "https://api.angr.io/projects/cle/en/latest/",
        "Repository": "https://github.com/angr/cle"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "7204ac0dc6900e83a70582e14e67bd4e05229326a47a0ce50f48703ecbdadad8",
                "md5": "45b1136a85d5ea3e479db9edb891bed8",
                "sha256": "93127399985e3f4b9bef6d2663eb3e52d4c453838d402b5a5bc0a9da5085fc3a"
            },
            "downloads": -1,
            "filename": "cle-9.2.168-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "45b1136a85d5ea3e479db9edb891bed8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 200800,
            "upload_time": "2025-07-29T18:18:34",
            "upload_time_iso_8601": "2025-07-29T18:18:34.089469Z",
            "url": "https://files.pythonhosted.org/packages/72/04/ac0dc6900e83a70582e14e67bd4e05229326a47a0ce50f48703ecbdadad8/cle-9.2.168-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "49fbfbad59d8dbc633595ad825ce9f0f8a49cadda94d948c3343442a52736db5",
                "md5": "97c8b891b9d600710ddb5d27468931ee",
                "sha256": "a230fa4ef12be8d602f8cd7be0fa563cea62720614f3b9392b870869f1da435d"
            },
            "downloads": -1,
            "filename": "cle-9.2.168.tar.gz",
            "has_sig": false,
            "md5_digest": "97c8b891b9d600710ddb5d27468931ee",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 196228,
            "upload_time": "2025-07-29T18:18:48",
            "upload_time_iso_8601": "2025-07-29T18:18:48.154038Z",
            "url": "https://files.pythonhosted.org/packages/49/fb/fbad59d8dbc633595ad825ce9f0f8a49cadda94d948c3343442a52736db5/cle-9.2.168.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-29 18:18:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "angr",
    "github_project": "cle",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "cle"
}
        
Elapsed time: 0.60560s