python实现计算资源图标crc值的方法

yipeiwu_com6年前Python基础

本文实例讲述了python实现计算资源图标crc值的方法,分享给大家供大家参考。具体方法如下:

实现该功能的关键在于解析资源信息,找到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) 

希望本文所述对大家的Python程序设计有所帮助。

相关文章

Python学习笔记之字符串和字符串方法实例详解

Python学习笔记之字符串和字符串方法实例详解

本文实例讲述了Python学习笔记之字符串和字符串方法。分享给大家供大家参考,具体如下: 字符串 在 python 中,字符串的变量类型显示为 str。你可以使用双引号 " 或单引号 '...

python脚本作为Windows服务启动代码详解

我们首先来看下全部代码: # -*- coding: cp936 -*- import win32serviceutil import win32service import...

python openpyxl使用方法详解

openpyxl特点 openpyxl(可读写excel表)专门处理Excel2007及以上版本产生的xlsx文件,xls和xlsx之间转换容易 注意:如果文字编码是“gb2312”...

Python中super函数的用法

描述 super() 函数用于调用下一个父类(超类)并返回该父类实例的方法。 super 是用来解决多重继承问题的,直接用类名调用父类方法在使用单继承的时候没问题,但是如果使用多继承...

对Django的restful用法详解(自带的增删改查)

对Django的restful用法详解(自带的增删改查)

什么是rest REST是所有Web应用都应该遵守的架构设计指导原则。 Representational State Transfer,翻译是”表现层状态转化”。 面向资源是REST最明...