Even more unix.
This commit is contained in:
parent
8d0b672b63
commit
f7aeb27e6e
24
infernal.py
24
infernal.py
|
@ -10,7 +10,8 @@ import Junk
|
||||||
|
|
||||||
def parse_args ():
|
def parse_args ():
|
||||||
parser = argparse.ArgumentParser(description="For fun x86-64 emulator and stack visualizer.")
|
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:
|
for register in REGISTERS:
|
||||||
parser.add_argument('--'+register[1:], nargs = 1, type = int, default = [Junk.Junk()], dest = register)
|
parser.add_argument('--'+register[1:], nargs = 1, type = int, default = [Junk.Junk()], dest = register)
|
||||||
args = vars(parser.parse_args())
|
args = vars(parser.parse_args())
|
||||||
|
@ -23,18 +24,28 @@ def parse_args ():
|
||||||
registers_init['rsp'] = 0
|
registers_init['rsp'] = 0
|
||||||
registers_init['rbp'] = Junk.Junk('old bp')
|
registers_init['rbp'] = Junk.Junk('old bp')
|
||||||
|
|
||||||
|
#
|
||||||
program = ""
|
program = ""
|
||||||
if args['filename'] == '-':
|
if args['input-file'] == '-':
|
||||||
program = sys.stdin.read()
|
program = sys.stdin.read()
|
||||||
else:
|
else:
|
||||||
with open(args['filename']) as file:
|
with open(args['input-file']) as file:
|
||||||
program = file.read()
|
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 ():
|
def main ():
|
||||||
|
|
||||||
(program, registers_init) = parse_args()
|
(program, registers_init, output_file) = parse_args()
|
||||||
|
|
||||||
# Determine registers to display
|
# Determine registers to display
|
||||||
registers_to_draw = ["%rip","%rbp","%rsp", ""]
|
registers_to_draw = ["%rip","%rbp","%rsp", ""]
|
||||||
|
@ -56,7 +67,8 @@ def main ():
|
||||||
painter.drawNames(emu)
|
painter.drawNames(emu)
|
||||||
|
|
||||||
# Display result
|
# Display result
|
||||||
print(painter.to_string())
|
output_file.write(painter.to_string())
|
||||||
|
output_file.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user