radareorg/radare2-r2pipe

r2pipe cannot `open` when it is being called from radare2 (using pipe)

a1ext opened this issue · 3 comments

a1ext commented

I have the following python code (test_r2lang_pipe.py) to check is pipe connection with radare2 works:

from __future__ import print_function

import sys
# sys.path.append(r't:\radare2-r2pipe\python')
print('python ver:', sys.version)
import r2pipe
r = r2pipe.open()
r.cmd('aa')
print(r.cmd('pd 10'))

When I run it on Windows with Python 2 it works well:

# radare2 -i t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py rabin2.exe
python ver: 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)]
[x] Analyze all flags starting with sym. and entry0 (aa)
/ (fcn) entry0 373
|   entry0 (int arg5, int arg2);
|       :   ; var int local_8h @ rsp+0x8
|       :   ; var int local_10h @ rsp+0x10
|       :   ; var int local_20h @ rsp+0x20
|       :   ; var int local_40h @ rsp+0x40
|       :   ; var int local_48h @ rsp+0x48
|       :   ; arg int arg5 @ r8
|       :   ; arg int arg2 @ rsi
|       :   0x14001a6f4      4883ec28       sub rsp, 0x28              ; '('
|       :   0x14001a6f8      e85b050000     call 0x14001ac58
|       :   0x14001a6fd      4883c428       add rsp, 0x28              ; '('
\       `=< 0x14001a701      e972feffff     jmp 0x14001a578
            0x14001a706      cc             int3
            0x14001a707      cc             int3
            0x14001a708      4053           push rbx
            0x14001a70a      4883ec20       sub rsp, 0x20
            0x14001a70e      488bd9         mov rbx, rcx
            0x14001a711      33c9           xor ecx, ecx
 -- Initial frame selected; you cannot go up.
[0x14001a6f4]> q

But when I run it with Python 3 it fails:

# set PATH=c:\Python36x64;%PATH%
# radare2 -i t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py rabin2.exe
python ver: 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)]
Invalid Handle Value
Could not open pipe
Traceback (most recent call last):
  File "t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py", line 10, in <module>
    print('`aa` returned:', r.cmd('aa'))
  File "c:\Python36x64\lib\site-packages\r2pipe\open_base.py", line 197, in cmd
    res = self._cmd(cmd, **kwargs)
AttributeError: 'open' object has no attribute '_cmd'
a1ext commented

This is fixed in git already. Will do a new release when i get my hands on a keyboard today

On 15 Dec 2018, at 18:05, a1ext @.***> wrote: I have the following python code (test_r2lang_pipe.py) to check is pipe connection with radare2 works: from future import print_function import sys # sys.path.append(r't:\radare2-r2pipe\python') print('python ver:', sys.version) import r2pipe r = r2pipe.open() r.cmd('aa') print(r.cmd('pd 10')) When I run it on Windows with Python 2 it works well: # radare2 -i t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py rabin2.exe python ver: 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] [x] Analyze all flags starting with sym. and entry0 (aa) / (fcn) entry0 373 | entry0 (int arg5, int arg2); | : ; var int local_8h @ rsp+0x8 | : ; var int local_10h @ rsp+0x10 | : ; var int local_20h @ rsp+0x20 | : ; var int local_40h @ rsp+0x40 | : ; var int local_48h @ rsp+0x48 | : ; arg int arg5 @ r8 | : ; arg int arg2 @ rsi | : 0x14001a6f4 4883ec28 sub rsp, 0x28 ; '(' | : 0x14001a6f8 e85b050000 call 0x14001ac58 | : 0x14001a6fd 4883c428 add rsp, 0x28 ; '(' \ =< 0x14001a701 e972feffff jmp 0x14001a578 0x14001a706 cc int3 0x14001a707 cc int3 0x14001a708 4053 push rbx 0x14001a70a 4883ec20 sub rsp, 0x20 0x14001a70e 488bd9 mov rbx, rcx 0x14001a711 33c9 xor ecx, ecx -- Initial frame selected; you cannot go up. [0x14001a6f4]> q But when I run it with Python 3 it fails: # set PATH=c:\Python36x64;%PATH% # radare2 -i t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py rabin2.exe python ver: 3.6.6 (v3.6.6:4cf1f54eb7, Jun 27 2018, 03:37:03) [MSC v.1900 64 bit (AMD64)] Invalid Handle Value Could not open pipe Traceback (most recent call last): File "t:\radare2-r2pipe\python\examples\test_r2lang_pipe.py", line 10, in <module> print('aa` returned:', r.cmd('aa')) File "c:\Python36x64\lib\site-packages\r2pipe\open_base.py", line 197, in cmd res = self._cmd(cmd, **kwargs) AttributeError: 'open' object has no attribute '_cmd' — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

which one?

a1ext commented

Fixes #64 as well