Skip to content

Commit cc9a78e

Browse files
committed
device: Add override_option()
Expose Device.override_option() for overriding backend-specific options on a device. Overrides apply when establishing a host session. If one already exists, changes take effect on the next connection.
1 parent 22ed1fa commit cc9a78e

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

frida/_frida/extension.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ static void PyDevice_init_from_handle (PyDevice * self, FridaDevice * handle);
404404
static void PyDevice_dealloc (PyDevice * self);
405405
static PyObject * PyDevice_repr (PyDevice * self);
406406
static PyObject * PyDevice_is_lost (PyDevice * self);
407+
static PyObject * PyDevice_override_option (PyDevice * self, PyObject * args, PyObject * kw);
407408
static PyObject * PyDevice_query_system_parameters (PyDevice * self);
408409
static PyObject * PyDevice_get_frontmost_application (PyDevice * self, PyObject * args, PyObject * kw);
409410
static PyObject * PyDevice_enumerate_applications (PyDevice * self, PyObject * args, PyObject * kw);
@@ -620,6 +621,7 @@ static PyMethodDef PyDeviceManager_methods[] =
620621
static PyMethodDef PyDevice_methods[] =
621622
{
622623
{ "is_lost", (PyCFunction) PyDevice_is_lost, METH_NOARGS, "Query whether the device has been lost." },
624+
{ "override_option", (PyCFunction) PyDevice_override_option, METH_VARARGS | METH_KEYWORDS, "Override a backend-specific option." },
623625
{ "query_system_parameters", (PyCFunction) PyDevice_query_system_parameters, METH_NOARGS, "Returns a dictionary of information about the host system." },
624626
{ "get_frontmost_application", (PyCFunction) PyDevice_get_frontmost_application, METH_VARARGS | METH_KEYWORDS, "Get details about the frontmost application." },
625627
{ "enumerate_applications", (PyCFunction) PyDevice_enumerate_applications, METH_VARARGS | METH_KEYWORDS, "Enumerate applications." },
@@ -2521,6 +2523,33 @@ PyDevice_is_lost (PyDevice * self)
25212523
return PyBool_FromLong (is_lost);
25222524
}
25232525

2526+
static PyObject *
2527+
PyDevice_override_option (PyDevice * self, PyObject * args, PyObject * kw)
2528+
{
2529+
static char * keywords[] = { "name", "value", NULL };
2530+
const char * name;
2531+
PyObject * value;
2532+
GVariant * raw_value;
2533+
GError * error = NULL;
2534+
2535+
if (!PyArg_ParseTupleAndKeywords (args, kw, "sO", keywords, &name, &value))
2536+
return NULL;
2537+
2538+
if (!PyGObject_unmarshal_variant (value, &raw_value))
2539+
return NULL;
2540+
2541+
Py_BEGIN_ALLOW_THREADS
2542+
frida_device_override_option (PY_GOBJECT_HANDLE (self), name, raw_value, &error);
2543+
Py_END_ALLOW_THREADS
2544+
2545+
g_variant_unref (raw_value);
2546+
2547+
if (error != NULL)
2548+
return PyFrida_raise (error);
2549+
2550+
PyFrida_RETURN_NONE;
2551+
}
2552+
25242553
static PyObject *
25252554
PyDevice_query_system_parameters (PyDevice * self)
25262555
{

frida/core.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,14 @@ def is_lost(self) -> bool:
883883

884884
return self._impl.is_lost()
885885

886+
@cancellable
887+
def override_option(self, name: str, value: Any) -> None:
888+
"""
889+
Override a backend-specific option
890+
"""
891+
892+
self._impl.override_option(name, value)
893+
886894
@cancellable
887895
def query_system_parameters(self) -> Dict[str, Any]:
888896
"""

0 commit comments

Comments
 (0)