Skip to content

Commit

Permalink
bc command (tracing) fix to handle multiple idb
Browse files Browse the repository at this point in the history
Tracing is globally enabled/disabled for all connected idbs.
  • Loading branch information
bootleg committed Jul 13, 2015
1 parent 0b11e67 commit 30740eb
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion ext_gdb/sync.py
Expand Up @@ -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))


Expand Down
16 changes: 11 additions & 5 deletions ext_ida/SyncPlugin.py
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
15 changes: 13 additions & 2 deletions 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.
#
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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:
Expand All @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ext_lldb/sync.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion ext_windbg/sync/sync.cpp
Expand Up @@ -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;
}

Expand Down

0 comments on commit 30740eb

Please sign in to comment.