C/C++ 查找指定文件HEX特征

	// 获取 Temp 目录路径
	TCHAR lpTempPathBuffer[MAX_PATH];
	GetTempPath(MAX_PATH,lpTempPathBuffer);

	// 拼接字符窜
    std::string inPath = lpTempPathBuffer;
	inPath.append("\\*");

    // 遍历 Temp 目录下的文件
    struct _finddata_t fileinfo;
    long handle = _findfirst(inPath.c_str(),&fileinfo);
    if(handle == -1){cout << "_findfirst 失败" << endl;}
    do{
		// cout << fileName << endl;
		// 筛选 .tmp 后缀的文件
		string fileName = fileinfo.name;
		if(fileName.find(".tmp")!=fileName.npos){
			//cout << fileName << endl;
			// 获取文件全路径
			string fullPath = lpTempPathBuffer;
			fullPath += fileName;
			cout << fullPath << endl;

			// 打开文件
			ifstream fin(fullPath,ios::binary);
			if(!fin){cout<<"打开文件失败"<<endl;}
	
			// 设置文件指针位置为 0xA00,当然也可以设置为其他的地方
			fin.seekg(0xa00,ios::beg);
			char buffer[16];
			fin.read(buffer,16*sizeof(char));
	
			// 读取内容
			for(int i=0;i<16;i++){
				cout << hex << (unsigned short)((unsigned char)buffer[i]) << " ";
				
				// 对比你自己的特征数组(略)
				// ...
				// ...
			}
			
			cout<<"\n*****************"<<endl;
		}

    } while (!_findnext(handle,&fileinfo));
posted @ 2021-07-16 14:42  lyshark  阅读(215)  评论(0编辑  收藏  举报

loading... | loading...
博客园 - 开发者的网上家园