X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=bios%2Fseabios%2Ftools%2Ftransdump.py;fp=bios%2Fseabios%2Ftools%2Ftransdump.py;h=4caaeb70b7e89ca54188525cdaf45dbbe73dd68f;hb=ab1e08bb6653d0d65ff64ea8f42506b9fd502357;hp=0000000000000000000000000000000000000000;hpb=5c40a15de52c320b70c94331e482b25fdcf768c4;p=palacios.git diff --git a/bios/seabios/tools/transdump.py b/bios/seabios/tools/transdump.py new file mode 100755 index 0000000..4caaeb7 --- /dev/null +++ b/bios/seabios/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 +# +# 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]) + parts = parts[1].split() + mem.extend([unhex(v) for v in parts]) + except ValueError: + continue + return mem + +def printUsage(): + sys.stderr.write("Usage:\n %s \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("