Guest User

11801 Memory Dump Tool V0.1

a guest
Oct 27th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. #!/usr/bin/python
  2. #11801 memory dump cleanup tool V0.1
  3. #(C) David Carr 2019
  4. #USE AT YOUR OWN RISK --- VERY MINIMALLY TESTED
  5.  
  6. import struct
  7. import sys
  8.  
  9. f = open(sys.argv[1])
  10.  
  11. x = f.read()
  12.  
  13. #ram
  14. ram = {}
  15.  
  16. #search for start of address line
  17. start = 0
  18. while True:
  19. start = x.find("1 RM", start+1)
  20. if start == -1:
  21. break
  22.  
  23. line = x[start:start+38]
  24. #print line
  25.  
  26. #parse it
  27. addr = int(line[6:14],16)
  28.  
  29. bytes = []
  30.  
  31. for i in range(8):
  32. bytes += [int(line[15+3*i:17+3*i], 16)]
  33.  
  34. #for i in range(8):
  35. # print "%02x " % bytes[i],
  36. #print
  37.  
  38. #store it
  39. if addr in ram: #if a duplicate, check for match
  40. assert(bytes == ram[addr])
  41. else: #if new...
  42. ram[addr] = bytes
  43.  
  44. #check that addresses are contiguous
  45. addrs = sorted(ram.keys())
  46. for i in range(len(addrs)-1):
  47. assert(addrs[i] == addrs[i+1] - 8)
  48. print "Addresses contiguous."
  49.  
  50. #calculate size
  51. start = addrs[0]
  52. end = addrs[-1]
  53. print "Start: %x" % start
  54. print "End: %x" % end
  55. calc_size = end-start+8
  56.  
  57. #check actual size
  58. actual_size = 0
  59. for a in ram.keys():
  60. actual_size += len(ram[a])
  61.  
  62. print "Calc size: %d" % calc_size
  63. print "Acutal size: %d" % actual_size
  64. assert(calc_size == actual_size)
  65.  
  66. #write out
  67. byte_count = 0
  68. outfile = open(sys.argv[1]+".bin","wb")
  69. for a in addrs:
  70. #print "%x" % a
  71. for b in ram[a]:
  72. outfile.write(struct.pack("B",b))
  73. byte_count += 1
  74. #print "%02x" % b,
  75. #print "\n"
  76. print "Bytes written: %d" % byte_count
  77. assert (calc_size == byte_count)
Add Comment
Please, Sign In to add comment