Skip to main content

Yet anohter radare2 python bindings.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

pyr2-2.0.0-py3-none-win_amd64.whl (6.7 MB view details)

Uploaded Python 3 Windows x86-64

pyr2-2.0.0-py3-none-manylinux1_x86_64.whl (15.7 MB view details)

Uploaded Python 3

pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl (12.3 MB view details)

Uploaded Python 3 macOS 10.14+ x86-64

File details

Details for the file pyr2-2.0.0-py3-none-win_amd64.whl.

File metadata

  • Download URL: pyr2-2.0.0-py3-none-win_amd64.whl
  • Upload date:
  • Size: 6.7 MB
  • Tags: Python 3, Windows x86-64
  • Uploaded using 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

File hashes

Hashes for pyr2-2.0.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 f8fcd416242c552d59d8a9908ebc070a1b811674f91145b5147c768dfe80ccc7
MD5 7e8cc4d86e06378d10bbe86bfa9dce55
BLAKE2b-256 4f334d79975e2c2e86a75d428a8e04a08add51c785ddb1b6861fd6b1b7209732

See more details on using hashes here.

File details

Details for the file pyr2-2.0.0-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: pyr2-2.0.0-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 15.7 MB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pyr2-2.0.0-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 83fc1106373edbda99828bcdcf0ea8a9b1ac5596f1c527f0f058953da6e9f6b6
MD5 30796da0df4b1ccd49c9c8852b5c5d48
BLAKE2b-256 4792fec30626f8f1fd9e4a0d1b1a39e6a11dcf231b26aa064482c0ee503753f5

See more details on using hashes here.

File details

Details for the file pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 12.3 MB
  • Tags: Python 3, macOS 10.14+ x86-64
  • Uploaded using 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

File hashes

Hashes for pyr2-2.0.0-py3-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 3c22d750939e3b98f77c1a95be2708d9b6a23de0bb3e34a475e824252f1c6b76
MD5 d8a497c26d6b06708d6529af84c0f536
BLAKE2b-256 22789bf0c34890243d5f04a0e4e4f7c0d2cbd296acc225db80ba6d3b46772487

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page