mirror of
https://github.com/frida/frida-python.git
synced 2026-11-11 10:01:27 -10:00
Compare commits
No files matched your search
+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.
|
||||
"""
|
||||
@@ -354,6 +364,12 @@ class Device(Object):
|
||||
"""
|
||||
...
|
||||
|
||||
def override_option(self, name: str, value: Any) -> None:
|
||||
"""
|
||||
Override a backend-specific option.
|
||||
"""
|
||||
...
|
||||
|
||||
def query_system_parameters(self) -> Dict[str, Any]:
|
||||
"""
|
||||
Returns a dictionary of information about the host system.
|
||||
@@ -611,6 +627,12 @@ class Script(Object):
|
||||
"""
|
||||
...
|
||||
|
||||
def interrupt(self) -> None:
|
||||
"""
|
||||
Interrupt any JavaScript currently executing in the script.
|
||||
"""
|
||||
...
|
||||
|
||||
def post(self, message: str, data: Optional[Union[str, bytes]] = None) -> None:
|
||||
"""
|
||||
Post a JSON-encoded message to the script.
|
||||
@@ -623,6 +645,12 @@ class Script(Object):
|
||||
"""
|
||||
...
|
||||
|
||||
def terminate(self) -> None:
|
||||
"""
|
||||
Interrupt execution and unload the script.
|
||||
"""
|
||||
...
|
||||
|
||||
def enable_debugger(self, port: Optional[int]) -> None:
|
||||
"""
|
||||
Enable the Node.js compatible script debugger
|
||||
|
||||
+110
-6
@@ -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);
|
||||
@@ -492,7 +492,9 @@ static FridaPortalOptions * PySession_parse_portal_options (const gchar * certif
|
||||
static PyObject * PyScript_new_take_handle (FridaScript * handle);
|
||||
static PyObject * PyScript_is_destroyed (PyScript * self);
|
||||
static PyObject * PyScript_load (PyScript * self);
|
||||
static PyObject * PyScript_interrupt (PyScript * self);
|
||||
static PyObject * PyScript_unload (PyScript * self);
|
||||
static PyObject * PyScript_terminate (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);
|
||||
@@ -740,7 +742,9 @@ static PyMethodDef PyScript_methods[] =
|
||||
{
|
||||
{ "is_destroyed", (PyCFunction) PyScript_is_destroyed, METH_NOARGS, "Query whether the script has been destroyed." },
|
||||
{ "load", (PyCFunction) PyScript_load, METH_NOARGS, "Load the script." },
|
||||
{ "interrupt", (PyCFunction) PyScript_interrupt, METH_NOARGS, "Interrupt any JavaScript currently executing in the script." },
|
||||
{ "unload", (PyCFunction) PyScript_unload, METH_NOARGS, "Unload the script." },
|
||||
{ "terminate", (PyCFunction) PyScript_terminate, METH_NOARGS, "Interrupt execution and 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." },
|
||||
@@ -3081,21 +3085,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 +3136,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 +3144,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 +3167,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:
|
||||
@@ -4340,6 +4416,20 @@ PyScript_load (PyScript * self)
|
||||
PyFrida_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyScript_interrupt (PyScript * self)
|
||||
{
|
||||
GError * error = NULL;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
frida_script_interrupt_sync (PY_GOBJECT_HANDLE (self), g_cancellable_get_current (), &error);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (error != NULL)
|
||||
return PyFrida_raise (error);
|
||||
|
||||
PyFrida_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyScript_unload (PyScript * self)
|
||||
{
|
||||
@@ -4354,6 +4444,20 @@ PyScript_unload (PyScript * self)
|
||||
PyFrida_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyScript_terminate (PyScript * self)
|
||||
{
|
||||
GError * error = NULL;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
frida_script_terminate_sync (PY_GOBJECT_HANDLE (self), g_cancellable_get_current (), &error);
|
||||
Py_END_ALLOW_THREADS
|
||||
if (error != NULL)
|
||||
return PyFrida_raise (error);
|
||||
|
||||
PyFrida_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyScript_eternalize (PyScript * self)
|
||||
{
|
||||
|
||||
+32
-1
@@ -309,6 +309,15 @@ class Script:
|
||||
|
||||
self._impl.load()
|
||||
|
||||
@cancellable
|
||||
def interrupt(self) -> None:
|
||||
"""
|
||||
Interrupt any JavaScript currently executing in the script, leaving it
|
||||
loaded and able to run again
|
||||
"""
|
||||
|
||||
self._impl.interrupt()
|
||||
|
||||
@cancellable
|
||||
def unload(self) -> None:
|
||||
"""
|
||||
@@ -317,6 +326,15 @@ class Script:
|
||||
|
||||
self._impl.unload()
|
||||
|
||||
@cancellable
|
||||
def terminate(self) -> None:
|
||||
"""
|
||||
Interrupt execution and unload the script, even if it is stuck in a
|
||||
long-running or infinite operation
|
||||
"""
|
||||
|
||||
self._impl.terminate()
|
||||
|
||||
@cancellable
|
||||
def eternalize(self) -> None:
|
||||
"""
|
||||
@@ -1046,13 +1064,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...db122dd1f0.
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/frida/frida-core.git
|
||||
revision = 17.9.10
|
||||
revision = 17.15.5
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
Reference in new issue
Block a user