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 installand 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
Metadata
Release files for r2libr 5.7.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distributions (wheels)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| r2libr-5.7.4-py3-none-win_amd64.whl | Python 3 | none | Windows x86-64 | Details |
| r2libr-5.7.4-py3-none-manylinux1_x86_64.whl | Python 3 | none | Linux glibc 2.5+ x86-64 | Details |
| r2libr-5.7.4-py3-none-macosx_10_15_universal2.whl | Python 3 | none | macOS 10.15+ universal2 (ARM64, x86-64) | Details |
Total release size: 35.3 MB
Release files / r2libr-5.7.4-py3-none-win_amd64.whl
| Download URL | r2libr-5.7.4-py3-none-win_amd64.whl |
|---|---|
| Size | 7.1 MB |
| Tags | Python 3 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
93d80b435fcd237dc5a686737b09fdccd5853098d2bcf7a4f7fd601e77afa2dd
|
|
BLAKE2b-256 checksum How to use checksums |
d5b125ab0e33120602b122aaa2e610b30d5a644f0146a11d55c0ffd1763063c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / r2libr-5.7.4-py3-none-manylinux1_x86_64.whl
| Download URL | r2libr-5.7.4-py3-none-manylinux1_x86_64.whl |
|---|---|
| Size | 15.8 MB |
| Tags | Linux glibc 2.5+ x86-64 Python 3 |
|
SHA-256 checksum How to use checksums |
80df7902492de77e2cb770ecb7ffbe215908192962d95f0e43b42d3c3d464096
|
|
BLAKE2b-256 checksum How to use checksums |
0a72cb4a1479ac08d71025ae7f1874f515d1fd1b1eec460595af121f59a9f7b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / r2libr-5.7.4-py3-none-macosx_10_15_universal2.whl
| Download URL | r2libr-5.7.4-py3-none-macosx_10_15_universal2.whl |
|---|---|
| Size | 12.4 MB |
| Tags | Python 3 macOS 10.15+ universal2 (ARM64, x86-64) |
|
SHA-256 checksum How to use checksums |
c752e57085fed9d34527d2ff6692068c2a162c3477c0539e9e61cd7eb5acdcfc
|
|
BLAKE2b-256 checksum How to use checksums |
8e17a3aff7cbf00a84e6ce4710cc6e65907b308721a03013a2bd4a09669455c7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|