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 r2
import ctypes
import argparse
class R2:
def __init__(self, binary):
binary = binary.encode("utf-8")
self._r2c = r2.r_core.r_core_new()
fh = r2.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
r2.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)
def cmd(self, cmd):
r = r2.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):
r2.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.1.0.post1-py3-none-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 384a5220c293b0c8eda50c78d9eb4e8a3486df847c9ee6c732d6531ff6cad497 |
|
MD5 | 01b97b29896882a3e17db5f3b630376a |
|
BLAKE2b-256 | 5f0910f11821d8ec38c7739941d8545cc07f0011104e0e7f26c1c918c84d43e4 |
Hashes for r2libr-5.1.0.post1-py3-none-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 78bcfe25730f238a5109b7c0c9f4fbae90130e0d47edea10d76b45e35ba060e7 |
|
MD5 | 2d76befc887139c4c2903c202dbaabeb |
|
BLAKE2b-256 | 190251ea34320db4e0e575073c230cc8c30f687d3f93d36bd7c1dede5cad155c |
Hashes for r2libr-5.1.0.post1-py3-none-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63728d46c725433d12321157fb7223acda733615e5716bf2470fdd0485af13c5 |
|
MD5 | 122b9184121c3ffbe3bccdb11db68fba |
|
BLAKE2b-256 | 1288271caf04a9aa0c1abc446ce8e22043ccaf50b45c464a7cf515e8176b8d06 |