From cb34be7f0a09ea0eacba21eb4628cd8e6c603d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Wed, 15 Jul 2015 03:47:15 +0200 Subject: [PATCH] Add Device.get_frontmost_application() --- src/_frida.c | 20 ++++++++++++++++++++ src/frida/core.py | 3 +++ 2 files changed, 23 insertions(+) diff --git a/src/_frida.c b/src/_frida.c index da22af1..957fee1 100644 --- a/src/_frida.c +++ b/src/_frida.c @@ -140,6 +140,7 @@ static PyObject * PyDevice_from_handle (FridaDevice * handle); static int PyDevice_init (PyDevice * self); static void PyDevice_dealloc (PyDevice * self); static PyObject * PyDevice_repr (PyDevice * self); +static PyObject * PyDevice_get_frontmost_application (PyDevice * self); static PyObject * PyDevice_enumerate_applications (PyDevice * self); static PyObject * PyDevice_enumerate_processes (PyDevice * self); static PyObject * PyDevice_spawn (PyDevice * self, PyObject * args); @@ -205,6 +206,7 @@ static PyMethodDef PyDeviceManager_methods[] = static PyMethodDef PyDevice_methods[] = { + { "get_frontmost_application", (PyCFunction) PyDevice_get_frontmost_application, METH_NOARGS, "Get details about the frontmost application." }, { "enumerate_applications", (PyCFunction) PyDevice_enumerate_applications, METH_NOARGS, "Enumerate applications." }, { "enumerate_processes", (PyCFunction) PyDevice_enumerate_processes, METH_NOARGS, "Enumerate processes." }, { "spawn", (PyCFunction) PyDevice_spawn, METH_VARARGS, "Spawn a process into an attachable state." }, @@ -802,6 +804,24 @@ PyDevice_repr (PyDevice * self) return PyRepr_FromFormat ("Device(id=%u, name=\"%s\", type='%s')", self->id, self->name, self->type); } +static PyObject * +PyDevice_get_frontmost_application (PyDevice * self) +{ + GError * error = NULL; + FridaApplication * result; + + Py_BEGIN_ALLOW_THREADS + result = frida_device_get_frontmost_application_sync (self->handle, &error); + Py_END_ALLOW_THREADS + if (error != NULL) + return PyFrida_raise (error); + + if (result != NULL) + return PyApplication_from_handle (result); + else + Py_RETURN_NONE; +} + static PyObject * PyDevice_enumerate_applications (PyDevice * self) { diff --git a/src/frida/core.py b/src/frida/core.py index 004606e..8ed1469 100644 --- a/src/frida/core.py +++ b/src/frida/core.py @@ -45,6 +45,9 @@ class Device(object): def __repr__(self): return repr(self._impl) + def get_frontmost_application(self): + return self._impl.get_frontmost_application() + def enumerate_applications(self): return self._impl.enumerate_applications()