tools/symsrc/pdb_fingerprint_from_img.py
def GetPDBInfoFromImg(filename):
  """Returns the PDB fingerprint and the pdb filename given an image file"""

  pe = pefile.PE(filename)

  for dbg in pe.DIRECTORY_ENTRY_DEBUG:
    if dbg.struct.Type == 2:  # IMAGE_DEBUG_TYPE_CODEVIEW
      off = dbg.struct.AddressOfRawData
      size = dbg.struct.SizeOfData
      data = pe.get_memory_mapped_image()[off:off+size]

      cv = pefile.Structure(__CV_INFO_PDB70_format__)
      cv.__unpack__(data)
      cv.PdbFileName = data[cv.sizeof():]
      guid = pefile.Structure(__GUID_format__)
      guid.__unpack__(cv.Signature)

      if not isinstance(guid.Data4[0], int):
        # In non-py3 pefile, this is a list of bytes.
        guid.Data4 = map(ord, guid.Data4)

      guid.Data4_0 = ''.join("%02X" % x for x in guid.Data4[0:2])
      guid.Data4_1 = ''.join("%02X" % x for x in guid.Data4[2:])

      return ("%08X%04X%04X%s%s%d" % (guid.Data1, guid.Data2, guid.Data3,
                                      guid.Data4_0, guid.Data4_1, cv.Age),
              str(cv.PdbFileName.split(b'\x00', 1)[0].decode()))

    break
Returns the PDB fingerprint and the pdb filename given an image file
Returns the PDB fingerprint and the pdb filename given an image file
Returns the PDB fingerprint and the pdb filename given an image file
def GetPDBInfoFromImg(filename):
  pe = pefile.PE(filename)
  for dbg in pe.DIRECTORY_ENTRY_DEBUG:
    if dbg.struct.Type == 2:  
      off = dbg.struct.AddressOfRawData
      size = dbg.struct.SizeOfData
      data = pe.get_memory_mapped_image()[off:off+size]
      cv = pefile.Structure(__CV_INFO_PDB70_format__)
      cv.__unpack__(data)
      cv.PdbFileName = data[cv.sizeof():]
      guid = pefile.Structure(__GUID_format__)
      guid.__unpack__(cv.Signature)
      if not isinstance(guid.Data4[0], int):
        guid.Data4 = map(ord, guid.Data4)
      guid.Data4_0 = ''.join("%02X" % x for x in guid.Data4[0:2])
      guid.Data4_1 = ''.join("%02X" % x for x in guid.Data4[2:])
      return ("%08X%04X%04X%s%s%d" % (guid.Data1, guid.Data2, guid.Data3,
                                      guid.Data4_0, guid.Data4_1, cv.Age),
              str(cv.PdbFileName.split(b'\x00', 1)[0].decode()))
    break
def GetPDBInfoFromImg ( filename ) : pe = pefile . PE ( filename ) for dbg in pe . DIRECTORY_ENTRY_DEBUG : if dbg . struct . Type == 2 : off = dbg . struct . AddressOfRawData size = dbg . struct . SizeOfData data = pe . get_memory_mapped_image ( ) [ off : off + size ] cv = pefile . Structure ( __CV_INFO_PDB70_format__ ) cv . __unpack__ ( data ) cv . PdbFileName = data [ cv . sizeof ( ) : ] guid = pefile . Structure ( __GUID_format__ ) guid . __unpack__ ( cv . Signature ) if not isinstance ( guid . Data4 [ 0 ] , int ) : guid . Data4 = map ( ord , guid . Data4 ) guid . Data4_0 = '' . join ( "%02X" % x for x in guid . Data4 [ 0 : 2 ] ) guid . Data4_1 = '' . join ( "%02X" % x for x in guid . Data4 [ 2 : ] ) return ( "%08X%04X%04X%s%s%d" % ( guid . Data1 , guid . Data2 , guid . Data3 , guid . Data4_0 , guid . Data4_1 , cv . Age ) , str ( cv . PdbFileName . split ( b'\x00' , 1 ) [ 0 ] . decode ( ) ) ) break
Returns the PDB fingerprint and the pdb filename given an image file
Returns the PDB fingerprint and the pdb filename given an image file
"""Returns the PDB fingerprint and the pdb filename given an image file""" # IMAGE_DEBUG_TYPE_CODEVIEW # In non-py3 pefile, this is a list of bytes.
filename