From f2fa697b15eb318340782466f766c8825c4a9275 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Mon, 23 Sep 2024 15:19:34 +0200 Subject: [PATCH] Wire up some more --- agents/tracer/agent.ts | 8 ++-- apps/tracer/src/App.tsx | 26 ++++++++++--- apps/tracer/src/DisassemblyView.tsx | 36 ++++++++++++++---- apps/tracer/src/EventView.css | 43 +++++++++++++++++++--- apps/tracer/src/EventView.tsx | 57 +++++++++++++++++++++++++---- apps/tracer/src/model.ts | 10 ++++- frida_tools/tracer.py | 10 ++--- 7 files changed, 154 insertions(+), 36 deletions(-) diff --git a/agents/tracer/agent.ts b/agents/tracer/agent.ts index b17d589..bfea6d1 100644 --- a/agents/tracer/agent.ts +++ b/agents/tracer/agent.ts @@ -450,9 +450,10 @@ class Agent { const timestamp = Date.now() - this.started; const threadId = context.threadId; const depth = this.updateDepth(threadId, cutPoint); + const caller = context.returnAddress.toString(); const log = (...message: string[]) => { - this.emit([id, timestamp, threadId, depth, message.join(" ")]); + this.emit([id, timestamp, threadId, depth, caller, message.join(" ")]); }; callback.call(context, log, param, this.traceState); @@ -464,7 +465,7 @@ class Agent { const depth = this.updateDepth(threadId, cutPoint); const log = (...message: string[]) => { - this.emit([id, timestamp, threadId, depth, message.join(" ")]); + this.emit([id, timestamp, threadId, depth, null, message.join(" ")]); }; try { @@ -981,10 +982,11 @@ interface HandlerResponse { type HandlerScript = string; type TraceTargetId = number; -type TraceEvent = [TraceTargetId, Timestamp, ThreadId, Depth, Message]; +type TraceEvent = [TraceTargetId, Timestamp, ThreadId, Depth, Caller, Message]; type Timestamp = number; type Depth = number; +type Caller = string | null; type Message = string; type TraceHandler = [TraceEnterHandler, TraceLeaveHandler]; diff --git a/apps/tracer/src/App.tsx b/apps/tracer/src/App.tsx index dc91cf4..7f4d28f 100644 --- a/apps/tracer/src/App.tsx +++ b/apps/tracer/src/App.tsx @@ -1,6 +1,6 @@ import "./App.css"; import AddTargetsDialog from "./AddTargetsDialog.tsx"; -import DisassemblyView from "./DisassemblyView.tsx"; +import DisassemblyView, { type DisassemblyTarget } from "./DisassemblyView.tsx"; import EventView from "./EventView.tsx"; import HandlerEditor from "./HandlerEditor.tsx"; import HandlerList from "./HandlerList.tsx"; @@ -46,7 +46,7 @@ export default function App() { commitItems, } = useModel(); const [selectedTabId, setSelectedTabId] = useState("events"); - const [disassemblyAddress, setDisassemblyAddress] = useState(null); + const [disassemblyTarget, setDisassemblyTarget] = useState(); const connectionError = lostConnection ? { + selectHandler(handlerId); + setHighlightedEventIndex(eventIndex); + }} + onDeactivate={() => { + setHighlightedEventIndex(null); + }} + onDisassemble={address => { + setSelectedTabId("disassembly"); + setDisassemblyTarget({ type: "instruction", address }); + }} /> ); const disassemblyView = ( - + ); return ( @@ -106,10 +116,14 @@ export default function App() { + {isHighlighted ? ( + + + + + + + + + {(caller !== null) ? ( + + + + + + ) : null + } + +
Thread ID0x{threadId.toString(16)} +
Caller{caller} + +
+ +
+ ) : null} ); diff --git a/apps/tracer/src/model.ts b/apps/tracer/src/model.ts index f90e426..f487c59 100644 --- a/apps/tracer/src/model.ts +++ b/apps/tracer/src/model.ts @@ -195,7 +195,15 @@ export type StagedItemId = number; export type ScopeName = string; export type MemberName = string | [string, string]; -export type Event = [targetId: HandlerId, timestamp: number, threadId: number, depth: number, message: string, style: string[]]; +export type Event = [ + targetId: HandlerId, + timestamp: number, + threadId: number, + depth: number, + caller: string | null, + message: string, + style: string[] +]; export interface ProcessDetails { id: number; diff --git a/frida_tools/tracer.py b/frida_tools/tracer.py index d5351c4..a717ebc 100644 --- a/frida_tools/tracer.py +++ b/frida_tools/tracer.py @@ -251,15 +251,15 @@ def on_trace_error(self, message: str) -> None: def on_trace_events(self, raw_events) -> None: events = [ - (target_id, timestamp, thread_id, depth, message, self._get_style(thread_id)) - for target_id, timestamp, thread_id, depth, message in raw_events + (target_id, timestamp, thread_id, depth, caller, message, self._get_style(thread_id)) + for target_id, timestamp, thread_id, depth, caller, message in raw_events ] self._asyncio_loop.call_soon_threadsafe( lambda: self._asyncio_loop.create_task(self._broadcast_trace_events(events)) ) no_attributes = Style.RESET_ALL - for target_id, timestamp, thread_id, depth, message, style in events: + for target_id, timestamp, thread_id, depth, caller, message, style in events: if self._output is not None: self._output.append(message + "\n") elif self._quiet: @@ -615,8 +615,8 @@ def _on_message(self, message, data, ui) -> None: def _try_handle_message(self, mtype, params, data, ui) -> False: if mtype == "events:add": events = [ - (target_id, timestamp, thread_id, depth, message) - for target_id, timestamp, thread_id, depth, message in params["events"] + (target_id, timestamp, thread_id, depth, caller, message) + for target_id, timestamp, thread_id, depth, caller, message in params["events"] ] ui.on_trace_events(events) return True