fixed hex-mode bug and added symbolic editing
--HG-- branch : pmacs2
This commit is contained in:
parent
9b6659c7b9
commit
298d011154
|
@ -568,7 +568,7 @@ class Binary32Buffer(FileBuffer):
|
||||||
groupsize = (((2 + self.bytepad) * self.groupsize) + self.grouppad)
|
groupsize = (((2 + self.bytepad) * self.groupsize) + self.grouppad)
|
||||||
maxsize = groupsize * self.numgroups - self.grouppad
|
maxsize = groupsize * self.numgroups - self.grouppad
|
||||||
if ix < maxsize:
|
if ix < maxsize:
|
||||||
return (ix // self.groupsize) * self.grouppad + ix * (2 + self.bytepad)
|
return (ix // self.groupsize) * (self.grouppad - 1) + ix * (2 + self.bytepad)
|
||||||
else:
|
else:
|
||||||
return None
|
return None
|
||||||
def datax_to_cursory(self, ix):
|
def datax_to_cursory(self, ix):
|
||||||
|
|
51
mode/hex.py
51
mode/hex.py
|
@ -99,11 +99,53 @@ class HexOverwriteChar(Method):
|
||||||
self.args = []
|
self.args = []
|
||||||
self.help = "Overwrite %r into the current hex buffer." % c
|
self.help = "Overwrite %r into the current hex buffer." % c
|
||||||
self.char = c
|
self.char = c
|
||||||
|
self.part1, self.part2 = '%02x' % ord(self.char)
|
||||||
def _execute(self, w, **vargs):
|
def _execute(self, w, **vargs):
|
||||||
|
if w.mode.symbolic_edit:
|
||||||
|
b = w.buffer
|
||||||
|
hb = w.application.methods['hex-backward']
|
||||||
|
(cx, cy) = w.cursor.xy()
|
||||||
|
ix = b.cursorx_to_datax(cy, cx)
|
||||||
|
cx2 = w.buffer.datax_to_cursorx(ix)
|
||||||
|
w.goto(Point(cx2, cy))
|
||||||
|
w.overwrite_char_at_cursor(self.part1)
|
||||||
|
w.overwrite_char_at_cursor(self.part2)
|
||||||
|
elif self.char not in string.hexdigits:
|
||||||
|
return
|
||||||
|
else:
|
||||||
w.overwrite_char_at_cursor(self.char)
|
w.overwrite_char_at_cursor(self.char)
|
||||||
end = w.buffer.get_buffer_end()
|
end = w.buffer.get_buffer_end()
|
||||||
while w.cursor_char().isspace() and w.cursor < end:
|
while w.cursor_char().isspace() and w.cursor < end:
|
||||||
w.forward()
|
w.forward()
|
||||||
|
class HexOverwriteSpace(HexOverwriteChar):
|
||||||
|
def __init__(self):
|
||||||
|
self.name = 'hex-overwrite-space'
|
||||||
|
self.args = []
|
||||||
|
self.help = "Overwrite SPACE into the current hex buffer."
|
||||||
|
self.char = ' '
|
||||||
|
self.part1, self.part2 = '%02x' % ord(self.char)
|
||||||
|
class HexOverwriteTab(HexOverwriteChar):
|
||||||
|
def __init__(self):
|
||||||
|
self.name = 'hex-overwrite-tab'
|
||||||
|
self.args = []
|
||||||
|
self.help = "Overwrite TAB into the current hex buffer."
|
||||||
|
self.char = '\t'
|
||||||
|
self.part1, self.part2 = '%02x' % ord(self.char)
|
||||||
|
class HexOverwriteNewline(HexOverwriteChar):
|
||||||
|
def __init__(self):
|
||||||
|
self.name = 'hex-overwrite-newline'
|
||||||
|
self.args = []
|
||||||
|
self.help = "Overwrite NEWLINE into the current hex buffer."
|
||||||
|
self.char = '\n'
|
||||||
|
self.part1, self.part2 = '%02x' % ord(self.char)
|
||||||
|
|
||||||
|
class HexToggleSymbolic(Method):
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
w.mode.symbolic_edit = not w.mode.symbolic_edit
|
||||||
|
if w.mode.symbolic_edit:
|
||||||
|
w.set_error("Symbolic editing enabled")
|
||||||
|
else:
|
||||||
|
w.set_error("Symbolic editing disabled")
|
||||||
|
|
||||||
class ShowX86Instruction(Method):
|
class ShowX86Instruction(Method):
|
||||||
''''''
|
''''''
|
||||||
|
@ -170,7 +212,8 @@ class Hex(mode.Fundamental):
|
||||||
ctrans = ''.join(_ctrans)
|
ctrans = ''.join(_ctrans)
|
||||||
actions = [HexForward, HexBackward, HexForwardWord, HexBackwardWord,
|
actions = [HexForward, HexBackward, HexForwardWord, HexBackwardWord,
|
||||||
HexStartOfLine, HexEndOfLine, ShowAddress, ShowX86Instruction,
|
HexStartOfLine, HexEndOfLine, ShowAddress, ShowX86Instruction,
|
||||||
GotoAddress, HexSetByteOrder]
|
GotoAddress, HexSetByteOrder, HexToggleSymbolic,
|
||||||
|
HexOverwriteSpace, HexOverwriteTab, HexOverwriteNewline]
|
||||||
def __init__(self, w):
|
def __init__(self, w):
|
||||||
mode.Fundamental.__init__(self, w)
|
mode.Fundamental.__init__(self, w)
|
||||||
self.bindings = {}
|
self.bindings = {}
|
||||||
|
@ -257,8 +300,12 @@ class Hex(mode.Fundamental):
|
||||||
|
|
||||||
# create all the insert actions for the basic text input
|
# create all the insert actions for the basic text input
|
||||||
for c in string.letters + string.digits + string.punctuation:
|
for c in string.letters + string.digits + string.punctuation:
|
||||||
if c in string.hexdigits:
|
|
||||||
self.add_action_and_bindings(HexOverwriteChar(c), (c,))
|
self.add_action_and_bindings(HexOverwriteChar(c), (c,))
|
||||||
|
self.add_bindings('hex-overwrite-space', ('SPACE',))
|
||||||
|
self.add_bindings('hex-overwrite-tab', ('TAB',))
|
||||||
|
self.add_bindings('hex-overwrite-newline', ('RETURN',))
|
||||||
|
|
||||||
|
self.symbolic_edit = False
|
||||||
|
|
||||||
def get_address(self, y, x):
|
def get_address(self, y, x):
|
||||||
return (y * 16) + x
|
return (y * 16) + x
|
||||||
|
|
Loading…
Reference in New Issue