1. 程式人生 > 其它 >C/C++ 查詢目錄指定檔案HEX特徵

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));
文章出處:https://www.cnblogs.com/lyshark
許可協議: 文章中的程式碼均為學習時整理的筆記,部落格中除去明確標註有參考文獻的文章,其他文章【均為原創】作品,轉載請務必【添加出處】,您添加出處是我創作的動力!

防惡意轉載:如果發現您在轉載時,沒有新增本人部落格連結,本人將通過爬蟲批量爬取您部落格中所有內容,打上本人原創版權水印,並進行二次發行,請相互尊重,你尊重我的勞動成果,我才會尊重你。