Skip to content

Commit

Permalink
actions: Refactor function to dump function disassembly.
Browse files Browse the repository at this point in the history
  • Loading branch information
pfalcon committed Feb 24, 2017
1 parent 816a8bd commit b95ad40
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion ScratchABit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 10 additions & 5 deletions scratchabit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit b95ad40

Please sign in to comment.