Skip to content

Commit

Permalink
tracer: Auto-migrate old-style handlers
Browse files Browse the repository at this point in the history
  • Loading branch information
oleavr committed Oct 15, 2024
1 parent f30886f commit 7b69911
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions frida_tools/tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 7b69911

Please sign in to comment.