mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Removed old r2pipe server
This commit is contained in:
parent
3164b5c118
commit
a5e77c5095
@ -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 \
|
||||
|
@ -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;
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef COMMANDSERVER_H
|
||||
#define COMMANDSERVER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
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
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@
|
||||
#define JUPYTERCONNECTION_H
|
||||
|
||||
#include <QProcess>
|
||||
#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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user