diff --git a/application.py b/application.py index c84ff7e..7c3c93e 100755 --- a/application.py +++ b/application.py @@ -282,7 +282,17 @@ class Application(object): b = buffer.AesBuffer(path, password, name=name) else: raise Exception, "not a file or dir: %r" % path - b.open() + try: + b.open() + except buffer.BinaryDataException: + if binary: + raise + else: + binary = True + b = buffer.Binary32Buffer(path, name=name) + b.open() + if mode_name is None: + mode_name = 'hex' window.Window(b, self, height=0, width=0, mode_name=mode_name) self.add_buffer(b) return b @@ -342,7 +352,12 @@ class Application(object): f.write(data) f.close() b = buffer.FileBuffer(path) - b.open() + try: + b.open() + except buffer.BinaryDataException: + b = buffer.Binary32Buffer(path) + b.open() + b.modename = 'hex' window.Window(b, self, height=0, width=0) self.add_buffer(b) if switch_to: @@ -902,6 +917,10 @@ if __name__ == "__main__": if opts.debug: mode.DEBUG = True + # if -b but no -m, then use -m hex + if opts.binary and not opts.mode: + opts.mode = 'hex' + # we will support using +19 as the first argument to indicate opening the # first file on line 19 (same as -g 19 or --goto 19) if goto_line: @@ -941,6 +960,8 @@ if __name__ == "__main__": b = f(path, nl, name, opts.binary) b.open() except buffer.BinaryDataException, e: + if not opts.mode: + opts.mode = 'hex' b = f(path, nl, name, True) b.open() diff --git a/buffer.py b/buffer.py index 82ff14b..7b69be9 100644 --- a/buffer.py +++ b/buffer.py @@ -585,6 +585,8 @@ class Binary32Buffer(FileBuffer): j += self.groupsize lines.append(grouppad.join(groups)) i += self.numgroups * self.groupsize + if not self.rawdata: + self.rawdata = [''] return '\n'.join(lines) def write_filter(self, data): return ''.join(self.rawdata)