mirror of
https://github.com/frida/frida-python
synced 2026-06-08 14:16:17 +00:00
Compare commits
62 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fab765f91 | |||
| a6c02cb7ee | |||
| 6033dd0904 | |||
| 77e94e24a1 | |||
| c97343dc83 | |||
| e1ffe5fd50 | |||
| c7314098c6 | |||
| 41d769fa4d | |||
| 044d23eef7 | |||
| 1641af6ca3 | |||
| e513eca572 | |||
| 15260bfa4a | |||
| dec8aca9ae | |||
| 8c69b9d032 | |||
| f57b0c1cfa | |||
| fd2c1f2424 | |||
| a9caf62a0c | |||
| 8bc4415f34 | |||
| e3eca3179c | |||
| ef190d9957 | |||
| 1e06ebe9a3 | |||
| 925378439c | |||
| 7ae323a3cd | |||
| 9c5985c254 | |||
| b469134be4 | |||
| 9933d916ae | |||
| 09cac4e2a5 | |||
| 6b49e14ce1 | |||
| 7711fa12ac | |||
| d468dc038c | |||
| 58ff000596 | |||
| 3652e985d8 | |||
| 210c56e1b2 | |||
| b3d6aa8ffe | |||
| 16eb645844 | |||
| b7b1fcf0ff | |||
| 978b756134 | |||
| 7b1fc43a42 | |||
| 244cf6926b | |||
| 24b941fb8a | |||
| e2b340eda1 | |||
| 2b306c6d30 | |||
| 57cee13b43 | |||
| 23aa442826 | |||
| 65236f3b05 | |||
| e52e7a95bd | |||
| 3b57222cfa | |||
| 319ac9e699 | |||
| 2e842a4e44 | |||
| f9bf571497 | |||
| 8f50f743e1 | |||
| 6da337df6f | |||
| e29d41806c | |||
| 8faf01dc2e | |||
| 4286667bc6 | |||
| 86d4b4b4bf | |||
| b5808d7b27 | |||
| 5466050755 | |||
| 4db854a02c | |||
| cc9a78ef19 | |||
| 22ed1fac3c | |||
| 9b15bde24e |
@@ -42,18 +42,16 @@ class Application:
|
||||
print("✔ enable_child_gating()")
|
||||
session.enable_child_gating()
|
||||
print("✔ create_script()")
|
||||
script = session.create_script(
|
||||
"""\
|
||||
Interceptor.attach(Module.getExportByName(null, 'open'), {
|
||||
onEnter: function (args) {
|
||||
script = session.create_script("""\
|
||||
Interceptor.attach(Module.getGlobalExportByName('open'), {
|
||||
onEnter(args) {
|
||||
send({
|
||||
type: 'open',
|
||||
path: Memory.readUtf8String(args[0])
|
||||
path: args[0].readUtf8String()
|
||||
});
|
||||
}
|
||||
});
|
||||
"""
|
||||
)
|
||||
""")
|
||||
script.on("message", lambda message, data: self._reactor.schedule(lambda: self._on_message(pid, message)))
|
||||
print("✔ load()")
|
||||
script.load()
|
||||
|
||||
@@ -15,7 +15,7 @@ def on_uninjected(id):
|
||||
print("on_uninjected id=%u" % id)
|
||||
|
||||
|
||||
(target, library_path) = sys.argv[1:]
|
||||
target, library_path = sys.argv[1:]
|
||||
|
||||
device = frida.get_local_device()
|
||||
device.on("uninjected", on_uninjected)
|
||||
|
||||
@@ -15,7 +15,7 @@ def on_uninjected(id):
|
||||
print("on_uninjected id=%u" % id)
|
||||
|
||||
|
||||
(target, library_path) = sys.argv[1:]
|
||||
target, library_path = sys.argv[1:]
|
||||
|
||||
device = frida.get_local_device()
|
||||
device.on("uninjected", on_uninjected)
|
||||
|
||||
+2
-4
@@ -1,8 +1,7 @@
|
||||
import frida
|
||||
|
||||
session = frida.attach("Twitter")
|
||||
script = session.create_script(
|
||||
"""\
|
||||
script = session.create_script("""\
|
||||
rpc.exports = {
|
||||
hello: function () {
|
||||
return 'Hello';
|
||||
@@ -11,8 +10,7 @@ rpc.exports = {
|
||||
oops;
|
||||
}
|
||||
};
|
||||
"""
|
||||
)
|
||||
""")
|
||||
script.load()
|
||||
api = script.exports_sync
|
||||
print("api.hello() =>", api.hello())
|
||||
|
||||
@@ -22,8 +22,7 @@ class Application:
|
||||
self._session = session
|
||||
session.on("detached", lambda *args: self._reactor.schedule(lambda: self._on_detached(*args)))
|
||||
|
||||
script = session.create_script(
|
||||
"""
|
||||
script = session.create_script("""
|
||||
let _puts = null;
|
||||
|
||||
Interceptor.attach(DebugSymbol.getFunctionByName('f'), {
|
||||
@@ -48,8 +47,7 @@ function puts(s) {
|
||||
}
|
||||
_puts(Memory.allocUtf8String(s));
|
||||
}
|
||||
"""
|
||||
)
|
||||
""")
|
||||
self._script = script
|
||||
script.on("message", lambda *args: self._reactor.schedule(lambda: self._on_message(*args)))
|
||||
script.load()
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
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)
|
||||
{
|
||||
|
||||
+9
-1
@@ -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]:
|
||||
"""
|
||||
@@ -1310,7 +1318,7 @@ class EndpointParameters:
|
||||
_filter_missing_kwargs(kwargs)
|
||||
|
||||
if authentication is not None:
|
||||
(auth_scheme, auth_data) = authentication
|
||||
auth_scheme, auth_data = authentication
|
||||
if auth_scheme == "token":
|
||||
kwargs["auth_token"] = auth_data
|
||||
elif auth_scheme == "callback":
|
||||
|
||||
+1
-1
Submodule releng updated: 5595d31705...a76acfc2b5
@@ -1,6 +1,6 @@
|
||||
[wrap-git]
|
||||
url = https://github.com/frida/frida-core.git
|
||||
revision = 17.8.3
|
||||
revision = 17.9.7
|
||||
depth = 1
|
||||
|
||||
[provide]
|
||||
|
||||
Reference in New Issue
Block a user