Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- #11801 memory dump cleanup tool V0.1
- #(C) David Carr 2019
- #USE AT YOUR OWN RISK --- VERY MINIMALLY TESTED
- import struct
- import sys
- f = open(sys.argv[1])
- x = f.read()
- #ram
- ram = {}
- #search for start of address line
- start = 0
- while True:
- start = x.find("1 RM", start+1)
- if start == -1:
- break
- line = x[start:start+38]
- #print line
- #parse it
- addr = int(line[6:14],16)
- bytes = []
- for i in range(8):
- bytes += [int(line[15+3*i:17+3*i], 16)]
- #for i in range(8):
- # print "%02x " % bytes[i],
- #print
- #store it
- if addr in ram: #if a duplicate, check for match
- assert(bytes == ram[addr])
- else: #if new...
- ram[addr] = bytes
- #check that addresses are contiguous
- addrs = sorted(ram.keys())
- for i in range(len(addrs)-1):
- assert(addrs[i] == addrs[i+1] - 8)
- print "Addresses contiguous."
- #calculate size
- start = addrs[0]
- end = addrs[-1]
- print "Start: %x" % start
- print "End: %x" % end
- calc_size = end-start+8
- #check actual size
- actual_size = 0
- for a in ram.keys():
- actual_size += len(ram[a])
- print "Calc size: %d" % calc_size
- print "Acutal size: %d" % actual_size
- assert(calc_size == actual_size)
- #write out
- byte_count = 0
- outfile = open(sys.argv[1]+".bin","wb")
- for a in addrs:
- #print "%x" % a
- for b in ram[a]:
- outfile.write(struct.pack("B",b))
- byte_count += 1
- #print "%02x" % b,
- #print "\n"
- print "Bytes written: %d" % byte_count
- assert (calc_size == byte_count)
Add Comment
Please, Sign In to add comment