Add enable_debugger() and disable_debugger() to Session

The underlying implementation defaults to port 5858, which is the
default Node.js debugger port. Pass the `port` keyword argument to
override it:

```python
session.enable_debugger(port=1337)
```
This commit is contained in:
Ole André Vadla Ravnås
2015-04-14 20:02:33 +02:00
parent 1104a011c5
commit 8ca3c47aee
2 changed files with 51 additions and 0 deletions
+45
View File
@@ -152,6 +152,8 @@ static int PySession_init (PySession * self);
static void PySession_dealloc (PySession * self);
static PyObject * PySession_detach (PySession * self);
static PyObject * PySession_create_script (PySession * self, PyObject * args, PyObject * kw);
static PyObject * PySession_enable_debugger (PySession * self, PyObject * args, PyObject * kw);
static PyObject * PySession_disable_debugger (PySession * self, PyObject * args);
static PyObject * PySession_on (PySession * self, PyObject * args);
static PyObject * PySession_off (PySession * self, PyObject * args);
static void PySession_on_detached (PySession * self, FridaSession * handle);
@@ -226,6 +228,8 @@ static PyMethodDef PySession_methods[] =
{
{ "detach", (PyCFunction) PySession_detach, METH_NOARGS, "Detach session from the process." },
{ "create_script", (PyCFunction) PySession_create_script, METH_VARARGS | METH_KEYWORDS, "Create a new script." },
{ "enable_debugger", (PyCFunction) PySession_enable_debugger, METH_VARARGS | METH_KEYWORDS, "Enable the Node.js compatible script debugger." },
{ "disable_debugger", (PyCFunction) PySession_disable_debugger, METH_VARARGS, "Disable the Node.js compatible script debugger." },
{ "on", (PyCFunction) PySession_on, METH_VARARGS, "Add an event handler." },
{ "off", (PyCFunction) PySession_off, METH_VARARGS, "Remove an event handler." },
{ NULL }
@@ -1181,6 +1185,47 @@ PySession_create_script (PySession * self, PyObject * args, PyObject * kw)
return PyScript_from_handle (handle);
}
static PyObject *
PySession_enable_debugger (PySession * self, PyObject * args, PyObject * kw)
{
static char * keywords[] = { "port", NULL };
unsigned short int port = 0;
GError * error = NULL;
if (!PyArg_ParseTupleAndKeywords (args, kw, "|H", keywords, &port))
return NULL;
Py_BEGIN_ALLOW_THREADS
frida_session_enable_debugger_sync (self->handle, port, &error);
Py_END_ALLOW_THREADS
if (error != NULL)
{
PyErr_SetString (PyExc_SystemError, error->message);
g_error_free (error);
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *
PySession_disable_debugger (PySession * self, PyObject * args)
{
GError * error = NULL;
Py_BEGIN_ALLOW_THREADS
frida_session_disable_debugger_sync (self->handle, &error);
Py_END_ALLOW_THREADS
if (error != NULL)
{
PyErr_SetString (PyExc_SystemError, error->message);
g_error_free (error);
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *
PySession_on (PySession * self, PyObject * args)
{
+6
View File
@@ -183,6 +183,12 @@ recv(function (string) {
def create_script(self, source, **kwargs):
return self._impl.create_script(source, **kwargs)
def enable_debugger(self, **kwargs):
return self._impl.enable_debugger(**kwargs)
def disable_debugger(self):
return self._impl.disable_debugger()
def on(self, signal, callback):
self._impl.on(signal, callback)