diff --git a/src/_frida.c b/src/_frida.c index 5c45d96..72bdb8c 100644 --- a/src/_frida.c +++ b/src/_frida.c @@ -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) { diff --git a/src/frida/core.py b/src/frida/core.py index d58fe77..ece2245 100644 --- a/src/frida/core.py +++ b/src/frida/core.py @@ -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)