Skip to content

Commit

Permalink
device: Add unpair()
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Oct 9, 2023
1 parent 1d35663 commit 3e489df
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
5 changes: 5 additions & 0 deletions _frida/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,11 @@ class Device(Object):
Open a device-specific communication channel.
"""
...
def unpair(self) -> None:
"""
Unpair device.
"""
...
def query_system_parameters(self) -> Dict[str, Any]:
"""
Returns a dictionary of information about the host system.
Expand Down
4 changes: 4 additions & 0 deletions examples/unpair.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import frida

device = frida.get_usb_device()
device.unpair()
8 changes: 8 additions & 0 deletions frida/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1035,6 +1035,14 @@ def open_channel(self, address: str) -> IOStream:

return IOStream(self._impl.open_channel(address))

@cancellable
def unpair(self) -> None:
"""
Unpair device
"""

self._impl.unpair()

@cancellable
def get_bus(self) -> Bus:
"""
Expand Down
18 changes: 17 additions & 1 deletion src/_frida.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2013-2022 Ole André Vadla Ravnås <[email protected]>
* Copyright (C) 2013-2023 Ole André Vadla Ravnås <[email protected]>
*
* Licence: wxWindows Library Licence, Version 3.1
*/
Expand Down Expand Up @@ -389,6 +389,7 @@ static FridaSessionOptions * PyDevice_parse_session_options (const gchar * realm
static PyObject * PyDevice_inject_library_file (PyDevice * self, PyObject * args);
static PyObject * PyDevice_inject_library_blob (PyDevice * self, PyObject * args);
static PyObject * PyDevice_open_channel (PyDevice * self, PyObject * args);
static PyObject * PyDevice_unpair (PyDevice * self);

static PyObject * PyApplication_new_take_handle (FridaApplication * handle);
static int PyApplication_init (PyApplication * self, PyObject * args, PyObject * kw);
Expand Down Expand Up @@ -565,6 +566,7 @@ static PyMethodDef PyDevice_methods[] =
{ "inject_library_file", (PyCFunction) PyDevice_inject_library_file, METH_VARARGS, "Inject a library file to a PID." },
{ "inject_library_blob", (PyCFunction) PyDevice_inject_library_blob, METH_VARARGS, "Inject a library blob to a PID." },
{ "open_channel", (PyCFunction) PyDevice_open_channel, METH_VARARGS, "Open a device-specific communication channel." },
{ "unpair", (PyCFunction) PyDevice_unpair, METH_NOARGS, "Unpair device." },
{ NULL }
};

Expand Down Expand Up @@ -2835,6 +2837,20 @@ PyDevice_open_channel (PyDevice * self, PyObject * args)
return PyIOStream_new_take_handle (stream);
}

static PyObject *
PyDevice_unpair (PyDevice * self)
{
GError * error = NULL;

Py_BEGIN_ALLOW_THREADS
frida_device_unpair_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 *
PyApplication_new_take_handle (FridaApplication * handle)
Expand Down

0 comments on commit 3e489df

Please sign in to comment.