img_fingerprint.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2011 The Chromium Authors. All rights reserved.
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. """Retrieves an image's "fingerprint".
  6. This is used when retrieving the image from the symbol server. The .dll (or cab
  7. compressed .dl_) or .exe is expected at a path like:
  8. foo.dll/FINGERPRINT/foo.dll
  9. """
  10. from __future__ import print_function
  11. import os
  12. import sys
  13. # Assume this script is under tools/symsrc/
  14. _SCRIPT_DIR = os.path.dirname(__file__)
  15. _ROOT_DIR = os.path.join(_SCRIPT_DIR, os.pardir, os.pardir)
  16. _PEFILE_DIR = os.path.join(
  17. _ROOT_DIR, 'third_party', 'pefile_py3' if sys.version_info >=
  18. (3, 0) else 'pefile')
  19. sys.path.insert(1, _PEFILE_DIR)
  20. import pefile
  21. def GetImgFingerprint(filename):
  22. """Returns the fingerprint for an image file"""
  23. pe = pefile.PE(filename)
  24. return "%08X%x" % (
  25. pe.FILE_HEADER.TimeDateStamp, pe.OPTIONAL_HEADER.SizeOfImage)
  26. def main():
  27. if len(sys.argv) != 2:
  28. print("usage: file.dll")
  29. return 1
  30. print(GetImgFingerprint(sys.argv[1]))
  31. return 0
  32. if __name__ == '__main__':
  33. sys.exit(main())