Skip to content

Commit 906ab1d

Browse files
committed
Rename import r2 to import r2libr
1 parent 1c5e2ad commit 906ab1d

30 files changed

+37
-37
lines changed

.github/workflows/generate_bindings.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
push:
55
paths:
66
- 'r2libr/**'
7-
- '!r2libr/r2/**'
7+
- '!r2libr/libr/**'
88
branches:
99
- "*"
1010
workflow_dispatch:
@@ -40,7 +40,7 @@ jobs:
4040
run: cd r2libr && env BINDINGS=1 python3 setup.py build
4141

4242
- name: Generate bindings.
43-
run: cd r2libr/tools && python3 gen.py -O ../r2/ -B ../radare2/pyr2installdir/
43+
run: cd r2libr/tools && python3 gen.py -O ../libr/ -B ../radare2/pyr2installdir/
4444

4545
- name: Test bindings.
4646
run: cd r2libr && python3 -m pip install -e . && cd tests && python3 test_r2libr.py

r2libr/README.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,24 @@ pip3 install --upgrade r2libr
2020
Implement a basic command line r2 by r2libr.
2121

2222
```python
23-
import r2
23+
import libr
2424
import ctypes
2525
import argparse
2626

2727
class R2:
2828

2929
def __init__(self, binary):
3030
binary = binary.encode("utf-8")
31-
self._r2c = r2.r_core.r_core_new()
32-
fh = r2.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
33-
r2.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)
31+
self._r2c = libr.r_core.r_core_new()
32+
fh = libr.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
33+
libr.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)
3434

3535
def cmd(self, cmd):
36-
r = r2.r_core.r_core_cmd_str(self._r2c, ctypes.create_string_buffer(cmd.encode("utf-8")))
36+
r = libr.r_core.r_core_cmd_str(self._r2c, ctypes.create_string_buffer(cmd.encode("utf-8")))
3737
return ctypes.string_at(r).decode('utf-8')
3838

3939
def __del__(self):
40-
r2.r_core.r_core_free(self._r2c)
40+
libr.r_core.r_core_free(self._r2c)
4141

4242
if __name__ == "__main__":
4343
ap = argparse.ArgumentParser("Implement a basic command line r2 by r2libr")

r2libr/examples/r2-cli.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
import r2
1+
import libr
22
import ctypes
33
import argparse
44

55
class R2:
66

77
def __init__(self, binary):
88
binary = binary.encode("utf-8")
9-
self._r2c = r2.r_core.r_core_new()
10-
fh = r2.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
11-
r2.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)
9+
self._r2c = libr.r_core.r_core_new()
10+
fh = libr.r_core.r_core_file_open(self._r2c, ctypes.create_string_buffer(binary), 0b101, 0)
11+
libr.r_core.r_core_bin_load(self._r2c, ctypes.create_string_buffer(binary), (1<<64) - 1)
1212

1313
def cmd(self, cmd):
14-
r = r2.r_core.r_core_cmd_str(self._r2c, ctypes.create_string_buffer(cmd.encode("utf-8")))
14+
r = libr.r_core.r_core_cmd_str(self._r2c, ctypes.create_string_buffer(cmd.encode("utf-8")))
1515
return ctypes.string_at(r).decode('utf-8')
1616

1717
def __del__(self):
18-
r2.r_core.r_core_free(self._r2c)
18+
libr.r_core.r_core_free(self._r2c)
1919

2020
if __name__ == "__main__":
2121
ap = argparse.ArgumentParser("Implement a basic command line r2 by r2libr")
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

r2libr/setup.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
ROOT_DIR = os.path.dirname(os.path.abspath(__file__))
2020
RADARE2_DIR = Path(ROOT_DIR) / "radare2"
21-
LIBS_DIR = Path(ROOT_DIR) / "r2" / "libr"
21+
LIBS_DIR = Path(ROOT_DIR) / "libr" / "libr"
2222

2323
def detect_python_on_windows():
2424
try:
@@ -38,7 +38,7 @@ def detect_python_on_windows():
3838

3939
def clean_builds():
4040
shutil.rmtree(Path(ROOT_DIR) / "build", ignore_errors=True)
41-
shutil.rmtree(Path(ROOT_DIR) / "r2" / "libr", ignore_errors=True)
41+
shutil.rmtree(Path(ROOT_DIR) / "libr" / "libr", ignore_errors=True)
4242
shutil.rmtree(Path(ROOT_DIR) / "radare2" / "pyr2installdir", ignore_errors=True)
4343
shutil.rmtree(Path(ROOT_DIR) / "radare2" / "pyr2build", ignore_errors=True)
4444

@@ -176,7 +176,7 @@ def build_radare2():
176176
if sys.platform == "darwin" and not p.is_symlink():
177177
rewrite_dyld_path(p)
178178
# Known Issue: Altough we copy symlinks here, still python would follow symlink and copy a duplicate one.
179-
# To keep r2libs.py simple (meson write versions to file names), let's keep that copy.
179+
# To keep r_libs.py simple (meson write versions to file names), let's keep that copy.
180180
shutil.copy(p, LIBS_DIR, follow_symlinks=False)
181181
os.chdir(ROOT_DIR)
182182

@@ -227,7 +227,7 @@ def run(self):
227227

228228
setuptools.setup(
229229
name="r2libr",
230-
version="5.1.0-1",
230+
version="5.1.0-2",
231231
author="mio",
232232
author_email="[email protected]",
233233
description="Yet anohter radare2 python bindings.",
@@ -248,7 +248,7 @@ def run(self):
248248
include_package_data=True,
249249
is_pure=False,
250250
package_data= {
251-
"r2" : ['libr/*']
251+
"libr" : ['libr/*']
252252
}
253253
)
254254

r2libr/tests/test_r2libr.py

+18-18
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import unittest
22
import ctypes
3-
import r2
3+
import libr
44
import json
55
import struct
66
import sys
@@ -13,43 +13,43 @@
1313
class R2LIBRTest(unittest.TestCase):
1414

1515
def __get_r_core(self):
16-
r2c = r2.r_core.r_core_new()
17-
fh = r2.r_core.r_core_file_open(r2c, ctypes.create_string_buffer(example_file), 0b101, 0)
18-
r2.r_core.r_core_bin_load(r2c, ctypes.create_string_buffer(example_file), (1<<64) - 1)
16+
r2c = libr.r_core.r_core_new()
17+
fh = libr.r_core.r_core_file_open(r2c, ctypes.create_string_buffer(example_file), 0b101, 0)
18+
libr.r_core.r_core_bin_load(r2c, ctypes.create_string_buffer(example_file), (1<<64) - 1)
1919
return r2c
2020

2121
def test_r_core(self):
2222
r2c = self.__get_r_core()
23-
r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"ieq"))
24-
r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"aaa"))
23+
libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"ieq"))
24+
libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"aaa"))
2525
if sys.platform != "win32":
26-
print(f'Disasm 1 instruction:\n{ctypes.string_at(r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"pd 1"))).decode("utf-8")}')
26+
print(f'Disasm 1 instruction:\n{ctypes.string_at(libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"pd 1"))).decode("utf-8")}')
2727
else:
2828
# CMD doesn't support colors.
29-
print(f'Disasm 1 instruction:\n{ctypes.string_at(r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"pdj 1"))).decode("utf-8")}')
30-
r2.r_core.r_core_free(r2c)
29+
print(f'Disasm 1 instruction:\n{ctypes.string_at(libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"pdj 1"))).decode("utf-8")}')
30+
libr.r_core.r_core_free(r2c)
3131

3232
def test_r_anal(self):
3333
r2c = self.__get_r_core()
34-
r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"ieq"))
35-
r2.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"aaa"))
34+
libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"ieq"))
35+
libr.r_core.r_core_cmd_str(r2c, ctypes.create_string_buffer(b"aaa"))
3636
# Workaround for multiple declarations in sources.
37-
r2anal = ctypes.cast(ctypes.addressof(r2c.contents.anal.contents), ctypes.POINTER(r2.r_anal.struct_r_anal_t))
38-
print(f"We have {r2.r_anal.r_anal_xrefs_count(r2anal)} xrefs!")
37+
r2anal = ctypes.cast(ctypes.addressof(r2c.contents.anal.contents), ctypes.POINTER(libr.r_anal.struct_r_anal_t))
38+
print(f"We have {libr.r_anal.r_anal_xrefs_count(r2anal)} xrefs!")
3939

4040
def test_r_asm(self):
4141
buffer = b"\x90\x90\x90"
4242
buffer = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte))
4343
r2c = self.__get_r_core()
44-
r2asm = ctypes.cast(r2c.contents.rasm, ctypes.POINTER(r2.r_asm.struct_r_asm_t))
45-
asmcode = r2.r_asm.r_asm_mdisassemble(r2asm, buffer, 3)
44+
r2asm = ctypes.cast(r2c.contents.rasm, ctypes.POINTER(libr.r_asm.struct_r_asm_t))
45+
asmcode = libr.r_asm.r_asm_mdisassemble(r2asm, buffer, 3)
4646
disasm_output = ctypes.string_at(asmcode.contents.assembly).decode('utf-8')
4747
self.assertEqual(disasm_output, "nop\nnop\nnop\n")
4848

4949
def test_r_util_json(self):
5050
json_str = b'{"key" : "value"}'
51-
rjson = r2.r_util.r_json_parse(json_str)
52-
rjson = r2.r_util.r_json_get(rjson, b"key")
51+
rjson = libr.r_util.r_json_parse(json_str)
52+
rjson = libr.r_util.r_json_get(rjson, b"key")
5353
value = ctypes.string_at(rjson.contents.str_value).decode("utf-8")
5454
self.assertEqual(value, "value")
5555

@@ -58,7 +58,7 @@ def test_r_util_utf8(self):
5858
rune = ord(u8)
5959
buffer = ctypes.create_string_buffer(4)
6060
buffer = ctypes.cast(buffer, ctypes.POINTER(ctypes.c_ubyte))
61-
l = r2.r_util.r_utf8_encode(buffer, ctypes.c_uint32(rune))
61+
l = libr.r_util.r_utf8_encode(buffer, ctypes.c_uint32(rune))
6262
self.assertEqual(ctypes.string_at(buffer, l), u8.encode("utf-8"))
6363

6464
if __name__ == "__main__":

0 commit comments

Comments
 (0)