adding quickscan
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -24,7 +24,7 @@
|
||||
"RelativeDocumentMoniker": "client_frontend.cpp",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp",
|
||||
"RelativeToolTip": "client_frontend.cpp",
|
||||
"ViewState": "AQIAADkAAAAAAAAAAAAwwFUAAABsAAAA",
|
||||
"ViewState": "AQIAAEsAAAAAAAAAAAAAAGQAAACHAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2024-03-23T13:52:32.121Z",
|
||||
"EditorCaption": ""
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#define IDM_SCAN_FOLDER 102
|
||||
#define IDM_DEEP_SCAN_FILE 103
|
||||
#define IDM_DEEP_SCAN_FOLDER 104
|
||||
#define IDM_QUICK_SCAN 105
|
||||
|
||||
|
||||
std::wstring string_to_widestring(const std::string& str) {
|
||||
@@ -91,13 +92,13 @@ void scan_file(HWND hWndTextField, const std::string& filePath, bool deep) {
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
answered = true;
|
||||
update_textfield(hWndTextField, "Error: Unable to talk to daemon!\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
}
|
||||
inputFile.close();
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
@@ -167,7 +168,7 @@ void scan_folder(HWND hProgressBar,HWND hWndTextField, const std::string& folder
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
}
|
||||
else if (status == "progress") {
|
||||
std::string progress;
|
||||
@@ -196,13 +197,91 @@ void scan_folder(HWND hProgressBar,HWND hWndTextField, const std::string& folder
|
||||
}
|
||||
update_textfield(hWndTextField, "Folder scan completed\r\n");
|
||||
update_textfield(hWndTextField, "Number of infected files: " + std::to_string(num_of_found) + "\r\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
SendMessage(hProgressBar, PBM_SETPOS, 100, 0);
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
void quick_scan(HWND hProgressBar, HWND hWndTextField) {
|
||||
//set progress bar to 0
|
||||
SendMessage(hProgressBar, PBM_SETPOS, 0, 0);
|
||||
int num_of_found = 0;
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
|
||||
update_textfield(hWndTextField, "Running quick scan\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "quick_scan \"" << "_._" << "\"";
|
||||
outputFile.close();
|
||||
}
|
||||
else {
|
||||
update_textfield(hWndTextField, "Error: Unable to talk to daemon!\n");
|
||||
return;
|
||||
}
|
||||
|
||||
while (!answered) {
|
||||
// Wait for answer in file
|
||||
std::ifstream inputFile(ANSWER_COM_PATH);
|
||||
// The structure of the answer file is as follows:
|
||||
// found/not_found
|
||||
// filepath
|
||||
// hash
|
||||
// action_taken/no_action_taken
|
||||
if (inputFile.is_open()) {
|
||||
std::string status, scannedFilePath, hash, action;
|
||||
while (!inputFile.eof()) {
|
||||
if (inputFile >> status) {
|
||||
if (status == "found" || status == "not_found") {
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile.ignore(1); // Ignore starting double quote
|
||||
std::getline(inputFile, scannedFilePath, '\"'); // Read until closing double quote
|
||||
inputFile.ignore(1); // Ignore space between filepath and hash
|
||||
inputFile.ignore(1); // Ignore starting double quote
|
||||
std::getline(inputFile, hash, ' '); // Read until space
|
||||
std::getline(inputFile, action); // Read until end of line
|
||||
|
||||
//answered = true;
|
||||
|
||||
if (status == "found") {
|
||||
update_textfield(hWndTextField, "Virus found in file: " + scannedFilePath + "\r\n");
|
||||
update_textfield(hWndTextField, "Hash: " + hash + "\r\n");
|
||||
update_textfield(hWndTextField, "Action taken: " + action + "\r\n");
|
||||
num_of_found++;
|
||||
}
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
}
|
||||
else if (status == "start") {
|
||||
std::string all_files;
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile >> all_files;
|
||||
update_textfield(hWndTextField, "Quick scan started\r\n\r\n");
|
||||
}
|
||||
else if (status == "end") {
|
||||
answered = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
std::ofstream(ANSWER_COM_PATH);//clear the file
|
||||
Sleep(1000);//only see for new entrys ~ once a second
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
update_textfield(hWndTextField, "Quick scan completed\r\n");
|
||||
update_textfield(hWndTextField, "Number of infected files: " + std::to_string(num_of_found) + "\r\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------------------------------------------------\r\n");
|
||||
SendMessage(hProgressBar, PBM_SETPOS, 100, 0);
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
std::string getFolderPath(HWND hWnd) {
|
||||
std::wstring selectedFolderPath;
|
||||
@@ -223,8 +302,6 @@ std::string getFolderPath(HWND hWnd) {
|
||||
if (pidlSelected != NULL) {
|
||||
SHGetPathFromIDList(pidlSelected, selectedPath);
|
||||
|
||||
// Convert TCHAR array to std::string
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
selectedFolderPath = selectedPath;
|
||||
|
||||
// Free the PIDL
|
||||
@@ -238,7 +315,9 @@ std::string getFolderPath(HWND hWnd) {
|
||||
// Uninitialize COM
|
||||
CoUninitialize();
|
||||
|
||||
return std::string(selectedFolderPath.begin(), selectedFolderPath.end());
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
std::string narrowSelectedFolder = converter.to_bytes(selectedFolderPath);
|
||||
return narrowSelectedFolder;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
@@ -273,6 +352,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 130, 150, 30, hWnd, (HMENU)IDM_DEEP_SCAN_FOLDER, GetModuleHandle(NULL), NULL);
|
||||
|
||||
//create the quick scan button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Quick Scan",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 170, 150, 30, hWnd, (HMENU)IDM_QUICK_SCAN, GetModuleHandle(NULL), NULL);
|
||||
|
||||
// Create a multi-line edit control for displaying text
|
||||
hWndTextField = CreateWindowEx(WS_EX_CLIENTEDGE, L"EDIT", NULL,
|
||||
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY,
|
||||
@@ -319,7 +403,8 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (GetOpenFileName(&ofn) == TRUE) {
|
||||
std::wstring selectedFile = ofn.lpstrFile; // Use std::wstring for wide characters
|
||||
std::string narrowSelectedFile(selectedFile.begin(), selectedFile.end());
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
std::string narrowSelectedFile = converter.to_bytes(selectedFile);
|
||||
std::thread(scan_file, hWndTextField, narrowSelectedFile,0).detach();
|
||||
}
|
||||
}
|
||||
@@ -354,8 +439,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
|
||||
if (GetOpenFileName(&ofn) == TRUE) {
|
||||
std::wstring selectedFile = ofn.lpstrFile; // Use std::wstring for wide characters
|
||||
std::string narrowSelectedFile(selectedFile.begin(), selectedFile.end());
|
||||
std::thread(scan_file, hWndTextField, narrowSelectedFile, 1).detach();
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter;
|
||||
std::string narrowSelectedFile = converter.to_bytes(selectedFile);
|
||||
std::thread(scan_file, hWndTextField, narrowSelectedFile, 0).detach();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -368,6 +454,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if(selected_folder!="")
|
||||
std::thread(scan_folder,hProgressBar, hWndTextField, selected_folder,1).detach();
|
||||
}
|
||||
break;
|
||||
case IDM_QUICK_SCAN:
|
||||
{
|
||||
std::thread(quick_scan, hProgressBar, hWndTextField).detach();
|
||||
}
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -1,36 +1,3 @@
|
||||
client_frontend.cpp
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility(4537,18): warning C4244: "=": Konvertierung von "wchar_t" in "char", möglicher Datenverlust
|
||||
(Quelldatei „client_frontend.cpp“ wird kompiliert)
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xutility(4537,18):
|
||||
der Vorlageninstanziierungskontext (der älteste zuerst) ist
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend.cpp(241,23):
|
||||
Siehe Verweis auf die gerade kompilierte Instanziierung "std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string<std::_String_iterator<std::_String_val<std::_Simple_types<_Elem>>>,0>(_Iter,_Iter,const _Alloc &)" der Funktions-Vorlage.
|
||||
with
|
||||
[
|
||||
_Elem=wchar_t,
|
||||
_Iter=std::_String_iterator<std::_String_val<std::_Simple_types<wchar_t>>>,
|
||||
_Alloc=std::allocator<char>
|
||||
]
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend.cpp(241,5):
|
||||
Ersten Verweis auf "std::basic_string<char,std::char_traits<char>,std::allocator<char>>::basic_string" in "getFolderPath" anzeigen
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xstring(2600,17):
|
||||
Siehe Verweis auf die gerade kompilierte Instanziierung "void std::basic_string<char,std::char_traits<char>,std::allocator<char>>::_Construct_from_iter<wchar_t*,wchar_t*,_Size_type>(_Iter,const _Sent,_Size)" der Funktions-Vorlage.
|
||||
with
|
||||
[
|
||||
_Size_type=unsigned __int64,
|
||||
_Iter=wchar_t *,
|
||||
_Sent=wchar_t *,
|
||||
_Size=unsigned __int64
|
||||
]
|
||||
C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.39.33519\include\xstring(2756,18):
|
||||
Siehe Verweis auf die gerade kompilierte Instanziierung "_OutIt *std::_Copy_n_unchecked4<wchar_t*,_Size,char*>(_InIt,_SizeTy,_OutIt)" der Funktions-Vorlage.
|
||||
with
|
||||
[
|
||||
_OutIt=char *,
|
||||
_Size=unsigned __int64,
|
||||
_InIt=wchar_t *,
|
||||
_SizeTy=unsigned __int64
|
||||
]
|
||||
|
||||
client_frontend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\x64\Debug\client_frontend.exe
|
||||
C:\vcpkg\vcpkg-2023.08.09\scripts\buildsystems\msbuild\vcpkg.targets(228,5): warning : [vcpkg] Failed to gather app local DLL dependencies, program may not run. Set VcpkgApplocalDeps to false in your project file to suppress this warning. PowerShell arguments: -ExecutionPolicy Bypass -noprofile -File "C:\vcpkg\vcpkg-2023.08.09\scripts\buildsystems\msbuild\applocal.ps1" "C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\x64\Debug\client_frontend.exe" "C:\vcpkg\vcpkg-2023.08.09\installed\x64-windows\debug\bin" "client_frontend\x64\Debug\client_frontend.tlog\client_frontend.write.1u.tlog" "client_frontend\x64\Debug\vcpkg.applocal.log"
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user