统计c盘的PE文件的个数 (遍历所有文件)

PE文件有    if(tmp=="exe"||tmp=="sys"||tmp=="dll"||tmp=="ocx"||tmp=="com") 这几种格式。

代码如下

View Code
#pragma warning (disable:4786)
#include <iostream>
#include <io.h> // _findfirst() _findnext()
#include <string.h> //strcat()
#include <stdio.h>//gets() puts()
#include <string>
#include <cstring>
#include <direct.h> //_chdir() _getcwd()
#include <vector>
using namespace std;
vector<string>PE;
bool Judge(string path)
{
int i;
if(path.size()<3)return 0;
string tmp;
for(i=path.size()-3;i<path.size();i++)
{
tmp+=path[i];
}
for(i=0;i<tmp.size();i++)
{
if(tmp[i]>='A'&&tmp[i]<='Z')
{
tmp[i]=tmp[i]-'A'+'a';
}
}
if(tmp=="exe"||tmp=="sys"||tmp=="dll"||tmp=="ocx"||tmp=="com") return 1;
else return 0;
}
void DispSubFiles()//遍历目录,包括子目录
{
long handle;
char path[_MAX_PATH];
struct _finddata_t t;
handle=_findfirst("*",&t);
if(handle==-1)//如果handle=-1,表示目录不存在
{
return ;
}
if(t.attrib & _A_SUBDIR)//1. 判断第一个文件:如果为目录
{
if(t.name[0]!='.')//如果目录非空
{
_chdir(t.name);
_getcwd(path,_MAX_PATH);
//puts(path);
DispSubFiles();//递归调用
_chdir("..");//当所有文件遍历完毕,返回上级目录
}
//如果为空目录,即t.name为"."或"..",则不输出
}
else//如果第一个是文件,不为目录
{
_getcwd(path,_MAX_PATH);
strcat(path,"\\");
strcat(path,t.name);
string tmp=path;
PE.push_back(path);

}
while(!(_findnext(handle,&t)))//2. 判断下一个文件,直至遍历所有文件
{
if(t.attrib & _A_SUBDIR)//如果第一个文件为目录
{
if(t.name[0]!='.')//如果目录非空
{
_chdir(t.name);
_getcwd(path,_MAX_PATH);
//puts(path);
DispSubFiles();//递归调用
_chdir("..");//当所有文件遍历完毕,返回上级目录
}
//如果为空目录,即t.name为"."或"..",则不输出
}
else//如果是文件,不为目录,显示文件完整路径
{
_getcwd(path,_MAX_PATH);//获取文件路径
strcat(path,"\\");
strcat(path,t.name);//文件完整路径
string tmp=path;
if(Judge(path)){
//puts(path);//输出路径
PE.push_back(tmp);
}

}
}
_findclose(handle);
}
void main()
{
char dirc[_MAX_PATH];
cout<<"请输入要查找的目录(如:E:\\):"<<endl;
cin>>dirc;
_chdir(dirc);//打开指定目录
DispSubFiles();//遍历所有目录及文件
printf("%d\n",PE.size());
}

统计C盘结果如下:

总文件:192006

PE文件:17386

转载于:https://www.cnblogs.com/zhxfl/archive/2011/11/11/2245143.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
搜索任意目录中的所有文件,并按照PE文件和非PE文件分类,并把PE文件按照PE文件头16字节分类。 结果如下: NO. PE_Header_HEX Number PE_Header_ASCII 1 4D 5A 90 00 03 00 11 11 11 11 10 00 FF FF 00 00 1 MZ? 2 4D 5A 90 00 03 00 01 11 11 11 11 00 FF FF 00 00 1 MZ? 3 4D 5A 90 00 03 00 00 00 11 11 10 00 FF FF 00 00 1 MZ? 4 4D 5A 90 00 03 00 00 00 01 11 00 00 FF FF 00 00 1 MZ? 5 4D 5A 90 00 03 00 00 01 11 10 00 00 FF FF 00 00 1 MZ? 6 4D 5A 90 00 03 00 00 00 11 11 11 10 FF FF 00 00 1 MZ? 7 4D 5A 90 11 11 11 11 10 04 00 00 00 FF FF 00 00 1 MZ? 8 4D 5A 90 00 03 00 11 11 04 01 10 00 FF 11 00 00 1 MZ? 9 4D 5A 90 01 13 00 00 00 04 00 00 01 11 FF 00 00 1 MZ? 10 4D 5A 90 00 03 00 00 01 11 11 11 11 1F FF 00 00 1 MZ? 11 4D 5A 44 56 41 50 41 11 11 11 14 6C 6C 00 6F 6C 1 MZDVAPA 12 4D 5A 72 75 6E 20 71 11 11 11 12 20 57 69 6E 33 1 MZrun qWin3 13 4D 5A 90 00 11 11 00 00 04 00 00 00 FF FF 00 00 1 MZ? 14 4D 5A 90 00 03 00 00 00 04 00 00 01 11 11 11 10 1 MZ? 15 4D 5A 50 00 02 00 00 00 04 00 0F 00 FF FF 01 10 1 MZP 16 4D 5A 50 00 02 00 00 10 04 11 11 00 FF FF 00 00 1 MZP 17 4D 5A 72 75 6E 20 75 E1 11 11 12 20 57 69 6E 33 1 MZrun u?Win3 18 4D 5A 90 54 68 69 73 20 70 72 6F 67 72 61 6D 20 2 MZ怲hiprogram 19 4D 5A D2 00 19 00 02 00 20 00 00 00 FF FF AD 02 1 MZ? 20 4D 5A 47 44 49 33 32 2E 64 6C 6C 00 55 53 45 52 2 MZGDI32.dll 21 4D 5A 90 00 03 00 02 22 22 22 22 20 FF FF 00 00 1 MZ? 22 4D 5A 50 00 02 00 00 00 04 00 0F 00 FF FF 00 00 2 MZP 23 4D 5A 4B 45 52 4E 45 4C 33 32 2E 64 6C 6C 00 6F 7MZKERNEL32.dll

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值