mirror of
https://github.com/frida/frida-python
synced 2026-06-08 14:16:17 +00:00
Compare commits
16 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 86d4b4b4bf | |||
| b5808d7b27 | |||
| 5466050755 | |||
| 4db854a02c | |||
| cc9a78ef19 | |||
| 22ed1fac3c | |||
| 9b15bde24e | |||
| a613d87b08 | |||
| 9ef240eff4 | |||
| 43a443f582 | |||
| dcc95216fd | |||
| 69e7c6c0ce | |||
| 3278173be8 | |||
| d8fa422062 | |||
| 3943d2eed2 | |||
| 8030b5aa68 |
@@ -44,11 +44,11 @@ class Application:
|
||||
print("✔ create_script()")
|
||||
script = session.create_script(
|
||||
"""\
|
||||
Interceptor.attach(Module.getExportByName(null, 'open'), {
|
||||
onEnter: function (args) {
|
||||
Interceptor.attach(Module.getGlobalExportByName('open'), {
|
||||
onEnter(args) {
|
||||
send({
|
||||
type: 'open',
|
||||
path: Memory.readUtf8String(args[0])
|
||||
path: args[0].readUtf8String()
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import threading
|
||||
|
||||
from frida_tools.application import Reactor
|
||||
|
||||
import frida
|
||||
|
||||
|
||||
class Application:
|
||||
def __init__(self):
|
||||
self._stop_requested = threading.Event()
|
||||
self._reactor = Reactor(run_until_return=lambda reactor: self._stop_requested.wait())
|
||||
|
||||
self._device = frida.get_usb_device()
|
||||
self._sessions = set()
|
||||
self._sessions_lock = threading.Lock()
|
||||
|
||||
self._device.on("spawn-added", lambda spawn: self._reactor.schedule(lambda: self._on_spawn_added(spawn)))
|
||||
self._device.on("spawn-removed", lambda spawn: self._reactor.schedule(lambda: self._on_spawn_removed(spawn)))
|
||||
|
||||
def run(self):
|
||||
self._reactor.schedule(lambda: self._start())
|
||||
self._reactor.run()
|
||||
|
||||
def _start(self):
|
||||
self._device.enable_spawn_gating()
|
||||
|
||||
def _instrument(self, pid):
|
||||
print(f"✔ attach(pid={pid})")
|
||||
session = self._device.attach(pid)
|
||||
session.on("detached", lambda reason: self._reactor.schedule(lambda: self._on_detached(pid, session, reason)))
|
||||
print("✔ create_script()")
|
||||
script = session.create_script(
|
||||
"""\
|
||||
const puts = new NativeFunction(Module.getGlobalExportByName('puts'), 'int', ['pointer']);
|
||||
puts(Memory.allocUtf8String('Hello from Frida agent'));
|
||||
Interceptor.attach(Module.getGlobalExportByName('open'), {
|
||||
onEnter(args) {
|
||||
send({
|
||||
type: 'open',
|
||||
path: args[0].readUtf8String()
|
||||
});
|
||||
}
|
||||
});
|
||||
"""
|
||||
)
|
||||
script.on("message", lambda message, data: self._reactor.schedule(lambda: self._on_message(pid, message)))
|
||||
print("✔ load()")
|
||||
script.load()
|
||||
print(f"✔ resume(pid={pid})")
|
||||
self._device.resume(pid)
|
||||
with self._sessions_lock:
|
||||
self._sessions.add(session)
|
||||
|
||||
def _on_spawn_added(self, spawn):
|
||||
print(f"⚡ spawn_added: {spawn}")
|
||||
t = threading.Thread(target=self._handle_spawn, args=(spawn,))
|
||||
t.start()
|
||||
|
||||
def _handle_spawn(self, spawn):
|
||||
if "/bin/ls" in spawn.identifier:
|
||||
self._instrument(spawn.pid)
|
||||
else:
|
||||
pid = spawn.pid
|
||||
print(f"✔ resume(pid={pid})")
|
||||
self._device.resume(pid)
|
||||
|
||||
def _on_spawn_removed(self, spawn):
|
||||
print(f"⚡ spawn_removed: {spawn}")
|
||||
|
||||
def _on_detached(self, pid, session, reason):
|
||||
print(f"⚡ detached: pid={pid}, reason='{reason}'")
|
||||
with self._sessions_lock:
|
||||
self._sessions.remove(session)
|
||||
|
||||
def _on_message(self, pid, message):
|
||||
print(f"⚡ message: pid={pid}, payload={message['payload']}")
|
||||
|
||||
|
||||
app = Application()
|
||||
app.run()
|
||||
@@ -404,6 +404,7 @@ static void PyDevice_init_from_handle (PyDevice * self, FridaDevice * handle);
|
||||
static void PyDevice_dealloc (PyDevice * self);
|
||||
static PyObject * PyDevice_repr (PyDevice * self);
|
||||
static PyObject * PyDevice_is_lost (PyDevice * self);
|
||||
static PyObject * PyDevice_override_option (PyDevice * self, PyObject * args, PyObject * kw);
|
||||
static PyObject * PyDevice_query_system_parameters (PyDevice * self);
|
||||
static PyObject * PyDevice_get_frontmost_application (PyDevice * self, PyObject * args, PyObject * kw);
|
||||
static PyObject * PyDevice_enumerate_applications (PyDevice * self, PyObject * args, PyObject * kw);
|
||||
@@ -620,6 +621,7 @@ static PyMethodDef PyDeviceManager_methods[] =
|
||||
static PyMethodDef PyDevice_methods[] =
|
||||
{
|
||||
{ "is_lost", (PyCFunction) PyDevice_is_lost, METH_NOARGS, "Query whether the device has been lost." },
|
||||
{ "override_option", (PyCFunction) PyDevice_override_option, METH_VARARGS | METH_KEYWORDS, "Override a backend-specific option." },
|
||||
{ "query_system_parameters", (PyCFunction) PyDevice_query_system_parameters, METH_NOARGS, "Returns a dictionary of information about the host system." },
|
||||
{ "get_frontmost_application", (PyCFunction) PyDevice_get_frontmost_application, METH_VARARGS | METH_KEYWORDS, "Get details about the frontmost application." },
|
||||
{ "enumerate_applications", (PyCFunction) PyDevice_enumerate_applications, METH_VARARGS | METH_KEYWORDS, "Enumerate applications." },
|
||||
@@ -2521,6 +2523,33 @@ PyDevice_is_lost (PyDevice * self)
|
||||
return PyBool_FromLong (is_lost);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyDevice_override_option (PyDevice * self, PyObject * args, PyObject * kw)
|
||||
{
|
||||
static char * keywords[] = { "name", "value", NULL };
|
||||
const char * name;
|
||||
PyObject * value;
|
||||
GVariant * raw_value;
|
||||
GError * error = NULL;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords (args, kw, "sO", keywords, &name, &value))
|
||||
return NULL;
|
||||
|
||||
if (!PyGObject_unmarshal_variant (value, &raw_value))
|
||||
return NULL;
|
||||
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
frida_device_override_option (PY_GOBJECT_HANDLE (self), name, raw_value, &error);
|
||||
Py_END_ALLOW_THREADS
|
||||
|
||||
g_variant_unref (raw_value);
|
||||
|
||||
if (error != NULL)
|
||||
return PyFrida_raise (error);
|
||||
|
||||
PyFrida_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PyDevice_query_system_parameters (PyDevice * self)
|
||||
{
|
||||
|
||||
@@ -883,6 +883,14 @@ class Device:
|
||||
|
||||
return self._impl.is_lost()
|
||||
|
||||
@cancellable
|
||||
def override_option(self, name: str, value: Any) -> None:
|
||||
"""
|
||||
Override a backend-specific option
|
||||
"""
|
||||
|
||||
self._impl.override_option(name, value)
|
||||
|
||||
@cancellable
|
||||
def query_system_parameters(self) -> Dict[str, Any]:
|
||||
"""
|
||||
|
||||
+1
-1
Submodule releng updated: 852c527081...5595d31705
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/frida/frida-core.git
|
||||
revision = 17.8.0
|
||||
revision = 17.9.1
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
Reference in New Issue
Block a user