Skip to main content

pyr2

Yet another radare2 python bindings.

Compared to radare2-bindings and radare2-r2pipe, this binding:

  • Doesn't need any extra installation of radare2. Just pip install and you are ready to go.
  • Gives you the full control of the core radare2 API and helps build your own tools.

Install

pip3 install --upgrade pyr2

No need to install radare2 since all dynamic libraries are bundled with the Python wheels.

Example

Implement a basic command line r2 by pyr2.

import r2
import ctypes
import argparse

class R2:

    def __init__(self, bin):
        self._r2c = r2.r_core.r_core_new()
        fh = r2.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(b"/bin/ls"), 0b101, 0)
        r2.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(b"/bin/ls"), (1<<64) - 1)

    def cmd(self, cmd):
        r = r2.r_core.r_core_cmd_str(self._r2c, ctypes.create_string_buffer(cmd.encode("utf-8")))
        return ctypes.string_at(r).decode('utf-8')

    def __del__(self):
        r2.r_core.r_core_free(self._r2c)

if __name__ == "__main__":
    ap = argparse.ArgumentParser("Implement a basic command line r2 by pyr2")
    ap.add_argument("binary", help="The binary to analyse.")
    args = ap.parse_args()

    r2pipe = R2(args.binary)

    while True:
        print("> ", end="")
        cmd = input()
        if cmd.strip() == "q":
            break
        print(r2pipe.cmd(cmd))

Note that all radare2 APIs are exported as bare ctypes function prototype. Be catious with c-style strings.

Build Instructions

Clone the repository and submodules.

git clone https://github.com/wtdcode/pyr2
cd pyr2
git submodule update --init --recursive

Since radare2 chooses meson as their alternative building system and it's cross-platform, the first step is install meson.

pip3 install meson

Build the package. Note that on Windows, x64 Native Tools Command Prompt is required to build.

python3 setup.py build

Install and use.

# Or pip3 install -e .
pip3 install .

Credits

Metadata

Release files for pyr2 2.0.0

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

Built distributions (wheels)

Table of built distributions (wheels) for pyr2 2.0.0
File Interpreter ABI Platform Actions
pyr2-2.0.0-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for pyr2-2.0.0-py3-none-win_amd64.whl
pyr2-2.0.0-py3-none-manylinux1_x86_64.whl Python 3 none Linux glibc 2.5+ x86-64 Details for pyr2-2.0.0-py3-none-manylinux1_x86_64.whl
pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl Python 3 none macOS 10.14+ x86-64 Details for pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl

Total release size: 34.6 MB

Release files / pyr2-2.0.0-py3-none-win_amd64.whl

Download URL pyr2-2.0.0-py3-none-win_amd64.whl
Size 6.7 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
f8fcd416242c552d59d8a9908ebc070a1b811674f91145b5147c768dfe80ccc7
BLAKE2b-256 checksum
How to use checksums
4f334d79975e2c2e86a75d428a8e04a08add51c785ddb1b6861fd6b1b7209732
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / pyr2-2.0.0-py3-none-manylinux1_x86_64.whl

Download URL pyr2-2.0.0-py3-none-manylinux1_x86_64.whl
Size 15.7 MB
Tags Linux glibc 2.5+ x86-64 Python 3
SHA-256 checksum
How to use checksums
83fc1106373edbda99828bcdcf0ea8a9b1ac5596f1c527f0f058953da6e9f6b6
BLAKE2b-256 checksum
How to use checksums
4792fec30626f8f1fd9e4a0d1b1a39e6a11dcf231b26aa064482c0ee503753f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Release files / pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl

Download URL pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl
Size 12.3 MB
Tags Python 3 macOS 10.14+ x86-64
SHA-256 checksum
How to use checksums
3c22d750939e3b98f77c1a95be2708d9b6a23de0bb3e34a475e824252f1c6b76
BLAKE2b-256 checksum
How to use checksums
22789bf0c34890243d5f04a0e4e4f7c0d2cbd296acc225db80ba6d3b46772487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

Security for pyr2 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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