io.py 849 B

1234567891011121314151617181920212223242526272829303132333435
  1. import os
  2. import sys
  3. import ast
  4. def info(msg):
  5. print(os.path.basename(sys.argv[0]) + ": " + msg)
  6. def warn(msg):
  7. print(os.path.basename(sys.argv[0]) + ": " + msg, file=sys.stderr)
  8. def fatal(msg):
  9. warn(msg)
  10. exit(1)
  11. def load_map(path):
  12. fd = open(path, "r")
  13. # check the header
  14. if fd.readline() != 'OFFSET\tSIZE\tNAME\tID\tSTRING\n':
  15. fatal("invalid map file")
  16. # parse symbols
  17. syms = []
  18. for line in fd:
  19. line = line.rstrip('\n')
  20. offset, size, name, tr_id, data = line.split('\t', 4)
  21. data = ast.literal_eval(data)
  22. tr_id = int(tr_id) if len(tr_id) else None
  23. syms.append({'offset': int(offset, 16),
  24. 'size': int(size, 16),
  25. 'id': tr_id,
  26. 'name': name,
  27. 'data': data})
  28. return syms