mirror of
https://github.com/frida/frida-python
synced 2026-06-08 14:16:17 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5215b5b2c8 | |||
| 54dca1d5da | |||
| 8eafeb24d9 | |||
| 1b75d93858 | |||
| c2145f3589 |
+19
-3
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
|
||||
from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union
|
||||
|
||||
try:
|
||||
from . import _frida
|
||||
@@ -86,14 +86,30 @@ def kill(target: core.ProcessTarget) -> None:
|
||||
|
||||
|
||||
def attach(
|
||||
target: core.ProcessTarget, realm: Optional[str] = None, persist_timeout: Optional[int] = None
|
||||
target: core.ProcessTarget,
|
||||
realm: Optional[str] = None,
|
||||
persist_timeout: Optional[int] = None,
|
||||
exceptor: Optional[str] = None,
|
||||
unwind_broker: Optional[bool] = None,
|
||||
exit_monitor: Optional[bool] = None,
|
||||
thread_suspend_monitor: Optional[bool] = None,
|
||||
linker_notifier_offsets: Optional[Sequence[int]] = None,
|
||||
) -> core.Session:
|
||||
"""
|
||||
Attach to a process
|
||||
:param target: the PID or name of the process
|
||||
"""
|
||||
|
||||
return get_local_device().attach(target, realm=realm, persist_timeout=persist_timeout)
|
||||
return get_local_device().attach(
|
||||
target,
|
||||
realm=realm,
|
||||
persist_timeout=persist_timeout,
|
||||
exceptor=exceptor,
|
||||
unwind_broker=unwind_broker,
|
||||
exit_monitor=exit_monitor,
|
||||
thread_suspend_monitor=thread_suspend_monitor,
|
||||
linker_notifier_offsets=linker_notifier_offsets,
|
||||
)
|
||||
|
||||
|
||||
def inject_library_file(target: core.ProcessTarget, path: str, entrypoint: str, data: str) -> int:
|
||||
|
||||
@@ -256,7 +256,17 @@ class Device(Object):
|
||||
"""
|
||||
...
|
||||
|
||||
def attach(self, pid: int, realm: Optional[str] = None, persist_timeout: Optional[int] = None) -> "Session":
|
||||
def attach(
|
||||
self,
|
||||
pid: int,
|
||||
realm: Optional[str] = None,
|
||||
persist_timeout: Optional[int] = None,
|
||||
exceptor: Optional[str] = None,
|
||||
unwind_broker: Optional[bool] = None,
|
||||
exit_monitor: Optional[bool] = None,
|
||||
thread_suspend_monitor: Optional[bool] = None,
|
||||
linker_notifier_offsets: Optional[Sequence[int]] = None,
|
||||
) -> "Session":
|
||||
"""
|
||||
Attach to a PID.
|
||||
"""
|
||||
|
||||
@@ -420,7 +420,7 @@ static PyObject * PyDevice_input (PyDevice * self, PyObject * args);
|
||||
static PyObject * PyDevice_resume (PyDevice * self, PyObject * args);
|
||||
static PyObject * PyDevice_kill (PyDevice * self, PyObject * args);
|
||||
static PyObject * PyDevice_attach (PyDevice * self, PyObject * args, PyObject * kw);
|
||||
static FridaSessionOptions * PyDevice_parse_session_options (const gchar * realm_value, guint persist_timeout);
|
||||
static FridaSessionOptions * PyDevice_parse_session_options (const gchar * realm_value, guint persist_timeout, const gchar * exceptor_value, gint unwind_broker, gint exit_monitor, gint thread_suspend_monitor, PyObject * linker_notifier_offsets_value);
|
||||
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);
|
||||
@@ -3081,21 +3081,43 @@ static PyObject *
|
||||
PyDevice_attach (PyDevice * self, PyObject * args, PyObject * kw)
|
||||
{
|
||||
PyObject * result = NULL;
|
||||
static char * keywords[] = { "pid", "realm", "persist_timeout", NULL };
|
||||
static char * keywords[] = {
|
||||
"pid",
|
||||
"realm",
|
||||
"persist_timeout",
|
||||
"exceptor",
|
||||
"unwind_broker",
|
||||
"exit_monitor",
|
||||
"thread_suspend_monitor",
|
||||
"linker_notifier_offsets",
|
||||
NULL
|
||||
};
|
||||
long pid;
|
||||
char * realm_value = NULL;
|
||||
unsigned int persist_timeout = 0;
|
||||
char * exceptor_value = NULL;
|
||||
int unwind_broker = -1;
|
||||
int exit_monitor = -1;
|
||||
int thread_suspend_monitor = -1;
|
||||
PyObject * linker_notifier_offsets_value = NULL;
|
||||
FridaSessionOptions * options = NULL;
|
||||
GError * error = NULL;
|
||||
FridaSession * handle;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kw, "l|esI", keywords,
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kw, "l|esIespppO", keywords,
|
||||
&pid,
|
||||
"utf-8", &realm_value,
|
||||
&persist_timeout))
|
||||
&persist_timeout,
|
||||
"utf-8", &exceptor_value,
|
||||
&unwind_broker,
|
||||
&exit_monitor,
|
||||
&thread_suspend_monitor,
|
||||
&linker_notifier_offsets_value))
|
||||
return NULL;
|
||||
|
||||
options = PyDevice_parse_session_options (realm_value, persist_timeout);
|
||||
options = PyDevice_parse_session_options (realm_value, persist_timeout,
|
||||
exceptor_value, unwind_broker, exit_monitor, thread_suspend_monitor,
|
||||
linker_notifier_offsets_value);
|
||||
if (options == NULL)
|
||||
goto beach;
|
||||
|
||||
@@ -3110,6 +3132,7 @@ PyDevice_attach (PyDevice * self, PyObject * args, PyObject * kw)
|
||||
beach:
|
||||
g_clear_object (&options);
|
||||
|
||||
PyMem_Free (exceptor_value);
|
||||
PyMem_Free (realm_value);
|
||||
|
||||
return result;
|
||||
@@ -3117,7 +3140,12 @@ beach:
|
||||
|
||||
static FridaSessionOptions *
|
||||
PyDevice_parse_session_options (const gchar * realm_value,
|
||||
guint persist_timeout)
|
||||
guint persist_timeout,
|
||||
const gchar * exceptor_value,
|
||||
gint unwind_broker,
|
||||
gint exit_monitor,
|
||||
gint thread_suspend_monitor,
|
||||
PyObject * linker_notifier_offsets_value)
|
||||
{
|
||||
FridaSessionOptions * options;
|
||||
|
||||
@@ -3135,6 +3163,50 @@ PyDevice_parse_session_options (const gchar * realm_value,
|
||||
|
||||
frida_session_options_set_persist_timeout (options, persist_timeout);
|
||||
|
||||
if (exceptor_value != NULL)
|
||||
{
|
||||
FridaExceptor exceptor;
|
||||
|
||||
if (!PyGObject_unmarshal_enum (exceptor_value, FRIDA_TYPE_EXCEPTOR, &exceptor))
|
||||
goto propagate_error;
|
||||
|
||||
frida_session_options_set_exceptor (options, exceptor);
|
||||
}
|
||||
|
||||
if (unwind_broker != -1)
|
||||
frida_session_options_set_unwind_broker (options, unwind_broker);
|
||||
|
||||
if (exit_monitor != -1)
|
||||
frida_session_options_set_exit_monitor (options, exit_monitor);
|
||||
|
||||
if (thread_suspend_monitor != -1)
|
||||
frida_session_options_set_thread_suspend_monitor (options, thread_suspend_monitor);
|
||||
|
||||
if (linker_notifier_offsets_value != NULL)
|
||||
{
|
||||
gint n, i;
|
||||
|
||||
n = PySequence_Size (linker_notifier_offsets_value);
|
||||
if (n == -1)
|
||||
goto propagate_error;
|
||||
|
||||
for (i = 0; i != n; i++)
|
||||
{
|
||||
PyObject * element;
|
||||
unsigned long offset;
|
||||
|
||||
element = PySequence_GetItem (linker_notifier_offsets_value, i);
|
||||
if (element == NULL)
|
||||
goto propagate_error;
|
||||
offset = PyLong_AsUnsignedLong (element);
|
||||
Py_DecRef (element);
|
||||
if (offset == (unsigned long) -1 && PyErr_Occurred () != NULL)
|
||||
goto propagate_error;
|
||||
|
||||
frida_session_options_add_linker_notifier_offset (options, offset);
|
||||
}
|
||||
}
|
||||
|
||||
return options;
|
||||
|
||||
propagate_error:
|
||||
|
||||
+14
-1
@@ -1046,13 +1046,26 @@ class Device:
|
||||
target: ProcessTarget,
|
||||
realm: Optional[str] = None,
|
||||
persist_timeout: Optional[int] = None,
|
||||
exceptor: Optional[str] = None,
|
||||
unwind_broker: Optional[bool] = None,
|
||||
exit_monitor: Optional[bool] = None,
|
||||
thread_suspend_monitor: Optional[bool] = None,
|
||||
linker_notifier_offsets: Optional[Sequence[int]] = None,
|
||||
) -> Session:
|
||||
"""
|
||||
Attach to a process
|
||||
:param target: the PID or name of the process
|
||||
"""
|
||||
|
||||
kwargs = {"realm": realm, "persist_timeout": persist_timeout}
|
||||
kwargs = {
|
||||
"realm": realm,
|
||||
"persist_timeout": persist_timeout,
|
||||
"exceptor": exceptor,
|
||||
"unwind_broker": unwind_broker,
|
||||
"exit_monitor": exit_monitor,
|
||||
"thread_suspend_monitor": thread_suspend_monitor,
|
||||
"linker_notifier_offsets": linker_notifier_offsets,
|
||||
}
|
||||
_filter_missing_kwargs(kwargs)
|
||||
return Session(self._impl.attach(self._pid_of(target), **kwargs)) # type: ignore
|
||||
|
||||
|
||||
+1
-1
Submodule releng updated: a76acfc2b5...029b3b189e
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/frida/frida-core.git
|
||||
revision = 17.9.11
|
||||
revision = 17.10.0
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
Reference in New Issue
Block a user