| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 """ Read a CRX file and write out the App ID and the Full Hash of the ID. | 6 """ Read a CRX file and write out the App ID and the Full Hash of the ID. |
| 7 See: http://code.google.com/chrome/extensions/crx.html | 7 See: http://code.google.com/chrome/extensions/crx.html |
| 8 and 'http://stackoverflow.com/questions/' | 8 and 'http://stackoverflow.com/questions/' |
| 9 + '1882981/google-chrome-alphanumeric-hashes-to-identify-extensions' | 9 + '1882981/google-chrome-alphanumeric-hashes-to-identify-extensions' |
| 10 for docs on the format. | 10 for docs on the format. |
| 11 """ | 11 """ |
| 12 | 12 |
| 13 import sys | 13 import sys |
| 14 import hashlib | 14 import hashlib |
| 15 | 15 |
| 16 |
| 17 EXPECTED_CRX_MAGIC_NUM = 'Cr24' |
| 18 EXPECTED_CRX_VERSION = 2 |
| 19 |
| 20 |
| 16 def usage(argv): | 21 def usage(argv): |
| 17 print "%s: crx_file" % argv[0] | 22 print "%s: crx_file" % argv[0] |
| 18 | 23 |
| 19 EXPECTED_CRX_MAGIC_NUM = 'Cr24' | |
| 20 EXPECTED_CRX_VERSION = 2 | |
| 21 | |
| 22 def HexToInt(hex_chars): | 24 def HexToInt(hex_chars): |
| 23 """ Convert bytes like \xab -> 171 """ | 25 """ Convert bytes like \xab -> 171 """ |
| 24 val = 0 | 26 val = 0 |
| 25 for i in xrange(len(hex_chars)): | 27 for i in xrange(len(hex_chars)): |
| 26 val += pow(256, i) * ord(hex_chars[i]) | 28 val += pow(256, i) * ord(hex_chars[i]) |
| 27 return val | 29 return val |
| 28 | 30 |
| 29 def HexToMPDecimal(hex_chars): | 31 def HexToMPDecimal(hex_chars): |
| 30 """ Convert bytes to an MPDecimal string. Example \x00 -> "aa" | 32 """ Convert bytes to an MPDecimal string. Example \x00 -> "aa" |
| 31 This gives us the AppID for a chrome extension. | 33 This gives us the AppID for a chrome extension. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 return HexTo256(pub_key_hash) | 76 return HexTo256(pub_key_hash) |
| 75 | 77 |
| 76 def GetCRXAppID(filename): | 78 def GetCRXAppID(filename): |
| 77 f = open(filename, 'rb') | 79 f = open(filename, 'rb') |
| 78 pub_key = GetPublicKey(f) | 80 pub_key = GetPublicKey(f) |
| 79 f.close() | 81 f.close() |
| 80 pub_key_hash = hashlib.sha256(pub_key).digest() | 82 pub_key_hash = hashlib.sha256(pub_key).digest() |
| 81 # AppID is the MPDecimal of only the first 128 bits of the hash. | 83 # AppID is the MPDecimal of only the first 128 bits of the hash. |
| 82 return HexToMPDecimal(pub_key_hash[:128/8]) | 84 return HexToMPDecimal(pub_key_hash[:128/8]) |
| 83 | 85 |
| 86 |
| 84 def main(argv): | 87 def main(argv): |
| 85 if len(argv) != 2: | 88 if len(argv) != 2: |
| 86 usage(argv) | 89 usage(argv) |
| 87 return 1 | 90 return 1 |
| 88 print 'Raw Bytes: %s' % GetCRXHash(sys.argv[1]) | 91 print 'Raw Bytes: %s' % GetCRXHash(sys.argv[1]) |
| 89 print 'AppID: %s' % GetCRXAppID(sys.argv[1]) | 92 print 'AppID: %s' % GetCRXAppID(sys.argv[1]) |
| 90 | 93 |
| 94 |
| 91 if __name__ == '__main__': | 95 if __name__ == '__main__': |
| 92 sys.exit(main(sys.argv)) | 96 sys.exit(main(sys.argv)) |
| OLD | NEW |