Miasm2
 All Classes Namespaces Files Functions Variables Typedefs Properties Macros
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
miasm2.analysis.debugging.DebugCmd Class Reference
+ Inheritance diagram for miasm2.analysis.debugging.DebugCmd:
+ Collaboration diagram for miasm2.analysis.debugging.DebugCmd:

Public Member Functions

def __init__
 
def print_breakpoints
 
def print_watchmems
 
def print_registers
 
def add_breakpoints
 
def update_display_mode
 
def print_warning
 
def onecmd
 
def can_exit
 
def do_display
 
def help_display
 
def do_watchmem
 
def help_watchmem
 
def do_info
 
def help_info
 
def do_breakpoint
 
def help_breakpoint
 
def do_step
 
def help_step
 
def do_dump
 
def help_dump
 
def do_run
 
def help_run
 
def do_exit
 
def do_exec
 
def help_exec
 
def help_exit
 
def help_help
 
def postloop
 

Public Attributes

 dbg
 
 display_mode
 

Static Public Attributes

string color_g = '\033[92m'
 
string color_e = '\033[0m'
 
string color_b = '\033[94m'
 
string color_r = '\033[91m'
 
string intro = color_g+"=== Miasm2 Debugging shell ===\nIf you need help, "
 
string prompt = color_b+"$> "
 
dictionary display_mode
 
 do_EOF = do_exit
 
 help_EOF = help_exit
 

Detailed Description

Definition at line 218 of file debugging.py.

Constructor & Destructor Documentation

def miasm2.analysis.debugging.DebugCmd.__init__ (   self,
  dbg 
)

Definition at line 231 of file debugging.py.

232  def __init__(self, dbg):
233  "dbg : Debugguer"
234  self.dbg = dbg
235  super(DebugCmd, self).__init__()

Member Function Documentation

def miasm2.analysis.debugging.DebugCmd.add_breakpoints (   self,
  bp_addr 
)

Definition at line 274 of file debugging.py.

275  def add_breakpoints(self, bp_addr):
276  for addr in bp_addr:
277  addr = int(addr, 0)
278 
279  good = True
280  for i, dbg_obj in enumerate(self.dbg.bp_list):
281  if dbg_obj.addr == addr:
282  good = False
283  break
284  if good is False:
285  print "Breakpoint 0x%08x already set (%d)" % (addr, i)
286  else:
287  l = len(self.dbg.bp_list)
288  self.dbg.add_breakpoint(addr)
289  print "Breakpoint 0x%08x successfully added ! (%d)" % (addr, l)

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.can_exit (   self)

Definition at line 325 of file debugging.py.

326  def can_exit(self):
327  return True
def miasm2.analysis.debugging.DebugCmd.do_breakpoint (   self,
  arg 
)

Definition at line 407 of file debugging.py.

408  def do_breakpoint(self, arg):
409  if arg == "":
410  self.help_breakpoint()
411  else:
412  addrs = arg.split(" ")
413  self.add_breakpoints(addrs)

+ Here is the call graph for this function:

def miasm2.analysis.debugging.DebugCmd.do_display (   self,
  arg 
)

Definition at line 328 of file debugging.py.

329  def do_display(self, arg):
330  if arg == "":
331  self.help_display()
332  return
333 
334  args = arg.split(" ")
335  if args[-1].lower() not in ["on", "off"]:
336  self.print_warning("/!\ %s not in 'on' / 'off'" % args[-1])
337  return
338  mode = args[-1].lower() == "on"
339  d = {}
340  for a in args[:-1]:
341  d[a] = mode
342  self.dbg.active_trace(**d)
343  self.update_display_mode()

+ Here is the call graph for this function:

def miasm2.analysis.debugging.DebugCmd.do_dump (   self,
  arg 
)

Definition at line 433 of file debugging.py.

434  def do_dump(self, arg):
435  if arg == "":
436  self.help_dump()
437  else:
438  args = arg.split(" ")
439  if len(args) >= 2:
440  size = int(args[1], 0)
441  else:
442  size = 0xF
443  addr = int(args[0], 0)
444 
445  self.dbg.get_mem(addr, size)

+ Here is the call graph for this function:

def miasm2.analysis.debugging.DebugCmd.do_exec (   self,
  line 
)

Definition at line 458 of file debugging.py.

459  def do_exec(self, line):
460  try:
461  print eval(line)
462  except Exception, error:
463  print "*** Error: %s" % error
def miasm2.analysis.debugging.DebugCmd.do_exit (   self,
  _ 
)

Definition at line 455 of file debugging.py.

456  def do_exit(self, _):
457  return True
def miasm2.analysis.debugging.DebugCmd.do_info (   self,
  arg 
)

Definition at line 372 of file debugging.py.

373  def do_info(self, arg):
374  av_info = ["registers",
375  "display",
376  "breakpoints",
377  "watchmem"]
378 
379  if arg == "":
380  print "'info' must be followed by the name of an info command."
381  print "List of info subcommands:"
382  for k in av_info:
383  print "\t%s" % k
384 
385  if arg.startswith("b"):
386  # Breakpoint
387  self.print_breakpoints()
388 
389  if arg.startswith("d"):
390  # Display
391  self.update_display_mode()
392  for k, v in self.display_mode.items():
393  print "%s\t\t%s" % (k, v)
394 
395  if arg.startswith("w"):
396  # Watchmem
397  self.print_watchmems()
398 
399  if arg.startswith("r"):
400  # Registers
401  self.print_registers()

+ Here is the call graph for this function:

def miasm2.analysis.debugging.DebugCmd.do_run (   self,
  _ 
)

Definition at line 449 of file debugging.py.

450  def do_run(self, _):
451  self.dbg.run()
def miasm2.analysis.debugging.DebugCmd.do_step (   self,
  arg 
)

Definition at line 420 of file debugging.py.

421  def do_step(self, arg):
422  if arg == "":
423  nb = 1
424  else:
425  nb = int(arg)
426  for _ in xrange(nb):
427  self.dbg.step()
def miasm2.analysis.debugging.DebugCmd.do_watchmem (   self,
  arg 
)

Definition at line 352 of file debugging.py.

353  def do_watchmem(self, arg):
354  if arg == "":
355  self.help_watchmem()
356  return
357 
358  args = arg.split(" ")
359  if len(args) >= 2:
360  size = int(args[1], 0)
361  else:
362  size = 0xF
363 
364  addr = int(args[0], 0)
365 
366  self.dbg.watch_mem(addr, size)

+ Here is the call graph for this function:

def miasm2.analysis.debugging.DebugCmd.help_breakpoint (   self)

Definition at line 414 of file debugging.py.

415  def help_breakpoint(self):
416  print "Add breakpoints to argument addresses."
417  print "Example:"
418  print "\tbreakpoint 0x11223344"
419  print "\tbreakpoint 1122 0xabcd"

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.help_display (   self)

Definition at line 344 of file debugging.py.

345  def help_display(self):
346  print "Enable/Disable tracing."
347  print "Usage: display <mode1> <mode2> ... on|off"
348  print "Available modes are:"
349  for k in self.display_mode:
350  print "\t%s" % k
351  print "Use 'info display' to get current values"

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.help_dump (   self)

Definition at line 446 of file debugging.py.

447  def help_dump(self):
448  print "Dump <addr> [size]. Dump size bytes at addr."

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.help_exec (   self)

Definition at line 464 of file debugging.py.

465  def help_exec(self):
466  print "Exec a python command."
467  print "You can also use '!' shortcut."
def miasm2.analysis.debugging.DebugCmd.help_exit (   self)

Definition at line 468 of file debugging.py.

469  def help_exit(self):
470  print "Exit the interpreter."
471  print "You can also use the Ctrl-D shortcut."
def miasm2.analysis.debugging.DebugCmd.help_help (   self)

Definition at line 472 of file debugging.py.

473  def help_help(self):
474  print "Print help"
def miasm2.analysis.debugging.DebugCmd.help_info (   self)

Definition at line 402 of file debugging.py.

403  def help_info(self):
404  print "Generic command for showing things about the program being"
405  print "debugged. Use 'info' without arguments to get the list of"
406  print "available subcommands."
def miasm2.analysis.debugging.DebugCmd.help_run (   self)

Definition at line 452 of file debugging.py.

453  def help_run(self):
454  print "Launch or continue the current program"
def miasm2.analysis.debugging.DebugCmd.help_step (   self)

Definition at line 428 of file debugging.py.

429  def help_step(self):
430  print "Step program until it reaches a different source line."
431  print "Argument N means do this N times (or till program stops"
432  print "for another reason)."
def miasm2.analysis.debugging.DebugCmd.help_watchmem (   self)

Definition at line 367 of file debugging.py.

368  def help_watchmem(self):
369  print "Add a memory watcher."
370  print "Usage: watchmem <addr> [size]"
371  print "Use 'info watchmem' to get current memory watchers"

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.onecmd (   self,
  line 
)

Definition at line 303 of file debugging.py.

304  def onecmd(self, line):
305  cmd_translate = {"h": "help",
306  "q": "exit",
307  "e": "exit",
308  "!": "exec",
309  "r": "run",
310  "i": "info",
311  "b": "breakpoint",
312  "s": "step",
313  "d": "dump"}
314 
315  if len(line) >= 2 and \
316  line[1] == " " and \
317  line[:1] in cmd_translate:
318  line = cmd_translate[line[:1]] + line[1:]
319 
320  if len(line) == 1 and line in cmd_translate:
321  line = cmd_translate[line]
322 
323  r = super(DebugCmd, self).onecmd(line)
324  return r
def miasm2.analysis.debugging.DebugCmd.postloop (   self)

Definition at line 475 of file debugging.py.

476  def postloop(self):
477  print '\nGoodbye !'
478  super(DebugCmd, self).postloop()
def miasm2.analysis.debugging.DebugCmd.print_breakpoints (   self)

Definition at line 238 of file debugging.py.

239  def print_breakpoints(self):
240  bp_list = self.dbg.bp_list
241  if len(bp_list) == 0:
242  print "No breakpoints."
243  else:
244  for i, b in enumerate(bp_list):
245  print "%d\t0x%08x" % (i, b.addr)

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.print_registers (   self)

Definition at line 256 of file debugging.py.

257  def print_registers(self):
258  regs = self.dbg.get_gpreg_all()
259 
260  # Display settings
261  title1 = "Registers"
262  title2 = "Values"
263  max_name_len = max(map(len, regs.keys() + [title1]))
264 
265  # Print value table
266  s = "%s%s | %s" % (
267  title1, " " * (max_name_len - len(title1)), title2)
268  print s
269  print "-" * len(s)
270  for name, value in sorted(regs.items(), key=lambda x: x[0]):
271  print "%s%s | %s" % (name,
272  " " * (max_name_len - len(name)),
273  hex(value).replace("L", ""))

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.print_warning (   self,
  s 
)

Definition at line 300 of file debugging.py.

301  def print_warning(self, s):
302  print self.color_r + s + self.color_e

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.print_watchmems (   self)

Definition at line 246 of file debugging.py.

247  def print_watchmems(self):
248  watch_list = self.dbg.mem_watched
249  if len(watch_list) == 0:
250  print "No memory watchpoints."
251  else:
252  print "Num\tAddress \tSize"
253  for i, w in enumerate(watch_list):
254  addr, size = w
255  print "%d\t0x%08x\t0x%08x" % (i, addr, size)

+ Here is the caller graph for this function:

def miasm2.analysis.debugging.DebugCmd.update_display_mode (   self)

Definition at line 294 of file debugging.py.

296  self.display_mode = {"mn": self.dbg.myjit.jit.log_mn,
297  "regs": self.dbg.myjit.jit.log_regs,
298  "newbloc": self.dbg.myjit.jit.log_newbloc}

+ Here is the caller graph for this function:

Member Data Documentation

string miasm2.analysis.debugging.DebugCmd.color_b = '\033[94m'
static

Definition at line 224 of file debugging.py.

string miasm2.analysis.debugging.DebugCmd.color_e = '\033[0m'
static

Definition at line 223 of file debugging.py.

string miasm2.analysis.debugging.DebugCmd.color_g = '\033[92m'
static

Definition at line 222 of file debugging.py.

string miasm2.analysis.debugging.DebugCmd.color_r = '\033[91m'
static

Definition at line 225 of file debugging.py.

miasm2.analysis.debugging.DebugCmd.dbg

Definition at line 233 of file debugging.py.

dictionary miasm2.analysis.debugging.DebugCmd.display_mode
static
Initial value:
1 = {"mn": None,
2  "regs": None,
3  "newbloc": None}

Definition at line 290 of file debugging.py.

miasm2.analysis.debugging.DebugCmd.display_mode

Definition at line 295 of file debugging.py.

miasm2.analysis.debugging.DebugCmd.do_EOF = do_exit
static

Definition at line 479 of file debugging.py.

miasm2.analysis.debugging.DebugCmd.help_EOF = help_exit
static

Definition at line 480 of file debugging.py.

string miasm2.analysis.debugging.DebugCmd.intro = color_g+"=== Miasm2 Debugging shell ===\nIf you need help, "
static

Definition at line 227 of file debugging.py.

string miasm2.analysis.debugging.DebugCmd.prompt = color_b+"$> "
static

Definition at line 229 of file debugging.py.


The documentation for this class was generated from the following file: