From 7b69911f0b914971aaa604d5c75b09bfc53dde2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 15 Oct 2024 13:38:03 +0200 Subject: [PATCH] tracer: Auto-migrate old-style handlers --- frida_tools/tracer.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frida_tools/tracer.py b/frida_tools/tracer.py index 2844510..48f5618 100644 --- a/frida_tools/tracer.py +++ b/frida_tools/tracer.py @@ -1139,8 +1139,23 @@ def ensure_handler(self, target: TraceTarget) -> str: def _load_handler(self, file: Path) -> None: handler = file.read_text(encoding="utf-8") + if "defineHandler" not in handler: + handler = self._migrate_handler(handler) + file.write_text(handler, encoding="utf-8") return handler + @staticmethod + def _migrate_handler(handler: str) -> str: + try: + start = handler.index("{") + end = handler.rindex("}") + except ValueError: + return handler + preamble = handler[:start] + definition = handler[start : end + 1] + postamble = handler[end + 1 :] + return "".join([preamble, "defineHandler(", definition, ");", postamble]) + def update_handler(self, target: TraceTarget, handler: str) -> None: _, _, handler_file = self._handler_by_id.get(target.identifier) entry = (target, handler, handler_file)