freemyipod r578 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r577‎ | r578 | r579 >
Date:17:23, 9 February 2011
Author:theseven
Status:new
Tags:
Comment:
emcore.py: Make hexdump even more flexible
Modified paths:
  • /emcore/trunk/tools/emcore.py (modified) (history)

Diff [purge]

Index: emcore/trunk/tools/emcore.py
@@ -256,8 +256,8 @@
257257 self.logger.info("done\n")
258258
259259 @command
260 - def hexdump(self, addr, size, width = 16, wordsize = 1, separate = 4, \
261 - align = False, relative = False, ascii = True, asciisep = 8):
 260+ def hexdump(self, addr, size, width = 16, wordsize = 1, separate = 4, align = False, \
 261+ relative = False, ascii = True, asciisep = 8, asciirep = ".", zeropad = True):
262262 """
263263 Downloads a region of memory from the device and hexdumps it
264264 <addr>: the address to download the data from
@@ -269,6 +269,8 @@
270270 [relative]: if true, the addresses displayed are relative to the <addr>, not zero
271271 [ascii]: add ASCII representations of the bytes to the output
272272 [asciisep]: add an additional space character every [asciisep] ASCII characters
 273+ [asciirep]: replacement character for non-printable ASCII characters
 274+ [zeropad]: pad hex values with zero instead of space characters
273275 """
274276 addr = to_int(addr)
275277 size = to_int(size)
@@ -279,6 +281,7 @@
280282 relative = to_bool(relative)
281283 ascii = to_bool(ascii)
282284 asciisep = to_int(asciisep)
 285+ zeropad = to_bool(zeropad)
283286 if addr % wordsize != 0: raise ArgumentError("Address is not word aligned!")
284287 if size % wordsize != 0: raise ArgumentError("Size is not word aligned!")
285288 if align: skip = addr % (wordsize * width)
@@ -294,7 +297,7 @@
295298 w = 0
296299 for b in range(wordsize):
297300 w = w | (struct.unpack("B", data[i + b])[0] << (8 * b))
298 - sys.stdout.write((" %%0%dX" % (wordsize * 2)) % w)
 301+ sys.stdout.write(((" %%0%dX" if zeropad else " %%%dX") % (wordsize * 2)) % w)
299302 else: sys.stdout.write(" " * (wordsize * 2 + 1))
300303 if ascii:
301304 sys.stdout.write(" |")
@@ -302,7 +305,7 @@
303306 if i - r > 0 and (i - r) % asciisep == 0: sys.stdout.write(" ")
304307 if i >= 0 and i < size:
305308 if ord(data[i]) > 0x1f: sys.stdout.write(data[i])
306 - else: sys.stdout.write(".")
 309+ else: sys.stdout.write(asciirep)
307310 else: sys.stdout.write(" ")
308311 sys.stdout.write("|")
309312 sys.stdout.write("\n")