Python 批量分析windows程序崩溃捕获的dump文件
2015-04-30 21:45
429 查看
dump文件可以用CDB和编译生成的pdb文件获取出崩溃堆栈,定位崩溃代码段。
在pdbPath.txt中读取pdb文件的路径。
用python运行cdb 带参数命令,逐个解析dump 文件,将解析结果保存到对于名字的文本文件内,再从这些文件中摘取堆栈信息输出到文本。
在pdbPath.txt中读取pdb文件的路径。
用python运行cdb 带参数命令,逐个解析dump 文件,将解析结果保存到对于名字的文本文件内,再从这些文件中摘取堆栈信息输出到文本。
# -*- coding: gbk -*- import os import os.path import sys import zipfile import subprocess def we_are_frozen(): # All of the modules are built-in to the interpreter, e.g., by py2exe return hasattr(sys, "frozen") def module_path(): encoding = sys.getfilesystemencoding() if we_are_frozen(): return os.path.dirname(sys.executable.encode(encoding)) return os.path.dirname(os.path.abspath(__file__.encode(encoding))) def files_in_path(path): return list(os.walk(path))[0][2] def files_filter(filelist,filtertype): ''' filtertype = 'zip' filter *.zip files ''' typelen = len(filtertype) + 1 return [filename for filename in filelist if '.' + filtertype == filename[-typelen:]] def mkdir(path): path = path.strip() path = path.rstrip("\\") isExists = os.path.exists(path) if not isExists: os.makedirs(path) return True else: return False def unzip(zipfilelist): mkdir(str(module_path(),'gbk')+'\\dump') for files in zipfilelist: zfile = zipfile.ZipFile(files,'r') for fileinzip in zfile.namelist(): data = zfile.read(fileinzip) file = open(fileinzip, 'w+b') file.write(data) file.close() os.rename(fileinzip,str(module_path(),'gbk')+'\\dump\\'+files[:-4]+'.dmp') def execute_command(command): popen = subprocess.Popen(command,\ shell=True,stdin=subprocess.PIPE, \ stdout=sys.stdout, stderr=subprocess.STDOUT) popen.wait() if __name__ == '__main__': files = files_in_path(str(module_path(),'gbk')) zipfiles = files_filter(files,'zip') unzip(zipfiles) mypdbpath = '' for line in open("pdbPath.txt"): mypdbpath += line.strip() mspdbpath = r'SRV*f:\localsymbols*http://msdl.microsoft.com/download/symbols;' files = files_in_path(str(module_path(),'gbk')+'\\dump') dumpfiles = files_filter(files,'dmp') for dumpfile in dumpfiles: command = "cdb -y " + mspdbpath + mypdbpath + " -z " + "dump\\" + dumpfile + \ " -logo " + "dump\\" + dumpfile[:-3] + "txt" + " -lines -c \"!analyze -v;q\"" execute_command(command) files = files_in_path(str(module_path(),'gbk')+'\\dump') txtfiles = files_filter(files,'txt') stakereport = open('STACK_TEXT.txt','wb+') for txtfile in txtfiles: needwrite = False stakereport.write(bytes(txtfile,'gbk')+b'\r\n') for line in open(str(module_path(),'gbk')+'\\dump\\'+txtfile,'rb'): #STACK_TEXT: if line[:len(b'STACK_TEXT:')] == b'STACK_TEXT:': needwrite = True if needwrite: stakereport.write(line) if line[:len(b'\r\n')] == b'\r\n' and needwrite: break
相关文章推荐
- windows下程序崩溃,生成dump文件分析
- Google Breakpad 在 windows下捕获程序崩溃报告
- windows程序崩溃生成dump文件
- Google Breakpad在windows下捕获程序崩溃报告
- Qt 使用 Google Breakpad 捕获程序崩溃报告(dump文件)
- Qt之使用Google Breakpad捕获程序崩溃报告(dump文件)
- Qt 使用 Google Breakpad 捕获程序崩溃报告(dump文件) good
- 崩溃的Python学习过程1—— 用Eclipse编写Python程序(windows)
- windows程序崩溃生成dump文件
- windows程序崩溃生成dump文件
- windows 应用程序崩溃时的内存转储及dump文件的分析
- Google Breakpad 在 windows下捕获程序崩溃报告
- windows 应用程序崩溃时的内存转储及dump文件的分析
- 在linux下利用程序崩溃后的core文件分析bug
- python在windows下实现备份程序实例
- 使用cProfile分析Python程序性能
- python练习程序(批量重命名)
- python 笔记 在windows下的程序 获取图片并显示出来
- 生成程序崩溃的dump文件,使用windbg调试
- Python程序分析