diff --git a/application.py b/application.py index dc86f8b..eb7d60d 100755 --- a/application.py +++ b/application.py @@ -280,7 +280,7 @@ class Application(object): if cipher is None: if not os.path.exists(path) or os.path.isfile(path): if binary: - b = buffer2.BinaryBuffer(path, name=name) + b = buffer2.Binary32Buffer(path, name=name) else: b = buffer2.FileBuffer(path, name=name) elif os.path.isdir(path): @@ -795,7 +795,7 @@ def open_aes_file(path, nl, name=None): def open_plain_file(path, nl, name=None, binary=False): if os.path.isfile(path) or not os.path.exists(path): if binary: - return buffer2.BinaryBuffer(path, nl, name) + return buffer2.Binary32Buffer(path, nl, name) else: return buffer2.FileBuffer(path, nl, name) elif os.path.isdir(path): diff --git a/buffer2.py b/buffer2.py index 2c575da..1f90460 100644 --- a/buffer2.py +++ b/buffer2.py @@ -484,27 +484,28 @@ class AesBuffer(FileBuffer): def write_filter(self, data): return aes.encrypt_data(data, self.password) -class BinaryBuffer(FileBuffer): - btype = 'binfile' - def __init__(self, path, nl='\n', name=None, numbytes=2): +class Binary32Buffer(FileBuffer): + btype = 'bin32file' + wordsize = 4 + numwords = 4 + def __init__(self, path, nl='\n', name=None): '''fb = FileBuffer(path)''' FileBuffer.__init__(self, path, nl, name) - self.numbytes = numbytes def read_filter(self, data): lines = [] i = 0 while i < len(data): j = 0 words = [] - while j < self.numbytes * 8 and i + j < len(data): + while j < self.numwords * self.wordsize and i + j < len(data): nibbles = [] - for c in data[i + j:i + j + 8]: + for c in data[i + j:i + j + self.wordsize]: nibbles.append(string.hexdigits[ord(c) / 16]) nibbles.append(string.hexdigits[ord(c) % 16]) words.append(''.join(nibbles)) - j += 8 + j += self.wordsize lines.append(' '.join(words)) - i += self.numbytes * 8 + i += self.numwords * self.wordsize return '\n'.join(lines) def write_filter(self, data): bytes = [] diff --git a/method.py b/method.py index 1a58f0d..b1e99bc 100644 --- a/method.py +++ b/method.py @@ -34,7 +34,7 @@ class Argument: def coerce_to_type(self, value): if self.type == type(0): try: - return int(value) + return int(value, 0) except: raise Exception, "expected int; got %s" % (repr(value)) else: diff --git a/mode/hex.py b/mode/hex.py index 9448c14..a087e4f 100644 --- a/mode/hex.py +++ b/mode/hex.py @@ -1,11 +1,12 @@ import string import color, mode2 from lex3 import Grammar, PatternRule, RegionRule +from method import Method, Argument +from point2 import Point class HexGrammar(Grammar): rules = [ PatternRule(r'zero', r"00"), - PatternRule(r'printable', r"[2-7][0-9a-f]"), PatternRule(r'byte', r'[0-f][0-f]'), ] @@ -13,12 +14,13 @@ class Hex(mode2.Fundamental): grammar = HexGrammar colors = { 'zero': ('magenta', 'default'), - 'printable': ('green', 'default'), 'byte': ('white', 'default'), } def __init__(self, w): mode2.Fundamental.__init__(self, w) + self.add_action_and_bindings(GotoWord(), ('M-g',)) + # create all the insert actions for the basic text input for c in string.letters + string.digits + string.punctuation: if c in string.hexdigits: @@ -28,3 +30,16 @@ class Hex(mode2.Fundamental): def name(self): return "Hex" + +class GotoWord(Method): + '''Jump to the specified line number''' + args = [Argument("wordno", type=type(0), prompt="Goto word: ")] + def _execute(self, w, **vargs): + n = vargs["wordno"] + if n < 0: + w.set_error("Negative word counts not supported.") + try: + p = Point((n % 4) * 9, n / 4) + w.goto(p) + except: + w.goto_end()