/PyInstaller/lib/macholib/macho_dump.py

https://bitbucket.org/pyinstaller/pyinstaller-git-svn2git · Python · 40 lines · 31 code · 8 blank · 1 comment · 8 complexity · 3fb097d7b766d138e53a82933bf37a32 MD5 · raw file

  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. from macholib._cmdline import main
  5. from macholib.MachO import MachO
  6. from mach_o import *
  7. ARCH_MAP={
  8. ('<', '64-bit'): 'x86_64',
  9. ('<', '32-bit'): 'i386',
  10. ('>', '64-bit'): 'pp64',
  11. ('>', '32-bit'): 'ppc',
  12. }
  13. def print_file(fp, path):
  14. print >>fp, path
  15. m = MachO(path)
  16. for header in m.headers:
  17. seen = set()
  18. if header.MH_MAGIC == MH_MAGIC_64:
  19. sz = '64-bit'
  20. else:
  21. sz = '32-bit'
  22. print >>fp, ' [%s endian=%r size=%r arch=%r]' % (header.__class__.__name__,
  23. header.endian, sz, ARCH_MAP[(header.endian, sz)])
  24. for idx, name, other in header.walkRelocatables():
  25. if other not in seen:
  26. seen.add(other)
  27. print >>fp, '\t' + other
  28. if __name__ == '__main__':
  29. try:
  30. sys.exit(main(print_file))
  31. except KeyboardInterrupt:
  32. pass