1 Star 0 Fork 0

软件工程师/NemesisDumpAnalyzer

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
DumpAnalyze.py 6.82 KB
一键复制 编辑 原始数据 按行查看 历史
软件工程师 提交于 2022-05-16 18:58 . [download]
# python3
# 作者 :NemesisZoo
# 联系方式 :276793422
# 创建日期 :2021/12/17
# 文件名 :DumpAnalyze
# 文件简介 :
# 文件说明 :
"""
"""
import datetime
import sys
import optparse
# from Analyzer.WinDBG.Lib.BaseLibrary import InitDebugLibrary
import time
from Downloader.Downloader import RunDumpAnalyze
from Order.Order import MainOrder
# 判断字符串是否有效
def IsStringValid(p):
if p is not None and p != "":
return True
return False
def RemakeDirPath(dir_path):
if not dir_path.endswith('/') and not dir_path.endswith('\\'):
dir_path = dir_path + '/'
return dir_path
def RemakeDayTime(day_time):
day_time = day_time.replace(".", "-")
return day_time
def GetArgsInfo():
parser = optparse.OptionParser()
parser.add_option("--type", dest="Type", type="string", help="要执行的类型,download(下载),analyze(调试),order(处理),stream(完整流程)")
parser.add_option("--indir", dest="InDir", type="string", help="输入目录")
parser.add_option("--outfile", dest="OutFile", type="string", help="输出到文件")
parser.add_option("--crash", dest="Crash", type="string", help="下载异常类型,可选值【bsod】查看崩溃,【module】查看进程模块,【process】指定进程")
parser.add_option("--process", dest="Process", type="string", help="目标进程")
parser.add_option("--module", dest="Module", type="string", help="崩溃模块名")
parser.add_option("--onlylist", dest="OnlyList", action="store_true", default=False, help="只要dump 列表,不用下载文件")
parser.add_option("--channel", dest="Channel", type="string", help="渠道号")
parser.add_option("--daytime", dest="DayTime", type="string", help="日期")
parser.add_option("--outdir", dest="OutDir", type="string", help="输出目录")
parser.add_option("--starttime", dest="StartTime", type="string", help="起始日期")
parser.add_option("--endtime", dest="EndTime", type="string", help="结束日期")
parser.add_option("--wget", dest="Wget", type="string", help="wget程序路径")
parser.add_option("--log", dest="Log", action="store_true", default=False, help="是否输出log")
return parser.parse_args()
def FuncDownload(opt, args):
channel_id = opt.Channel
day_time = opt.DayTime
start_time = opt.StartTime
end_time = opt.EndTime
dir_path = opt.OutDir
path_wget = opt.Wget
crash_type = opt.Crash
process_name = opt.Process
module_name = opt.Module
only_list = opt.OnlyList
output_log = opt.Log
if not IsStringValid(dir_path):
pass
elif not IsStringValid(path_wget):
pass
elif not IsStringValid(crash_type):
pass
if channel_id is None:
channel_id = ""
dir_path = RemakeDirPath(dir_path)
# 如果日期无效
if IsStringValid(day_time):
day_time = RemakeDayTime(day_time)
if not dir_path.endswith(day_time + '/'):
dir_path = dir_path + day_time + '/'
download_time_begin = datetime.datetime.now()
tmp = RunDumpAnalyze(crash_type, channel_id, day_time, dir_path, path_wget, process_name, module_name, only_list, output_log)
download_time_end = datetime.datetime.now()
print("")
print("")
print("下载结束:")
print("start :", download_time_begin)
print("end :", download_time_end)
print("time :", download_time_end - download_time_begin)
print("日期 :[", day_time, "] => 数量 :[", len(tmp), "]")
print("")
print("总计 :[", len(tmp), "]")
pass
# 如果 起始、结束 日期还无效
elif IsStringValid(start_time) and IsStringValid(end_time):
time_start = start_time.split("-")
if len(time_start) != 3:
return
time_end = end_time.split("-")
if len(time_end) != 3:
return
day_start_info = datetime.datetime(int(time_start[0]), int(time_start[1]), int(time_start[2]))
day_end_info = datetime.datetime(int(time_end[0]), int(time_end[1]), int(time_end[2]))
out_info = {}
print("起始日期:", start_time)
print("结束日期:", end_time)
print("开始下载")
download_time_begin = datetime.datetime.now()
tmp_dir_path = dir_path
for i in range(100):
# print(day_start_info, " => ", day_start_info.strftime("%Y-%m-%d"))
day_time = day_start_info.strftime("%Y-%m-%d")
dir_path = tmp_dir_path
if not dir_path.endswith(day_time + '/'):
dir_path = dir_path + day_time + '/'
tmp = RunDumpAnalyze(crash_type, channel_id, day_time, dir_path, path_wget, process_name, module_name, only_list, output_log)
out_info.setdefault(day_time, len(tmp))
if day_start_info == day_end_info:
break
day_start_info += datetime.timedelta(days=1)
download_time_end = datetime.datetime.now()
print("")
print("")
print("下载结束:")
print("start :", download_time_begin)
print("end :", download_time_end)
print("time :", download_time_end - download_time_begin)
sum_count = 0
for key in out_info:
sum_count += out_info[key]
print("日期 :[", key, "] => 数量 :[", out_info[key], "]")
print("")
print("总计 :[", sum_count, "]")
def FuncAnalyze(opt, args):
"""
if not InitDebugLibrary("Analyzer"):
print("配置出错,环境变量不足")
else:
pass
"""
pass
def FuncOrder(opt, args):
string_in_dir = opt.InDir
string_out_file = opt.OutFile
if not IsStringValid(string_in_dir):
pass
elif not IsStringValid(string_out_file):
pass
else:
MainOrder(string_in_dir, string_out_file)
pass
def FuncStream(opt, args):
pass
def Main():
if len(sys.argv) == 1:
sys.argv.append("--help")
print("" +
R"""
命令行示例:
BSOD下载
python3 DumpAnalyze.py --type download --crash bsod --channel 1339 --daytime 2021-12-19 --outdir G:\Temp\1339 --wget G:\Gitee\nemesis-dump-analyzer\Bin\wget64.exe
模块崩溃下载
python3 DumpAnalyze.py --type download --crash module --channel 1509 --daytime 2021-12-19 --module decs.dll --outdir G:\Temp\1517 --wget G:\Gitee\nemesis-dump-analyzer\Bin\wget64.exe
指定进程的所有模块dump下载
python3 DumpAnalyze.py --type download --log --crash process --channel 1339 --daytime 2021-12-18 --process center.exe --outdir G:\Temp\center.exe\1339\ --wget G:\Gitee\nemesis-dump-analyzer\Bin\wget64.exe
指定进程的指定模块dump下载
python3 DumpAnalyze.py --type download --log --crash process --channel 1339 --daytime 2021-12-18 --process center.exe --module decs.dll --outdir G:\Temp\center.exe\1339\ --wget G:\Gitee\nemesis-dump-analyzer\Bin\wget64.exe
整理dump解析结果
python3 DumpAnalyze.py --type order --indir D:\dump\2021-12-17\out --outfile temp.db
""")
opt, args = GetArgsInfo()
if opt.Type == "download":
# 下载
FuncDownload(opt, args)
pass
elif opt.Type == "analyze":
# 调试
FuncAnalyze(opt, args)
pass
elif opt.Type == "order":
# 处理
FuncOrder(opt, args)
pass
elif opt.Type == "stream":
# 完整流程
FuncStream(opt, args)
pass
else:
pass
pass
# 按间距中的绿色按钮以运行脚本。
if __name__ == '__main__':
Main()
pass
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/sqlxss/nemesis-dump-analyzer.git
git@gitee.com:sqlxss/nemesis-dump-analyzer.git
sqlxss
nemesis-dump-analyzer
NemesisDumpAnalyzer
develop

搜索帮助