diff --git a/src/cutter.pro b/src/cutter.pro index 19713723..a6e49cac 100644 --- a/src/cutter.pro +++ b/src/cutter.pro @@ -93,8 +93,7 @@ SOURCES += \ widgets/VTablesWidget.cpp \ CutterApplication.cpp \ utils/JupyterConnection.cpp \ - widgets/JupyterWidget.cpp \ - utils/CommandServer.cpp + widgets/JupyterWidget.cpp HEADERS += \ cutter.h \ @@ -157,8 +156,7 @@ HEADERS += \ CutterApplication.h \ widgets/VTablesWidget.h \ utils/JupyterConnection.h \ - widgets/JupyterWidget.h \ - utils/CommandServer.h + widgets/JupyterWidget.h FORMS += \ dialogs/AboutDialog.ui \ diff --git a/src/utils/CommandServer.cpp b/src/utils/CommandServer.cpp deleted file mode 100644 index 51308e93..00000000 --- a/src/utils/CommandServer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -#include "CommandServer.h" -#include "cutter.h" - -CommandServer::CommandServer(QObject *parent) : QObject(parent) -{ - -} - -CommandServer::~CommandServer() -{ - -} - -/** - * @brief Open a local TCP server on port 1234 to read and execute commands. - * This is useful for Jupyter Notebook to access radare2 context using r2pipe - * Example usage: - * import r2pipe; r2 = r2pipe.open('tcp://localhost:1234'); print(r2.cmd('i')) - */ -bool CommandServer::startCommandServer() -{ - RCore* core = Core()->core(); - const char* port = "1234"; - - unsigned char buf[4097]; - RSocket *ch = NULL; - RSocket *s; - int i, ret; - char *str; - - s = r_socket_new (0); - r_socket_listen (s, port, NULL); - if (false) { - eprintf ("Error listening on port %s\n", port); - r_socket_free (s); - return false; - } - - eprintf ("Listening for commands on port %s\n", port); - while (isRunning) { - ch = r_socket_accept (s); - buf[0] = 0; - ret = r_socket_read (ch, buf, sizeof (buf) - 1); - if (ret > 0) { - buf[ret] = 0; - for (i = 0; buf[i]; i++) { - if (buf[i] == '\n') { - buf[i] = buf[i + 1]? ';': '\0'; - } - } - if ((!r_config_get_i (core->config, "scr.prompt") && - !strcmp ((char *)buf, "q!")) || - !strcmp ((char *)buf, ".--")) { - r_socket_close (ch); - break; - } - str = r_core_cmd_str (core, (const char *)buf); - if (str && *str) { - r_socket_write (ch, str, strlen (str)); - } else { - const char nl[] = "\n"; - r_socket_write (ch, (void*) nl, 1); - } - free (str); - } - r_socket_close (ch); - r_socket_free (ch); - ch = NULL; - } - r_socket_free (s); - r_socket_free (ch); - eprintf ("TCP Server (on %s) exited.\n", port); - - return true; -} - -void CommandServer::process() -{ - startCommandServer(); - emit finished(); -} - -/** - * Stops the server. - */ -void CommandServer::stop() -{ - isRunning = false; -} diff --git a/src/utils/CommandServer.h b/src/utils/CommandServer.h deleted file mode 100644 index cf8d42c2..00000000 --- a/src/utils/CommandServer.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef COMMANDSERVER_H -#define COMMANDSERVER_H - -#include - -class CommandServer : public QObject -{ - Q_OBJECT -public: - explicit CommandServer(QObject *parent = nullptr); - ~CommandServer(); - void stop(); - -signals: - void finished(); - void error(QString err); - -public slots: - void process(); - -private: - bool isRunning = true; - bool startCommandServer(); -}; - -#endif // COMMANDSERVER_H diff --git a/src/utils/JupyterConnection.cpp b/src/utils/JupyterConnection.cpp index fe250809..2590f5ec 100644 --- a/src/utils/JupyterConnection.cpp +++ b/src/utils/JupyterConnection.cpp @@ -25,8 +25,6 @@ JupyterConnection::~JupyterConnection() Py_FinalizeEx(); } - - cmdServer->stop(); } void JupyterConnection::start() @@ -35,6 +33,11 @@ void JupyterConnection::start() PyEval_InitThreads(); cutterJupyterModule = PyImport_ImportModule("cutter_jupyter"); + if (!cutterJupyterModule) + { + qWarning() << "Could not import cutter_jupyter."; + return; + } auto startFunc = PyObject_GetAttrString(cutterJupyterModule, "start_jupyter"); cutterNotebookAppInstance = PyObject_CallObject(startFunc, nullptr); auto urlWithToken = PyObject_GetAttrString(cutterNotebookAppInstance, "url_with_token"); @@ -44,15 +47,4 @@ void JupyterConnection::start() Py_DECREF(urlWithToken); pyThreadState = PyEval_SaveThread(); - - - cmdServerThread = new QThread(this); - cmdServer = new CommandServer(); - cmdServer->moveToThread(cmdServerThread); - connect(cmdServer, &CommandServer::error, this, [](QString err){ qWarning() << "CmdServer error:" << err; }); - connect(cmdServerThread, SIGNAL (started()), cmdServer, SLOT (process())); - connect(cmdServer, SIGNAL (finished()), cmdServerThread, SLOT (quit())); - connect(cmdServer, SIGNAL (finished()), cmdServer, SLOT (deleteLater())); - connect(cmdServerThread, SIGNAL (finished()), cmdServerThread, SLOT (deleteLater())); - cmdServerThread->start(); -} \ No newline at end of file +} diff --git a/src/utils/JupyterConnection.h b/src/utils/JupyterConnection.h index 021ae1cd..7df523a0 100644 --- a/src/utils/JupyterConnection.h +++ b/src/utils/JupyterConnection.h @@ -2,7 +2,6 @@ #define JUPYTERCONNECTION_H #include -#include "CommandServer.h" struct _object; typedef _object PyObject; @@ -24,9 +23,6 @@ signals: void urlReceived(const QString &url); private: - CommandServer *cmdServer; - QThread *cmdServerThread; - PyObject *cutterJupyterModule = nullptr; PyObject *cutterNotebookAppInstance = nullptr;