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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for r2libr-5.3.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 211756be38cbabb53afc6bc7f63bd0e6b494cc948ca4986ddc247166ad79e6e2 |
|
MD5 | 99f56e778a1fa141fb18504eda496658 |
|
BLAKE2b-256 | 3da629db9b8edbaa6464fcb58a862a6fdda208e6f3f462622baf3a30fd34075b |
Hashes for r2libr-5.3.0-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb33b086c365f60728cd4933df8a0ed276f6164772a12ef0ec50c0449f451cd0 |
|
MD5 | 68287d47b355de341b6c425c60339d08 |
|
BLAKE2b-256 | b242413af0763b1e554d7d1d240ecf6e1dae41b259614647cd7a2e656dfd6f96 |
Hashes for r2libr-5.3.0-py3-none-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55b3985055efd1b4a1cf8cf651d7e6f00e6f5dd72f39c19208fdaf0b9cb31e34 |
|
MD5 | a82be535d15eab1107188ce4bbfd082e |
|
BLAKE2b-256 | 3b902557e9483e496737703ac5b9248cf944cbe9f85ae601489e576c8e8df7c7 |