exehashstore.cpp

来自「BVB杀毒软件的引擎代码,可以学习这种杀毒软件的核心 帮助自己设计杀毒软件」· C++ 代码 · 共 71 行

CPP
71
字号
#include <string>
 #include <vector>
 #include <fstream>
 
 
 
 using namespace std;
 
 #include "ExeHashStore.h"
 #include "Globals.h"
 #include "Sha1.h"
 
 #ifdef WRITE_PROGRESS_TO_CONSOLE
 #include <iostream>
 #endif
 
 string ExeHashStore::getExecutableHash( string exePath )
 /*
 Description: Copies the first few hundred bytes of the executable described by exePath and returns it as a string
 */
 {
 string hash;
 CSHA1 hasher;
 
 hasher.HashFile( exePath.c_str() );
 hasher.Final();
 
 hasher.ReportHash( hash );
 
 return hash;
 }
 
 ExeHashStore::ExeHashStore( vector<string> V )
 {
 FileNames = V;
 }
 
 ExeHashStore::ExeHashStore( void )
 {
 
 }
 
 void ExeHashStore::setFileNamesVector( vector<string> V )
 {
 FileNames = V;
 }
 
 int ExeHashStore::storeAllHashes( string TargetFileName )
 /*
 Description: Stores all Hashs in the member vector FileNames to the file described by TargetFileName.
 */
 {
 
 ofstream TargetFileHandle( TargetFileName.c_str(), ios_base::trunc );
 unsigned int i;
 
 for(i=0;i<FileNames.size() && TargetFileHandle.good();i++)
 {
 TargetFileHandle 
 << i << endl
 << FileNames[i] << endl
 << getExecutableHash( FileNames[i] ) << endl;
 #ifdef WRITE_PROGRESS_TO_CONSOLE
 cout << FileNames[i] << endl;
 #endif
 }
 
 TargetFileHandle.close();
 
 return i;
 } 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?