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


Posted in Python onOctober 05, 2014

本文实例讲述了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安装Imaging报错:The _imaging C module is not installed问题解决方法
Aug 22 Python
零基础写python爬虫之urllib2中的两个重要概念:Openers和Handlers
Nov 05 Python
在Python中操作列表之list.extend()方法的使用
May 20 Python
Python与R语言的简要对比
Nov 14 Python
代码讲解Python对Windows服务进行监控
Feb 11 Python
python微信跳一跳系列之色块轮廓定位棋盘
Feb 26 Python
Django实现单用户登录的方法示例
Mar 28 Python
python多进程(加入进程池)操作常见案例
Oct 21 Python
pytorch进行上采样的种类实例
Feb 18 Python
在python tkinter界面中添加按钮的实例
Mar 04 Python
python代码如何注释
Jun 01 Python
python实现暗通道去雾算法的示例
Sep 27 Python
python求crc32值的方法
Oct 05 #Python
Python获取文件ssdeep值的方法
Oct 05 #Python
python获取Linux下文件版本信息、公司名和产品名的方法
Oct 05 #Python
python获取文件版本信息、公司名和产品名的方法
Oct 05 #Python
python实现调用其他python脚本的方法
Oct 05 #Python
跟老齐学Python之让人欢喜让人忧的迭代
Oct 02 #Python
跟老齐学Python之关于循环的小伎俩
Oct 02 #Python
You might like
PHP函数之日期时间函数date()使用详解
2013/09/09 PHP
php获取目标函数执行时间示例
2014/03/04 PHP
Linux下快速搭建php开发环境
2017/03/13 PHP
PHP实现UTF8二进制及明文字符串的转化功能示例
2017/11/20 PHP
捕获键盘事件(且兼容各浏览器)
2013/07/03 Javascript
jquery、js操作checkbox全选反选
2014/03/12 Javascript
jQuery中ajax的get()方法用法实例
2014/12/26 Javascript
以jQuery中$.Deferred对象为例讲解promise对象是如何处理异步问题
2015/11/13 Javascript
Javascript实现从小到大的数组转换成二叉搜索树
2017/06/13 Javascript
关于vue单文件中引用路径的处理方法
2018/01/08 Javascript
ES6学习笔记之map、set与数组、对象的对比
2018/03/01 Javascript
浅析Vue项目中使用keep-Alive步骤
2018/07/27 Javascript
详解关于Vue版本不匹配问题(Vue packages version mismatch)
2018/09/17 Javascript
jquery图片预览插件实现方法详解
2019/07/18 jQuery
vue.js 2.0实现简单分页效果
2019/07/29 Javascript
Python统计日志中每个IP出现次数的方法
2015/07/06 Python
利用Python找出序列中出现最多的元素示例代码
2017/12/08 Python
对Python中的条件判断、循环以及循环的终止方法详解
2019/02/08 Python
Python开发网站目录扫描器的实现
2019/02/21 Python
详解Python读取yaml文件多层菜单
2019/03/23 Python
Pyqt清空某一个QTreeewidgetItem下的所有分支方法
2019/06/17 Python
python原类、类的创建过程与方法详解
2019/07/19 Python
python并发编程 Process对象的其他属性方法join方法详解
2019/08/20 Python
Python类中的魔法方法之 __slots__原理解析
2019/08/26 Python
python实现提取COCO,VOC数据集中特定的类
2020/03/10 Python
python实现在列表中查找某个元素的下标示例
2020/11/16 Python
input file上传文件样式支持html5的浏览器解决方案
2012/11/14 HTML / CSS
俄罗斯运动、健康和美容产品在线商店:Lactomin.ru
2020/07/23 全球购物
工会主席岗位责任制
2014/02/11 职场文书
幼儿园大班毕业教师寄语
2014/04/03 职场文书
外贸会计专业自荐信
2014/06/22 职场文书
2014国庆65周年领导讲话稿(3篇)
2014/09/21 职场文书
课外活动总结
2015/02/04 职场文书
高中家长意见怎么写
2015/06/03 职场文书
学校学期工作总结
2015/08/13 职场文书
教你用Java Swing实现自助取款机系统
2021/06/11 Java/Android