parent
a27edc8224
commit
93f94361ed
23
mode/hex.py
23
mode/hex.py
|
@ -13,6 +13,12 @@ class Hex(mode.Fundamental):
|
|||
lmargin = 12
|
||||
rmargin = 18
|
||||
_ctrans = ['.'] * 256
|
||||
byteorder = 'native'
|
||||
byteorders = {
|
||||
'native': '=',
|
||||
'little': '<',
|
||||
'big': '>',
|
||||
}
|
||||
cgreen = color.build('green', 'default', 'bold')
|
||||
ccyan = color.build('cyan', 'default', 'bold')
|
||||
ccursor = color.build('default', 'default', 'bold', 'reverse')
|
||||
|
@ -103,6 +109,8 @@ class Hex(mode.Fundamental):
|
|||
self.add_action_and_bindings(ShowX86Instruction(), ('C-c x',))
|
||||
self.add_action_and_bindings(GotoAddress(), ('C-c M-g',))
|
||||
|
||||
self.add_action(HexSetByteOrder())
|
||||
|
||||
# create all the insert actions for the basic text input
|
||||
for c in string.letters + string.digits + string.punctuation:
|
||||
if c in string.hexdigits:
|
||||
|
@ -152,8 +160,20 @@ class Hex(mode.Fundamental):
|
|||
return s
|
||||
def read_struct(self, cy, ix, fmt, size):
|
||||
s = self.read_data(cy, ix, size)
|
||||
fmt = '%s%s' % (self.byteorders[self.byteorder], fmt)
|
||||
return struct.unpack(fmt, s)[0]
|
||||
|
||||
class HexSetByteOrder(Method):
|
||||
'''Sets the byte-order to use to 'little', 'big', or 'native' order'''
|
||||
args = [Argument("byteorder", type=type(''), prompt="Byte order: ")]
|
||||
def _execute(self, w, **vargs):
|
||||
order = vargs['byteorder']
|
||||
if order in w.mode.byteorders:
|
||||
w.mode.byteorder = order
|
||||
w.set_error("byte-order set to %r" % w.mode.byteorder)
|
||||
else:
|
||||
w.set_error("invalid ordering %r (use 'little', 'big', or 'native'")
|
||||
|
||||
class HexForward(Method):
|
||||
def _execute(self, w, **vargs):
|
||||
w.forward()
|
||||
|
@ -212,7 +232,8 @@ class HexRead(Method):
|
|||
if v is None:
|
||||
w.set_error("not enough data to read %s" % self.type_)
|
||||
else:
|
||||
w.set_error("%s at 0x%08x: %r" % (self.type_, addr, v))
|
||||
end = '%s-endian' % w.mode.byteorder
|
||||
w.set_error("%s %s at 0x%08x: %r" % (end, self.type_, addr, v))
|
||||
except Exception, e:
|
||||
w.set_error("%s could not be read at 0x%08x" % (self.type_, addr))
|
||||
class HexReadAligned(HexRead):
|
||||
|
|
Loading…
Reference in New Issue