• 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<<"
    *****************"<<endl;
    		}
    
        } while (!_findnext(handle,&fileinfo));
    

    版权声明: 本博客,文章与代码均为学习时整理的笔记,博客中除去明确标注有参考文献的文章,其他文章【均为原创】作品,转载请务必【添加出处】,您添加出处是我创作的动力!

    警告:如果您恶意转载本人文章,则您的整站文章,将会变为我的原创作品,请相互尊重!
  • 相关阅读:
    web api的新玩法
    发送邮件的小功能(.net core 版)
    Docker入门命令备份
    在控制台进行依赖注入(DI in Console)
    .net Core 2.0使用NLog
    .Net Core下使用WCF
    C#枚举最优雅的用法
    Jquery.Ajax的使用方法
    PuTTY+Xming实现X11的ssh转发
    使用XMing+putty运行linux图形界面程序
  • 原文地址:https://www.cnblogs.com/LyShark/p/15020073.html
Copyright © 2020-2023  润新知