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

Side by Side Diff: tools/symsrc/pdb_fingerprint_from_img.py

Issue 155136: Add the symbol and source server scripts. (Closed)
Patch Set: review feedback Created 11 years, 5 months 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
« no previous file with comments | « tools/symsrc/img_fingerprint.py ('k') | tools/symsrc/pefile.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright (c) 2008 The Chromium Authors. All rights reserved.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 """This will retrieve a PDBs "fingerprint" from it's corresponding executable
8 image (.dll or .exe). This is used when retrieving the PDB from the symbol
9 server. The .pdb (or cab compressed .pd_) is expected at a path like:
10 foo.pdb/FINGERPRINT/foo.pdb
11
12 We can retrieve the same information from the .PDB file itself, but this file
13 format is much more difficult and undocumented. Instead, we can look at the
14 DLL's reference to the PDB, and use that to retrieve the information."""
15
16 import sys
17 import pefile
18
19 __CV_INFO_PDB70_format__ = ('CV_INFO_PDB70',
20 ('4s,CvSignature', '16s,Signature', 'L,Age'))
21
22 __GUID_format__ = ('GUID',
23 ('L,Data1', 'H,Data2', 'H,Data3', '8s,Data4'))
24
25 def GetPDBInfoFromImg(filename):
26 """Returns the PDB fingerprint and the pdb filename given an image file"""
27
28 pe = pefile.PE(filename)
29
30 for dbg in pe.DIRECTORY_ENTRY_DEBUG:
31 if dbg.struct.Type == 2: # IMAGE_DEBUG_TYPE_CODEVIEW
32 off = dbg.struct.AddressOfRawData
33 size = dbg.struct.SizeOfData
34 data = pe.get_memory_mapped_image()[off:off+size]
35
36 cv = pefile.Structure(__CV_INFO_PDB70_format__)
37 cv.__unpack__(data)
38 cv.PdbFileName = data[cv.sizeof():]
39 guid = pefile.Structure(__GUID_format__)
40 guid.__unpack__(cv.Signature)
41 guid.Data4_0 = ''.join("%02X" % ord(x) for x in guid.Data4[0:2])
42 guid.Data4_1 = ''.join("%02X" % ord(x) for x in guid.Data4[2:])
43
44 return ("%08X%04X%04X%s%s%d" % (
45 guid.Data1, guid.Data2, guid.Data3,
46 guid.Data4_0, guid.Data4_1, cv.Age),
47 cv.PdbFileName.split('\x00', 1)[0])
48
49 break
50
51 if __name__ == '__main__':
52 if len(sys.argv) != 2:
53 print "usage: file.dll"
54 sys.exit(1)
55
56 (fingerprint, file) = GetPDBInfoFromImg(sys.argv[1])
57 print "%s %s" % (fingerprint, file)
OLDNEW
« no previous file with comments | « tools/symsrc/img_fingerprint.py ('k') | tools/symsrc/pefile.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698