Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The outputs of 'cmd()' is empty on Windows 10 #146

Open
sdt27 opened this issue Jan 14, 2022 · 19 comments
Open

The outputs of 'cmd()' is empty on Windows 10 #146

sdt27 opened this issue Jan 14, 2022 · 19 comments

Comments

@sdt27
Copy link

sdt27 commented Jan 14, 2022

Environment

2022/01/14
5.5.4  r2
Windows 10 Enterprise
1.6.5 r2pipe

Description

There seems to be a bug here, the cmd command does not output the results correctly. This looks like an issue with newlines.

Test

examples>python
Python 3.10.1 (tags/v3.10.1:2cd268a, Dec  6 2021, 19:10:37) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import r2pipe
>>> r=r2pipe.open('hello.exe')
>>> print(r.cmd('uname'))
>>>#### the result is empty
>>> print(r.cmd('i'))
Windows 10 Enterprise
>>>#### the result is previous
@themaks
Copy link

themaks commented Jan 18, 2022

image
Here is a horrible work around :)

There seems to be an extra null-byte in the pipe at the start of the r2 process ?

@abay12676
Copy link

That's not a good work around, things are failing randomly due to these null bytes long after the pipe is opened.

@filipe-cogo
Copy link

Apparently changing zro = foo.find(b"\x00") to zro = foo.rfind(b"\x00") on _cmd_process(self, cmd) at open_sync.py solves the issue.

@radare
Copy link
Collaborator

radare commented Feb 6, 2022 via email

@stiv-kupchik
Copy link
Contributor

I had the same issue, and it seems that it's not only the first message after spawn that has a null byte - every command return started with \x00. I added a check after foo.read for this and it seemed to solve the issue

if os.name == "nt":
    if len(foo) > 1 and foo.startswith(b"\x00"):
        foo = foo[1:]

@radare
Copy link
Collaborator

radare commented Apr 25, 2022 via email

@stiv-kupchik stiv-kupchik mentioned this issue Apr 26, 2022
3 tasks
@trufae
Copy link
Contributor

trufae commented Apr 26, 2022

Fixed in master. thanks for submitting the fix!

@trufae trufae closed this as completed Apr 26, 2022
@jacob-pro
Copy link

I'm afraid this still doesn't work for me on Windows 11
Using r2 5.5.4

And I installed the latest from git:

pip install -e 'git+https://github.com/radareorg/radare2-r2pipe.git#egg=r2pipe&subdirectory=python'

With the above patch, but I still face the same problem, about 90% of the time the first cmd is empty, and the results don't come through unless I call r.cmd('') afterwards

@trufae
Copy link
Contributor

trufae commented Jun 2, 2022

r2 5.5.4 is pretty old, like 1 year old. there was a release of the r2pipe module so no need to install it from git. i'll look into that if that's not the case.

@trufae trufae reopened this Jun 2, 2022
@jacob-pro
Copy link

Last release of r2pipe on PyPi is 1.6.5 from November 2021, and doesn't have the code from #147 ?

@trufae
Copy link
Contributor

trufae commented Jun 3, 2022

omg i forgot to publish 1.6.6 🤦 i just pushed 1.7.0 with some more changes. can you try again? thanks for the headsup

@jacob-pro
Copy link

Thanks @trufae but it still doesn't work, what changes are you referring to?
Like I said I already tried commit e3b54c1 by downloading directly from git, but it still doesn't work unless I call r.cmd() twice.

I'm currently just doing this in my code to work around it:

def double_call(r, cmd):
    first = r.cmd(cmd)
    return first if len(first) > 0 else r.cmd("")

@trufae
Copy link
Contributor

trufae commented Jun 5, 2022

i had some time (finally) to test and fix it. Please try again with r2pipe 1.7.1 :) it seems to work well on windows linux and mac now. i need to improve the testsuite.

i have also realized that if you have outdated plugins, the "please run r2pm .." message is breaking r2pipe too.

@dobin
Copy link

dobin commented Mar 2, 2023

Still an issue for me, sadly:

  • python 3.11.2
  • r2pipe 1.7.4
  • radare2 5.8.2-w64

image

image

image

@radare
Copy link
Collaborator

radare commented Mar 2, 2023

I dont have windows 10, but on windows11 it works for me if i spawn python from inside r2. Like this:

cmd> radare2 -
[0x00000000]> #!pipe python
Python 3.10 ..
>>> import r2pipe
>>> r2 = r2pipe.open()
>>> r2.cmd("uname")
"Windows 10 Pro\n"

But it fails if i spawn r2 from the r2pipe instance.. so that means that i can repro, and it should be easy to fix. (hold my beer)

tempImagegDy1Xr

@radare
Copy link
Collaborator

radare commented Mar 2, 2023

uhm .wtf why this thing works from a script but not from prompt?
IMAGE 2023-03-02 17:53:40

@radare
Copy link
Collaborator

radare commented Mar 2, 2023

Looks like a racist condition 🤔

@spotted-deer
Copy link

spotted-deer commented Mar 9, 2023

Still an issue for me, sadly:

  • python 3.11.2
  • r2pipe 1.7.4
  • radare2 5.8.2-w64

image

image

image

I also meet this problem on Windows10 and Windows11. It work well in shell. But in r2pipe, I cannot get result from first time use r2pipe.cmd(xx), only second time use r2pipe.cmd(''), I can get really result.

@radare
Copy link
Collaborator

radare commented Mar 10, 2023

Fixed in r2pipe-1.8.0 please confirm :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants