📄 bvb.cpp
字号:
#include "Globals.h"
#include <iostream>
#include <ctime>
#include <string>
#include <sstream>
#include <string>
#include <stdexcept>
#include <windows.h>
#include "Sha1.h"
using namespace std;
/*
prototypes
*/
template< class T > std::string Stringify(T x);
bool getYesNoAnswer( const string question );
string getDriveChoice( void );
int main(void)
/*
Description: Main takes no arguments, and tests the classes. It does so with a simple
menu interface
*/
{
ExeFinder F;
ExeHashStore S;
ExeHashCheck C;
int rv1, rv2, rv3, c = 0;
string HashsFileName, logFileName, driveChoice;
bool op1, op2;
cout << "BVB PROTOTYPE v2 INITIATED\n";
while( c!=3 )
/*
Main Menu Loop
*/
{
cout << "Menu:\n1 - Make Hash Backups\n2 - Check Hash Backups\n3 - Exit\n>>";
cin >> c;
while( c < 1 || c > 3)
{
cout << "try again\n>>";
cin >> c;
}
if( c == 1)
{
op1 = getYesNoAnswer("Search for exes(y/n)? ");
op2 = getYesNoAnswer("Search for dlls(y/n)? ");
if( op1 == op2 && op1 == false )
{
cout << "Invalid option combination. Using defaults...\n";
op1 = true;
}
driveChoice = getDriveChoice();
cout << "Locating Executables...\n";
rv1 = F.findAllExecutables(driveChoice, true, op1, op2);
S.setFileNamesVector(F.getExecutableVector());
cout << "Storing Hashs...\n";
HashsFileName = "hbackup" + Stringify(time(0)) + ".dat";
rv2 = S.storeAllHashes(HashsFileName);
if( rv1 == rv2 ) cout << "Success!\n";
else cout << rv1 << " " << rv2 << " -> Discrepancy!\n";
system("PAUSE");
}
else if( c == 2)
{
system("dir *.dat");
cout << "Type full filename of backup file from list above\n";
cin >> HashsFileName;
C.setExeHashFile(HashsFileName);
C.setFileNamesVector(F.getExecutableVector());
cout << "Checking Executables...\n";
rv3 = C.checkAllHashes( logFileName );
if( rv3 == 0 ) cout << "No changes detected!\n";
else if( rv3 == 1 ){
cout << rv3 << " change detected! Data can be found in " << logFileName << endl;
system(("notepad " + logFileName).c_str() );
}
else if( rv3 > 1 ){
cout << rv3 << " change detected! Data can be found in " << logFileName << endl;
system(("notepad " + logFileName).c_str() );
}
else cout << "checkAllHashs() returned errorcode " << rv3 << endl;
system("PAUSE");
}
system("cls");
}
system("PAUSE");
return 0;
}
template< class T >
std::string Stringify(T x)
/*
Description: A function to turn virtually anything passed to it into a string.
Makes use of templates
*/
{
std::ostringstream o;
o << x;
return o.str();
}
bool getYesNoAnswer( const string question )
{
/*
Description: Gets a yes or no answer to a question and returns the result
*/
char c; bool result;
cout << question;
cin >> c;
c = toupper(c);
while( c != 'Y' && c != 'N' )
{
cout << "Invalid selection, try again\n: ";
cin >> c;
c = toupper(c);
}
if( toupper(c) == 'Y' )result = true;
else result = false;
return result;
}
string getDriveChoice( void )
/*
Description: gets drive choice
*/
{
string driveChoice;
cout << "Enter drive letter followed by semicolon: ( e.g. C: ): ";
cin >> driveChoice;
if( driveChoice.size() != 2 ||
toupper(driveChoice[0]) < 'A' ||
toupper(driveChoice[0]) > 'Z' ||
driveChoice[1] != ':')
driveChoice = "C:";
return driveChoice;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -