Skip to main content

Yet anohter radare2 python bindings.

Project description

r2libr

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 libr API and helps build your own tools.

Install

pip3 install --upgrade r2libr

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

Example

Implement a basic command line r2 by r2libr.

import libr
import ctypes
import argparse

class R2:

    def __init__(self, binary):
        binary = binary.encode("utf-8")
        self._r2c = libr.r_core.r_core_new()
        fh = libr.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
        libr.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)

    def cmd(self, cmd):
        r = libr.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):
        libr.r_core.r_core_free(self._r2c)

if __name__ == "__main__":
    ap = argparse.ArgumentParser("Implement a basic command line r2 by r2libr")
    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.

git clone https://github.com/radareorg/radare2-bindings
cd radare2-bindings/r2libr

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

If you're not sure about the file name format, learn more about wheel file names.

r2libr-5.2.1-py3-none-win_amd64.whl (6.7 MB view details)

Uploaded Python 3Windows x86-64

r2libr-5.2.1-py3-none-manylinux1_x86_64.whl (15.8 MB view details)

Uploaded Python 3

r2libr-5.2.1-py3-none-macosx_10_14_x86_64.whl (12.4 MB view details)

Uploaded Python 3macOS 10.14+ x86-64

File details

Details for the file r2libr-5.2.1-py3-none-win_amd64.whl.

File metadata

  • Download URL: r2libr-5.2.1-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/4.0.1 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 r2libr-5.2.1-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 4e1fd490c4c69e48b4a5ba196f2486aff19bf7818e0181412fe255c01a0aada7
MD5 35be4642aa885cfe583b2a33bc6db6b1
BLAKE2b-256 99e517200d305411ca889fcc4ea99155bcfb7820da40811d75bf6578ace9230c

See more details on using hashes here.

File details

Details for the file r2libr-5.2.1-py3-none-manylinux1_x86_64.whl.

File metadata

  • Download URL: r2libr-5.2.1-py3-none-manylinux1_x86_64.whl
  • Upload date:
  • Size: 15.8 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 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 r2libr-5.2.1-py3-none-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 8cccb50c66856970d21960f6b9fb8ec517600692cdd53a3112910287099d4e18
MD5 125a73990d0038a38c7d21b6255851bf
BLAKE2b-256 e3dbe9102589e37d01c5c2ff240f55f063df4a5ceade12fd23878c2041149302

See more details on using hashes here.

File details

Details for the file r2libr-5.2.1-py3-none-macosx_10_14_x86_64.whl.

File metadata

  • Download URL: r2libr-5.2.1-py3-none-macosx_10_14_x86_64.whl
  • Upload date:
  • Size: 12.4 MB
  • Tags: Python 3, macOS 10.14+ x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 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 r2libr-5.2.1-py3-none-macosx_10_14_x86_64.whl
Algorithm Hash digest
SHA256 e4c09aa3334a82247fcae49a5ada670e70213ad5594ebd21e25a965ed7b48ba5
MD5 6dc9e3713b7b58a8e2d709053aa6e78b
BLAKE2b-256 66edb687f1e936a1b0e1c55899a4e315a2e68619a762691a20c8198a180ca143

See more details on using hashes here.

Supported by

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