diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2010-07-30 18:51:29 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2010-07-30 18:51:29 -0400 |
commit | 597040dd3dba3471c9ed012a5056c42949f34962 (patch) | |
tree | 803373384df1034ec0ba0617172756beed03eb2b /tools | |
parent | 48f5f8b850d19767f60ee83bfe0fd30bc4e867b4 (diff) | |
download | seabios-597040dd3dba3471c9ed012a5056c42949f34962.tar.gz |
Add tools/trandump.py tool for converting hexdump() output.
Add tool for converting the output from hexdump() back into its
original binary form. This can be useful for use with tools such as
hexdump and objdump.
Diffstat (limited to 'tools')
-rwxr-xr-x | tools/transdump.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/tools/transdump.py b/tools/transdump.py new file mode 100755 index 00000000..c6f0e07f --- /dev/null +++ b/tools/transdump.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +# This script is useful for taking the output of memdump() and +# converting it back into binary output. This can be useful, for +# example, when one wants to push that data into other tools like +# objdump or hexdump. +# +# (C) Copyright 2010 Kevin O'Connor <kevin@koconnor.net> +# +# This file may be distributed under the terms of the GNU GPLv3 license. + +import sys +import struct + +def unhex(str): + return int(str, 16) + +def parseMem(filehdl): + mem = [] + for line in filehdl: + parts = line.split(':') + if len(parts) < 2: + continue + try: + vaddr = unhex(parts[0]) + except ValueError: + continue + parts = parts[1].split() + mem.extend([unhex(v) for v in parts]) + return mem + +def printUsage(): + sys.stderr.write("Usage:\n %s <file | ->\n" + % (sys.argv[0],)) + sys.exit(1) + +def main(): + if len(sys.argv) != 2: + printUsage() + filename = sys.argv[1] + if filename == '-': + filehdl = sys.stdin + else: + filehdl = open(filename, 'r') + mem = parseMem(filehdl) + for i in mem: + sys.stdout.write(struct.pack("<I", i)) + +if __name__ == '__main__': + main() |