diff --git a/infernal.py b/infernal.py index a4ccb09..9fd8599 100644 --- a/infernal.py +++ b/infernal.py @@ -10,7 +10,8 @@ import Junk def parse_args (): parser = argparse.ArgumentParser(description="For fun x86-64 emulator and stack visualizer.") - parser.add_argument('-i', '--input-file', default='-', help = '.S file to use as input', dest = 'filename') + parser.add_argument('-i', '--input-file', default='-', help = '.S file to use as input', dest = 'input-file') + parser.add_argument('-o', '--output-file', default='-', help = '.S file to use as output', dest = 'output-file') for register in REGISTERS: parser.add_argument('--'+register[1:], nargs = 1, type = int, default = [Junk.Junk()], dest = register) args = vars(parser.parse_args()) @@ -23,18 +24,28 @@ def parse_args (): registers_init['rsp'] = 0 registers_init['rbp'] = Junk.Junk('old bp') + # program = "" - if args['filename'] == '-': + if args['input-file'] == '-': program = sys.stdin.read() else: - with open(args['filename']) as file: + with open(args['input-file']) as file: program = file.read() - return (program, registers_init) + # Output file: + output_file = None + if args['output-file'] == '-': + output_file = sys.stdout + else: + output_file = open(args['output-file'], 'w') + + ## + + return (program, registers_init, output_file) def main (): - (program, registers_init) = parse_args() + (program, registers_init, output_file) = parse_args() # Determine registers to display registers_to_draw = ["%rip","%rbp","%rsp", ""] @@ -56,7 +67,8 @@ def main (): painter.drawNames(emu) # Display result - print(painter.to_string()) + output_file.write(painter.to_string()) + output_file.close() if __name__ == "__main__": main()