From 30740ebb5946f8265c82b091ec93302b49219892 Mon Sep 17 00:00:00 2001 From: bootleg Date: Mon, 13 Jul 2015 11:17:15 +0200 Subject: [PATCH] bc command (tracing) fix to handle multiple idb Tracing is globally enabled/disabled for all connected idbs. --- ext_gdb/sync.py | 2 +- ext_ida/SyncPlugin.py | 16 +++++++++++----- ext_ida/dispatcher.py | 15 +++++++++++++-- ext_lldb/sync.py | 2 +- ext_windbg/sync/sync.cpp | 2 +- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/ext_gdb/sync.py b/ext_gdb/sync.py index a50ae9e..0bd42da 100644 --- a/ext_gdb/sync.py +++ b/ext_gdb/sync.py @@ -497,7 +497,7 @@ def invoke(self, arg, from_tty): print("[sync] usage: bc <|on|off>") return - self.sync.tunnel.send("[sync]{\"type\":\"bc\",\"msg\":\"%s\",\"base\":%d,\"offset\":%d}\n" % + self.sync.tunnel.send("[notice]{\"type\":\"bc\",\"msg\":\"%s\",\"base\":%d,\"offset\":%d}\n" % (arg, self.sync.base, self.sync.offset)) diff --git a/ext_ida/SyncPlugin.py b/ext_ida/SyncPlugin.py index 736ab96..517a36f 100644 --- a/ext_ida/SyncPlugin.py +++ b/ext_ida/SyncPlugin.py @@ -374,9 +374,13 @@ def req_lbl(self, hash): def req_bc(self, hash): global COL_CBTRACE msg, offset, base = hash['msg'], hash['offset'], hash['base'] - ea = self.rebase(base, offset) - if not ea: - return + + if self.is_active: + ea = self.rebase(base, offset) + if not ea: + return + else: + ea = self.base if (msg == 'oneshot'): print ("[*] color oneshot added at 0x%x" % ea) @@ -542,13 +546,15 @@ def parse_exec(self, req): return req_handler = self.req_handlers[type] - if type in ['broker', 'dialect']: + + # few requests are handled even though idb is not enable + if type in ['broker', 'dialect', 'bc']: req_handler(hash) else: if self.is_active: req_handler(hash) else: - # idb is not enabled, silently drop the request + # otherwise, silently drop the request if idb is not enabled return idaapi.refresh_idaview_anyway() diff --git a/ext_ida/dispatcher.py b/ext_ida/dispatcher.py index 1265bdc..f14c37f 100644 --- a/ext_ida/dispatcher.py +++ b/ext_ida/dispatcher.py @@ -1,5 +1,5 @@ # -# Copyright (C) 2012-2015, Quarkslab. +# Copyright (C) 2012-2014, Quarkslab. # # This file is part of qb-sync. # @@ -91,6 +91,7 @@ def __init__(self): 'module': self.req_module, 'sync_mode': self.req_sync_mode, 'cmd': self.req_cmd, + 'bc': self.req_bc, 'kill': self.req_kill } @@ -223,7 +224,7 @@ def broadcast(self, msg): for idbc in self.idb_clients: self.announcement(msg, idbc.client_sock) - # send message to currently active idb client + # send dbg message to currently active idb client def forward(self, msg, s=None): if not s: if not self.current_idb: @@ -233,6 +234,11 @@ def forward(self, msg, s=None): if s: s.sendall(msg + "\n") + # send dbg message to all idb clients + def forward_all(self, msg, s=None): + for idbc in self.idb_clients: + self.forward(msg, idbc.client_sock) + # disable current idb and enable new idb matched from current module name def switch_idb(self, new_idb): msg = "[sync]{\"type\":\"broker\",\"subtype\":\"%s\"}\n" @@ -400,6 +406,11 @@ def req_sync_mode(self, s, hash): self.broadcast("sync mode auto set to %s" % mode) self.sync_mode_auto = (mode == "on") + # bc request should be forwarded to all idbs + def req_bc(self, s, hash): + msg = "[sync]%s" % json.dumps(hash) + self.forward_all(msg) + def req_cmd(self, s, hash): cmd = hash['cmd'] self.current_dbg.client_sock.sendall("%s\n" % cmd) diff --git a/ext_lldb/sync.py b/ext_lldb/sync.py index 3450c8f..e82eb8b 100644 --- a/ext_lldb/sync.py +++ b/ext_lldb/sync.py @@ -330,7 +330,7 @@ def bc(debugger, command, result, session): pinfo = sc.procinfo() if not pinfo: return - sc.cmd(CMD_SYNC, "bc", msg=arg, base=pinfo["base"], offset=pinfo["offset"]) + sc.cmd(CMD_NOTICE, "bc", msg=arg, base=pinfo["base"], offset=pinfo["offset"]) def addcmt(typ, debugger, command, result, session): diff --git a/ext_windbg/sync/sync.cpp b/ext_windbg/sync/sync.cpp index 8a5987e..7a3fd96 100644 --- a/ext_windbg/sync/sync.cpp +++ b/ext_windbg/sync/sync.cpp @@ -966,7 +966,7 @@ bc(PDEBUG_CLIENT4 Client, PCSTR Args) return E_FAIL; } - hRes = TunnelSend("[sync]{\"type\":\"bc\",\"msg\":\"%s\",\"base\":%llu,\"offset\":%llu}\n", msg, g_Base, g_Offset); + hRes = TunnelSend("[notice]{\"type\":\"bc\",\"msg\":\"%s\",\"base\":%llu,\"offset\":%llu}\n", msg, g_Base, g_Offset); return hRes; }