Cutter: Redirect STDOUT to Console Widget for Python Plugins

Created on 6 Apr 2019  路  12Comments  路  Source: rizinorg/cutter

Is your feature request related to a problem? Please describe.

Currently, when Plugin author uses print("hello, world"), the output would be executed on the terminal which was executing Cutter (on windows usually there won't be a terminal for this).

This is unexpected behavior since we have a Console Widget

Describe the solution you'd like
I want STDOUT to be redirected to the Console widget. In general, but specifically here for Python Plugins.

Additional context

related issue: #966

Enhancement Plugin

Most helpful comment

And there are more ways to generate output to STDOUT and STDERR in python (and any other thingies), not only prints. Even when python throws exception I'd expect it to be on Console widget and not on the executing Terminal (which not always exists)

All 12 comments

Related: https://github.com/radare/radare2/pull/13622 (to not clutter the output as much)

So you can just use cutter.message() instead of print().

But people use print, which is okay, should be redirected to Cutter.Message

And there are more ways to generate output to STDOUT and STDERR in python (and any other thingies), not only prints. Even when python throws exception I'd expect it to be on Console widget and not on the executing Terminal (which not always exists)

Python and plugins are initialized before MainWindow. So we have to change the order.

We can have some kind of buffer for output received before the MainWindow has been started. There might be something interesting in it, even without Python Plugins.

I agree that this should be the default. Existing interactive disassembler platforms already behave this way, so now all of your users will expect Cutter to behave the same way whether you like it or not 馃槄

Might be best not to overthink this. IDA has a pretty straightforward implementation that you can draw from for Cutter.

They hook the interpreter's stdout/stderr stream with a simple proxy object:

https://github.com/idapython/src/blob/15b9ab2535222e492cd21b8528c27f763fb799d6/python/init.py#L98-L101

The proxy simply passes along any file descriptor writes to idaapi.msg(), eg cutter.message():

https://github.com/idapython/src/blob/15b9ab2535222e492cd21b8528c27f763fb799d6/python/init.py#L59-L62

@gaasedelen sounds great! Want to have a look and try solve it?
Actually, maybe this can be fixed globally somehow for the whole application https://github.com/radareorg/cutter/issues/966

Yes, this should not be done in python. There are ways to replace/redirect the actual stderr/stdout fds.

Working on this issue in PR #1821. If you have any additional suggestions or recommendations based on your experience please add them there.

The pull request https://github.com/radareorg/cutter/pull/1821 is not merged but we still did not solve the issue for python printings

Was this page helpful?
0 / 5 - 0 ratings