Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Side by Side Diff: tools/crx_id/crx_id.py

Issue 8678023: Fix python scripts in src/tools/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 def usage(argv): 16 def usage(argv):
17 print "%s: crx_file" % argv[0] 17 print "%s: crx_file" % argv[0]
18 18
19 EXPECTED_CRX_MAGIC_NUM = 'Cr24' 19 EXPECTED_CRX_MAGIC_NUM = 'Cr24'
20 EXPECTED_CRX_VERSION = 2 20 EXPECTED_CRX_VERSION = 2
21 21
Alexander Potapenko 2011/11/24 07:53:02 Please fix the vertical whitespaces.
22 def HexToInt(hex_chars): 22 def HexToInt(hex_chars):
23 """ Convert bytes like \xab -> 171 """ 23 """ Convert bytes like \xab -> 171 """
24 val = 0 24 val = 0
25 for i in xrange(len(hex_chars)): 25 for i in xrange(len(hex_chars)):
26 val += pow(256, i) * ord(hex_chars[i]) 26 val += pow(256, i) * ord(hex_chars[i])
27 return val 27 return val
28 28
29 def HexToMPDecimal(hex_chars): 29 def HexToMPDecimal(hex_chars):
30 """ Convert bytes to an MPDecimal string. Example \x00 -> "aa" 30 """ Convert bytes to an MPDecimal string. Example \x00 -> "aa"
31 This gives us the AppID for a chrome extension. 31 This gives us the AppID for a chrome extension.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 83
84 def main(argv): 84 def main(argv):
85 if len(argv) != 2: 85 if len(argv) != 2:
86 usage(argv) 86 usage(argv)
87 return 1 87 return 1
88 print 'Raw Bytes: %s' % GetCRXHash(sys.argv[1]) 88 print 'Raw Bytes: %s' % GetCRXHash(sys.argv[1])
89 print 'AppID: %s' % GetCRXAppID(sys.argv[1]) 89 print 'AppID: %s' % GetCRXAppID(sys.argv[1])
90 90
91 if __name__ == '__main__': 91 if __name__ == '__main__':
92 sys.exit(main(sys.argv)) 92 sys.exit(main(sys.argv))
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698