From b95ad40b2730ebe698123a1b8c89f22410a090c9 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Fri, 24 Feb 2017 09:32:49 -0500 Subject: [PATCH] actions: Refactor function to dump function disassembly. --- ScratchABit.py | 2 +- scratchabit/actions.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ScratchABit.py b/ScratchABit.py index f5e3eb4..d79120d 100755 --- a/ScratchABit.py +++ b/ScratchABit.py @@ -540,7 +540,7 @@ def render_line(self, l): engine.render_partial(actions.TextSaveModel(f, self), 0, 0, 10000000) self.show_status("Disassembly listing written: " + out_fname) elif key == b"\x17": # Ctrl+W - outfile = actions.write_func(APP, self.cur_addr(), feedback_obj=self) + outfile = actions.write_func_by_addr(APP, self.cur_addr(), feedback_obj=self) if outfile: self.show_status("Wrote file: %s" % outfile) elif key == b"\x15": # Ctrl+U diff --git a/scratchabit/actions.py b/scratchabit/actions.py index f55d4e5..5b8a347 100644 --- a/scratchabit/actions.py +++ b/scratchabit/actions.py @@ -16,16 +16,21 @@ def add_line(self, addr, line): self.ctrl.show_status("Writing: 0x%x" % addr) self.cnt += 1 -def write_func(APP, addr, prefix="", feedback_obj=None): + +def write_func_stream(APP, func, stream, feedback_obj=None): + model = TextSaveModel(stream, feedback_obj) + for start, end in func.get_ranges(): + while start < end: + start = engine.render_from(model, start, 1) + + +def write_func_by_addr(APP, addr, prefix="", feedback_obj=None): func = APP.aspace.lookup_func(addr) if func: funcname = APP.aspace.get_label(func.start) outfile = prefix + funcname + ".lst" with open(outfile, "w") as f: - model = TextSaveModel(f, feedback_obj) - for start, end in func.get_ranges(): - while start < end: - start = engine.render_from(model, start, 1) + write_func_stream(APP, func, f, feedback_obj) return outfile