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.7.0-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1773f8fa3be42e58eb6532670a776d406322991b0e3af26275d81e339dea9e7a |
|
MD5 | 26dfee6a07011d6b7cdd78edbe7b2900 |
|
BLAKE2b-256 | 84de5c4b9e5b1bdda71faf83c7216394706bbbce857ae45b85b2bfe14e792e61 |
Hashes for r2libr-5.7.0-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2f8d3a088bf6e0b23c40284569845381484a70e078b1a8ad8cdb702cb93e8bcc |
|
MD5 | 3ec0865ad44e53d2f35a610e86196bdc |
|
BLAKE2b-256 | 73fcdcb56bf44c53bdba14fc7c958667c1458686f3d448d05eb5b6078f154c14 |
Hashes for r2libr-5.7.0-py3-none-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 53f0e41c316eca139d95fad9186f603560dd306483fcb56435b8d44437c3d7d8 |
|
MD5 | 0b00b0a6a5d5bdf528ab3e12db379b6a |
|
BLAKE2b-256 | 900a990cb3882e2816b2352c42993519759425b9cff16a7e57aa88a10d577035 |