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.2.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 625f64360fc7763e76de59f18e7fac8bd12b8d11e564837bb5cda3fd2a908b68 |
|
MD5 | c98cf8dec78f13c6b92ac4254300639d |
|
BLAKE2b-256 | d50cd7685405f27edd2363e6fe2cdc9d6180623d830b0f087ccb8c5233a0bf0b |
Hashes for r2libr-5.2.0-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79628c9ac135ba9e6750f3b17281252654cec3da30455683f15fd67c061cc7f3 |
|
MD5 | bbc64f9ae579840d4e77c134a8c6763e |
|
BLAKE2b-256 | d2f71aee067e8fd896ca1e5b228ef1172e811d14a126291bb2149e11079c86ca |
Hashes for r2libr-5.2.0-py3-none-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4912cbec12f66f7a41f838323cfcd0cc717ea20811465889251a6e7dbd6e6eb |
|
MD5 | 4a1a84d2f02c3099e8a5628105aecaa2 |
|
BLAKE2b-256 | 13a09178470a9c572ce0633d26e8a002131a6bfb9498950ff9fd5ba267e99037 |