import os
import pickle
from sklearn.ensemble import RandomForestClassifier
import pefile
def get_peheader_features(path):
peheader_features = []
try:
pe = pefile.PE(path)
if hasattr(pe, 'OPTIONAL_HEADER'):
cur = pe.OPTIONAL_HEADER
for it in cur.__keys__:
peheader_features += [cur.__getattribute__(it[0])]
if(len(peheader_features) != 30):
return [0] * 30
print(path)
return peheader_features
except pefile.PEFormatError:
return [0] * 30
def train_detector():
os.chdir(r"D:\PyCharmProjects\MiningDetection\black_fixed")
black_paths = os.listdir()
os.chdir(r"D:\PyCharmProjects\MiningDetection\white_fixed")
white_paths = os.listdir()
for i in range(len(black_paths)):
black_paths[i] = r"D:\PyCharmProjects\MiningDetection\black_fixed\\" + black_paths[i]
for i in range(len(white_paths)):
white_paths[i] = r"D:\PyCharmProjects\MiningDetection\white_fixed\\" + white_paths[i]
print("Begin Training...")
X = [get_peheader_features(path) for path in black_paths + white_paths]
y = [1 for i in range(len(black_paths))] + [0 for i in range(len(white_paths))]
classifier = RandomForestClassifier(n_estimators=500)
classifier.fit(X, y)
print("End Training...")
os.chdir(r"D:\PyCharmProjects\MiningDetection")
pickle.dump(classifier, open("train_data.pkl", "wb+"))
train_detector()
旺仔不爱牛奶
- 粉丝: 568
- 资源: 31
最新资源
- 基于Jupyter扩展的jupylet-cn项目中文翻译设计源码
- 基于Java语言的校园跳蚤市场后台管理系统设计源码
- 基于Jupyter Notebook的PYTHON项目——周某年度最骄傲之作:零挂科挑战成功设计源码
- 基于Html与Java的综合技术,打造电脑商城网站设计源码
- 基于Java语言的前后端分离投票系统设计源码
- 基于Python全栈技术的B2C在线教育商城天宫设计源码
- ubuntu20.04安装教程-ubuntu20.04安装指南:涵盖物理机和虚拟环境下的详细流程
- 基于Java注解的Emqx消息监听器设计源码及后台访问控制API
- 基于Java语言的dormitory-backend学生宿舍管理系统设计源码
- 基于Dart语言的Flutter框架设计源码镜像仓库
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
前往页