python-计算资源图标的crc值

来源:互联网 发布:淘宝卖家15天账期延长 编辑:程序博客网 时间:2024/06/06 07:44

关键在于解析资源信息,找到icon的数据,然后计算这些数据的crc

#----------------------------------------------------------------------    def _get_iconcrc(self, file_path):        """        Generates the crc32 hash of the icon of the file.        @return: str, the str value of the file's icon        """        iconData = ""        mype = pefile.PE(file_path)        if hasattr(mype, "DIRECTORY_ENTRY_RESOURCE"):            resIcons = filter(lambda x: x.id==pefile.RESOURCE_TYPE['RT_ICON'], mype.DIRECTORY_ENTRY_RESOURCE.entries)            if len(resIcons)>0:                resIcons = resIcons[0]                if hasattr(resIcons, "directory"):                    for resId in resIcons.directory.entries:                        if hasattr(resId, 'directory'):                            for resLang in resId.directory.entries:                                iconData += mype.get_data(resLang.data.struct.OffsetToData, resLang.data.struct.Size)                if not iconData:            print "not iconData"            return None        else:            return self._crc32(iconData)


原创粉丝点击