From 795e522f02ba4cbd6d7b2968aa328c01a67fb95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 26 Jul 2022 17:32:01 -0400 Subject: [PATCH] Port to the new frida-core API --- frida/core.py | 16 +++++------ src/_frida.c | 74 +++++++++++++++++++++++++-------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/frida/core.py b/frida/core.py index 341e5c3..ac4164d 100644 --- a/frida/core.py +++ b/frida/core.py @@ -277,14 +277,6 @@ class Session(object): def compile_script(self, *args, **kwargs): return self._impl.compile_script(*args, **kwargs) - @cancellable - def enable_debugger(self, *args, **kwargs): - self._impl.enable_debugger(*args, **kwargs) - - @cancellable - def disable_debugger(self): - self._impl.disable_debugger() - @cancellable def setup_peer_connection(self, *args, **kwargs): self._impl.setup_peer_connection(*args, **kwargs) @@ -339,6 +331,14 @@ class Script(object): raw_message = json.dumps(message) self._impl.post(raw_message, **kwargs) + @cancellable + def enable_debugger(self, *args, **kwargs): + self._impl.enable_debugger(*args, **kwargs) + + @cancellable + def disable_debugger(self): + self._impl.disable_debugger() + def on(self, signal, callback): if signal == 'message': self._on_message_callbacks.append(callback) diff --git a/src/_frida.c b/src/_frida.c index 16745c6..d109c13 100644 --- a/src/_frida.c +++ b/src/_frida.c @@ -414,8 +414,6 @@ static PyObject * PySession_create_script (PySession * self, PyObject * args, Py static PyObject * PySession_create_script_from_bytes (PySession * self, PyObject * args, PyObject * kw); static PyObject * PySession_compile_script (PySession * self, PyObject * args, PyObject * kw); static FridaScriptOptions * PySession_parse_script_options (const gchar * name, const gchar * runtime_value); -static PyObject * PySession_enable_debugger (PySession * self, PyObject * args, PyObject * kw); -static PyObject * PySession_disable_debugger (PySession * self); static PyObject * PySession_setup_peer_connection (PySession * self, PyObject * args, PyObject * kw); static FridaPeerOptions * PySession_parse_peer_options (const gchar * stun_server, PyObject * relays); static PyObject * PySession_join_portal (PySession * self, PyObject * args, PyObject * kw); @@ -427,6 +425,8 @@ static PyObject * PyScript_load (PyScript * self); static PyObject * PyScript_unload (PyScript * self); static PyObject * PyScript_eternalize (PyScript * self); static PyObject * PyScript_post (PyScript * self, PyObject * args, PyObject * kw); +static PyObject * PyScript_enable_debugger (PyScript * self, PyObject * args, PyObject * kw); +static PyObject * PyScript_disable_debugger (PyScript * self); static int PyRelay_init (PyRelay * self, PyObject * args, PyObject * kw); static void PyRelay_init_from_handle (PyRelay * self, FridaRelay * handle); @@ -613,8 +613,6 @@ static PyMethodDef PySession_methods[] = { "create_script", (PyCFunction) PySession_create_script, METH_VARARGS | METH_KEYWORDS, "Create a new script." }, { "create_script_from_bytes", (PyCFunction) PySession_create_script_from_bytes, METH_VARARGS | METH_KEYWORDS, "Create a new script from bytecode." }, { "compile_script", (PyCFunction) PySession_compile_script, METH_VARARGS | METH_KEYWORDS, "Compile script source code to bytecode." }, - { "enable_debugger", (PyCFunction) PySession_enable_debugger, METH_VARARGS | METH_KEYWORDS, "Enable the Node.js compatible script debugger." }, - { "disable_debugger", (PyCFunction) PySession_disable_debugger, METH_NOARGS, "Disable the Node.js compatible script debugger." }, { "setup_peer_connection", (PyCFunction) PySession_setup_peer_connection, METH_VARARGS | METH_KEYWORDS, "Set up a peer connection with the target process." }, { "join_portal", (PyCFunction) PySession_join_portal, METH_VARARGS | METH_KEYWORDS, "Join a portal." }, { NULL } @@ -633,6 +631,8 @@ static PyMethodDef PyScript_methods[] = { "unload", (PyCFunction) PyScript_unload, METH_NOARGS, "Unload the script." }, { "eternalize", (PyCFunction) PyScript_eternalize, METH_NOARGS, "Eternalize the script." }, { "post", (PyCFunction) PyScript_post, METH_VARARGS | METH_KEYWORDS, "Post a JSON-encoded message to the script." }, + { "enable_debugger", (PyCFunction) PyScript_enable_debugger, METH_VARARGS | METH_KEYWORDS, "Enable the Node.js compatible script debugger." }, + { "disable_debugger", (PyCFunction) PyScript_disable_debugger, METH_NOARGS, "Disable the Node.js compatible script debugger." }, { NULL } }; @@ -4199,39 +4199,6 @@ invalid_argument: } } -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 (PY_GOBJECT_HANDLE (self), port, g_cancellable_get_current (), &error); - Py_END_ALLOW_THREADS - if (error != NULL) - return PyFrida_raise (error); - - Py_RETURN_NONE; -} - -static PyObject * -PySession_disable_debugger (PySession * self) -{ - GError * error = NULL; - - Py_BEGIN_ALLOW_THREADS - frida_session_disable_debugger_sync (PY_GOBJECT_HANDLE (self), g_cancellable_get_current (), &error); - Py_END_ALLOW_THREADS - if (error != NULL) - return PyFrida_raise (error); - - Py_RETURN_NONE; -} - static PyObject * PySession_setup_peer_connection (PySession * self, PyObject * args, PyObject * kw) { @@ -4501,6 +4468,39 @@ PyScript_post (PyScript * self, PyObject * args, PyObject * kw) Py_RETURN_NONE; } +static PyObject * +PyScript_enable_debugger (PyScript * 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_script_enable_debugger_sync (PY_GOBJECT_HANDLE (self), port, g_cancellable_get_current (), &error); + Py_END_ALLOW_THREADS + if (error != NULL) + return PyFrida_raise (error); + + Py_RETURN_NONE; +} + +static PyObject * +PyScript_disable_debugger (PyScript * self) +{ + GError * error = NULL; + + Py_BEGIN_ALLOW_THREADS + frida_script_disable_debugger_sync (PY_GOBJECT_HANDLE (self), g_cancellable_get_current (), &error); + Py_END_ALLOW_THREADS + if (error != NULL) + return PyFrida_raise (error); + + Py_RETURN_NONE; +} + static int PyRelay_init (PyRelay * self, PyObject * args, PyObject * kw)