Python 2.7.6 r2pipe.打开加载二进制文件失败



我安装了r2pipe,但是它没有运行。我不明白。

 Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
   [GCC 4.8.2] on linux2
   Type "help", "copyright", "credits" or "license" for more information.  
   >>> import r2pipe
   >>> r2 = r2pipe.open("/bin/ls")
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "/usr/local/lib/python2.7/dist-packages/r2pipe/__init__.py", line      132, in __init__
   self.process = Popen(cmd, shell=False, stdin=PIPE, stdout=PIPE)
   File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
   errread, errwrite)
   File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
   raise child_exception
   OSError: [Errno 2] No such file or directory

环境

  • Python: Python 2.7.15+(默认,Oct 7 2019, 17:39:04)
  • 系统: Ubuntu 18.04 LTS
解决方案

  • r2pipe必须正确安装,radare2必须正确安装在系统上。
    • 按照下面的说明安装r2pipe: https://github.com/radareorg/radare2-r2pipe/tree/master/python
    • 安装radare2通过git按照下面的说明:https://github.com/radareorg/radare2
示例

未安装r2pipe和radare2的示例

user@host:~$ python
Python 2.7.15+ (default, Oct  7 2019, 17:39:04) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import r2pipe
>>> Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named r2pipe
>>> exit()
user@host:~$

安装r2pipe但不安装radare2的示例。

user@host:~$ pip install r2pipe
Collection r2pipe
...
Successfully installed r2pipe-1.4.2
user@host:~$ python
Python 2.7.15+ (default, Oct  7 2019, 17:39:04) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import r2pipe
>>> r2 = r2pipe.open("/bin/ls")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/.local/lib/python2.7/site-packages/r2pipe/open_sync.py", line 62, in __init__
    raise Exception("ERROR: Cannot find radare2 in PATH")
Exception: ERROR: Cannot find radare2 in PATH
>>> exit()
user@host:~$

安装r2pipe和radare2的示例

user@host:~$ git clone https://github.com/radareorg/radare2.git
cloning into 'radare2'...
...
user@host:~$ ./radare2/sys/install.sh
...
user@host:~$ r2
Usage: r2 [-ACdfLMnNqStuvwzX] [-P patch] [-p prj] [-a arch] [-b bits] [-i file]
          [-s addr] [-B baddr] [-m maddr] [-c cmd] [-e k=v] file|pid|-|--|=
user@host:~$ python
Python 2.7.15+ (default, Oct  7 2019, 17:39:04) 
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import r2pipe
>>> r2 = r2pipe.open("/bin/ls")
>>> r2.cmd('aaaa')
...
>>> print r2.cmd('afl')
0x00005850    1 42           entry0
0x0001636c    1 9            sym._fini
0x00003758    3 23           sym._init
0x00015690    5 42   -> 38   sym._obstack_memory_used
...
0x00005950    5 154  -> 67   entry.init0
0x00005910    5 58   -> 51   entry.fini0
0x00005880    4 50   -> 40   fcn.00005880
>>> exit()
user@host:~$

最新更新