updating frontend
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -3,28 +3,8 @@
|
||||
"WorkspaceRootPath": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:ui.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:choose_element.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:choose_element.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\id.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:id.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{644C9824-2298-46C6-9A62-7E080C98A0BB}|client_frontend.vcxproj|solutionrelative:ui.h||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
"AbsoluteMoniker": "D:0:0:{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}|client_frontend.vcxproj|solutionrelative:client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
@@ -34,84 +14,19 @@
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 4,
|
||||
"SelectedChildIndex": 0,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 2,
|
||||
"Title": "choose_element.h",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.h",
|
||||
"RelativeDocumentMoniker": "choose_element.h",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.h",
|
||||
"RelativeToolTip": "choose_element.h",
|
||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAUAAAAGAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||
"WhenOpened": "2024-03-14T17:06:27.941Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "choose_element.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.cpp",
|
||||
"RelativeDocumentMoniker": "choose_element.cpp",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\choose_element.cpp",
|
||||
"RelativeToolTip": "choose_element.cpp",
|
||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAABcAAABJAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2024-03-14T17:06:16.884Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 4,
|
||||
"Title": "id.h",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\id.h",
|
||||
"RelativeDocumentMoniker": "id.h",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\id.h",
|
||||
"RelativeToolTip": "id.h",
|
||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAEAAAAQAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||
"WhenOpened": "2024-03-14T16:31:43.692Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 5,
|
||||
"Title": "ui.h",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.h",
|
||||
"RelativeDocumentMoniker": "ui.h",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.h",
|
||||
"RelativeToolTip": "ui.h",
|
||||
"ViewState": "AQIAAAAAAAAAAAAAAAAAAAMAAAAQAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||
"WhenOpened": "2024-03-14T16:28:38.361Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "ui.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.cpp",
|
||||
"RelativeDocumentMoniker": "ui.cpp",
|
||||
"ToolTip": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\ui.cpp",
|
||||
"RelativeToolTip": "ui.cpp",
|
||||
"ViewState": "AQIAACoAAAAAAAAAAAAwwC8AAAAwAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2024-03-14T16:28:29.863Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 3,
|
||||
"Title": "client_frontend.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp",
|
||||
"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": "AQIAAHsAAAAAAAAAAAAAAJwAAAA3AAAA",
|
||||
"ViewState": "AQIAAA4BAAAAAAAAAAAAADYBAAAQAAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2024-03-14T16:22:29.931Z",
|
||||
"WhenOpened": "2024-03-23T13:52:32.121Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}|client_frontend.vcxproj|C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}|client_frontend.vcxproj|solutionrelative:client_frontend.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": 0,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "client_frontend.cpp",
|
||||
"DocumentMoniker": "C:\\Users\\janis\\Documents\\Projekte_mit_c\\ma\\ma\\src\\client_frontend\\client_frontend.cpp",
|
||||
"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": "AQIAAIQAAAAAAAAAAAAAALAAAAA7AAAA",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2024-03-23T13:52:32.121Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
#include "choose_element.h"
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
std::wstring open_file(HWND hWnd)
|
||||
{
|
||||
OPENFILENAME ofn;
|
||||
WCHAR szFile[MAX_PATH] = L"";
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hWnd;
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.lpstrFile[0] = '\0';
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = L"All Files\0*.*\0"; // Filter for all files
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.lpstrFileTitle = NULL;
|
||||
ofn.nMaxFileTitle = 0;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||
|
||||
if (GetOpenFileName(&ofn) == TRUE)
|
||||
{
|
||||
// User selected a file, 'szFile' contains the selected file path
|
||||
return std::wstring(szFile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// User canceled the dialog
|
||||
//MessageBox(hWnd, L"File selection canceled.", L"Canceled", MB_OK | MB_ICONEXCLAMATION);
|
||||
return L"cancel";
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
#pragma once
|
||||
#include "id.h"
|
||||
#include <Windows.h>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
std::wstring open_file(HWND hWnd);
|
||||
@@ -1,210 +1,380 @@
|
||||
// client_frontend.cpp : Definiert den Einstiegspunkt für die Anwendung.
|
||||
//
|
||||
#include <windows.h>
|
||||
#include "framework.h"
|
||||
#include "client_frontend.h"
|
||||
#include "ui.h"
|
||||
#include "id.h"
|
||||
#include "choose_element.h"
|
||||
#define MAX_LOADSTRING 100
|
||||
#include <Windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "../client_backend/well_known.h"
|
||||
|
||||
#define IDM_SCAN_FILE 101
|
||||
#define IDM_SCAN_FOLDER 102
|
||||
|
||||
|
||||
// Globale Variablen:
|
||||
HINSTANCE hInst; // Aktuelle Instanz
|
||||
WCHAR szTitle[MAX_LOADSTRING]; // Titelleistentext
|
||||
WCHAR szWindowClass[MAX_LOADSTRING]; // Der Klassenname des Hauptfensters.
|
||||
|
||||
// Vorwärtsdeklarationen der in diesem Codemodul enthaltenen Funktionen:
|
||||
ATOM frontend_class(HINSTANCE hInstance);
|
||||
BOOL InitInstance(HINSTANCE, int);
|
||||
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
|
||||
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
|
||||
|
||||
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
_In_opt_ HINSTANCE hPrevInstance,
|
||||
_In_ LPWSTR lpCmdLine,
|
||||
_In_ int nCmdShow)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
// TODO: Hier Code einfügen.
|
||||
|
||||
// Globale Zeichenfolgen initialisieren
|
||||
LoadStringW(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
|
||||
LoadStringW(hInstance, IDC_CLIENTFRONTEND, szWindowClass, MAX_LOADSTRING);
|
||||
frontend_class(hInstance);
|
||||
|
||||
// Anwendungsinitialisierung ausführen:
|
||||
if (!InitInstance (hInstance, nCmdShow))
|
||||
{
|
||||
return FALSE;
|
||||
std::wstring string_to_widestring(const std::string& str) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
void send_command(const std::string& command) {
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << command;
|
||||
outputFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
HACCEL hAccelTable = LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_CLIENTFRONTEND));
|
||||
// Function to update the content of the text field with the provided text
|
||||
void update_textfield(HWND hWndTextField, const std::string& text) {
|
||||
// Get the current text length
|
||||
int textLength = GetWindowTextLength(hWndTextField);
|
||||
|
||||
MSG msg;
|
||||
// Set the selection to the end of the text field
|
||||
SendMessage(hWndTextField, EM_SETSEL, textLength, textLength);
|
||||
|
||||
// Hauptnachrichtenschleife:
|
||||
while (GetMessage(&msg, nullptr, 0, 0))
|
||||
{
|
||||
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
// Append the new text
|
||||
SendMessage(hWndTextField, EM_REPLACESEL, FALSE, (LPARAM)string_to_widestring(text).c_str());
|
||||
}
|
||||
|
||||
void scan_file(HWND hWndTextField, const std::string& filePath) {
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
// Display the scanned file path in the window
|
||||
update_textfield(hWndTextField, "Scanning file: " + filePath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
//printf("%d\n",send_to_pipe("scanfile \"" + filePath + "\""));
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfile \"" << filePath << "\"";
|
||||
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;
|
||||
if (inputFile >> status) {
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile.ignore(1); // Ignore starting double quote
|
||||
if (status == "found" || status == "not_found") {
|
||||
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, "File: " + scannedFilePath + " is infected\r\n");
|
||||
update_textfield(hWndTextField, "Hash: " + hash + "\r\n");
|
||||
update_textfield(hWndTextField, "Action taken: " + action + "\r\n");
|
||||
|
||||
}
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
answered = true;
|
||||
update_textfield(hWndTextField, "Error: Unable to talk to daemon!\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------\n");
|
||||
}
|
||||
inputFile.close();
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
// Function to simulate folder scanning
|
||||
void scan_folder(HWND hProgressBar,HWND hWndTextField, const std::string& folderPath) {
|
||||
//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);
|
||||
// Display the scanned folder path in the window
|
||||
update_textfield(hWndTextField, "Scanning folder: " + folderPath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfolder \"" << folderPath << "\"";
|
||||
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, "File: " + scannedFilePath + " is infected\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 == "progress") {
|
||||
std::string progress;
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile >> progress;
|
||||
SendMessage(hProgressBar, PBM_SETPOS, std::stoi(progress), 0);
|
||||
|
||||
}
|
||||
else if (status == "start") {
|
||||
std::string all_files;
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile >> all_files;
|
||||
update_textfield(hWndTextField, "Folder scan started with "+ all_files +" files queued for scan\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, "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");
|
||||
SendMessage(hProgressBar, PBM_SETPOS, 100, 0);
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string getFolderPath(HWND hWnd) {
|
||||
std::wstring selectedFolderPath;
|
||||
|
||||
// Initialize COM
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
// Display the folder picker dialog
|
||||
BROWSEINFO browseInfo = { 0 };
|
||||
TCHAR selectedPath[MAX_PATH];
|
||||
browseInfo.hwndOwner = hWnd; // Set the owner window
|
||||
browseInfo.pidlRoot = NULL; // Start from the desktop
|
||||
browseInfo.pszDisplayName = selectedPath;
|
||||
browseInfo.lpszTitle = TEXT("Select a folder");
|
||||
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
|
||||
LPITEMIDLIST pidlSelected = SHBrowseForFolder(&browseInfo);
|
||||
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
|
||||
IMalloc* pMalloc;
|
||||
if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
|
||||
pMalloc->Free(pidlSelected);
|
||||
pMalloc->Release();
|
||||
}
|
||||
}
|
||||
|
||||
return (int) msg.wParam;
|
||||
// Uninitialize COM
|
||||
CoUninitialize();
|
||||
|
||||
return std::string(selectedFolderPath.begin(), selectedFolderPath.end());
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// FUNKTION: MyRegisterClass()
|
||||
//
|
||||
// ZWECK: Registriert die Fensterklasse.
|
||||
//
|
||||
ATOM frontend_class(HINSTANCE hInstance)
|
||||
{
|
||||
WNDCLASSEXW wcex;
|
||||
|
||||
wcex.cbSize = sizeof(WNDCLASSEX);
|
||||
|
||||
wcex.style = CS_HREDRAW | CS_VREDRAW;
|
||||
wcex.lpfnWndProc = WndProc;
|
||||
wcex.cbClsExtra = 0;
|
||||
wcex.cbWndExtra = 0;
|
||||
wcex.hInstance = hInstance;
|
||||
wcex.hIcon = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_CLIENTFRONTEND));
|
||||
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
|
||||
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
|
||||
wcex.lpszMenuName = MAKEINTRESOURCEW(IDC_CLIENTFRONTEND);
|
||||
wcex.lpszClassName = szWindowClass;
|
||||
wcex.hIconSm = LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
|
||||
|
||||
return RegisterClassExW(&wcex);
|
||||
}
|
||||
|
||||
//
|
||||
// FUNKTION: InitInstance(HINSTANCE, int)
|
||||
//
|
||||
// ZWECK: Speichert das Instanzenhandle und erstellt das Hauptfenster.
|
||||
//
|
||||
// KOMMENTARE:
|
||||
//
|
||||
// In dieser Funktion wird das Instanzenhandle in einer globalen Variablen gespeichert, und das
|
||||
// Hauptprogrammfenster wird erstellt und angezeigt.
|
||||
//
|
||||
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
{
|
||||
hInst = hInstance; // Instanzenhandle in der globalen Variablen speichern
|
||||
|
||||
HWND hWnd = CreateWindowW(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, nullptr, nullptr, hInstance, nullptr);
|
||||
|
||||
if (!hWnd)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
//
|
||||
// FUNKTION: WndProc(HWND, UINT, WPARAM, LPARAM)
|
||||
//
|
||||
// ZWECK: Verarbeitet Meldungen für das Hauptfenster.
|
||||
//
|
||||
// WM_COMMAND - Verarbeiten des Anwendungsmenüs
|
||||
// WM_PAINT - Darstellen des Hauptfensters
|
||||
// WM_DESTROY - Ausgeben einer Beendenmeldung und zurückkehren
|
||||
//
|
||||
//
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
int windowWidth=0;
|
||||
int windowHeight=0;
|
||||
RECT clientRect;
|
||||
GetClientRect(hWnd, &clientRect);
|
||||
windowWidth = clientRect.right - clientRect.left;
|
||||
windowHeight = clientRect.bottom - clientRect.top;
|
||||
switch (message)
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
static HWND hWndTextField;
|
||||
static HWND hProgressBar;
|
||||
static HBRUSH hBackgroundBrush = CreateSolidBrush(RGB(255, 255, 255)); // White color
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
int width = rect.right - rect.left;
|
||||
int height = rect.bottom - rect.top;
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
{
|
||||
|
||||
// Create the "Scan File" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan File",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 10, 100, 30, hWnd, (HMENU)IDM_SCAN_FILE, GetModuleHandle(NULL), NULL);
|
||||
|
||||
// Create the "Scan Folder" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan Folder",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 50, 100, 30, hWnd, (HMENU)IDM_SCAN_FOLDER, 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,
|
||||
140, 10, width-140-20, height-10-50, hWnd, NULL, NULL, NULL);
|
||||
update_textfield(hWndTextField, "Welcome to Cyberhex endpoint protection!\r\n");
|
||||
|
||||
hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
|
||||
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
|
||||
140, height-40, 200, 20, hWnd, NULL, NULL, NULL);
|
||||
SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
||||
SendMessage(hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
}
|
||||
break;
|
||||
case WM_SIZE:
|
||||
{
|
||||
// Resize the text field to fit the window
|
||||
MoveWindow(hWndTextField, 140, 10, width - 140 - 20, height - 10 - 50, TRUE);
|
||||
MoveWindow(hProgressBar, 140, height - 40, 200, 20, TRUE);
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
// Menüauswahl analysieren:
|
||||
switch (wmId)
|
||||
// Parse the menu selections:
|
||||
switch (wmId) {
|
||||
case IDM_SCAN_FILE:
|
||||
{
|
||||
case IDM_ABOUT:
|
||||
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
|
||||
break;
|
||||
case IDM_EXIT:
|
||||
DestroyWindow(hWnd);
|
||||
break;
|
||||
case ID_HOME_BUTTON: // Handle the home button click
|
||||
//set page to 0
|
||||
ui_clear();
|
||||
ui_display_page(0, windowWidth, windowHeight, hWnd);
|
||||
break;
|
||||
case ID_SCAN_FILE_BUTTON: // Handle the scan file button click
|
||||
//set page to 1
|
||||
ui_clear();
|
||||
ui_display_page(1, windowWidth, windowHeight, hWnd);
|
||||
break;
|
||||
// Open file dialog to select a file
|
||||
// Call scan_file function in a separate thread
|
||||
OPENFILENAME ofn;
|
||||
WCHAR szFile[MAX_PATH] = L""; // Use WCHAR for Unicode compatibility
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hWnd;
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.lpstrFile[0] = L'\0'; // Use wide character constant L'\0'
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = L"All Files\0*.*\0"; // Use wide character string literal L""
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.lpstrFileTitle = NULL;
|
||||
ofn.lpstrInitialDir = NULL;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||
|
||||
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).detach();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IDM_SCAN_FOLDER:
|
||||
{
|
||||
// Open folder picker dialog
|
||||
// Call scan_folder function in a separate thread
|
||||
std::string selected_folder = getFolderPath(hWnd);
|
||||
if(selected_folder!="")
|
||||
std::thread(scan_folder,hProgressBar, hWndTextField, selected_folder).detach();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
// TODO: Zeichencode, der hdc verwendet, hier einfügen...
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
FillRect(hdc, &rect, hBackgroundBrush); // Fill the entire client area with white color
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_CREATE:
|
||||
{
|
||||
//ui_create();
|
||||
ui_display_page(0, windowWidth, windowHeight, hWnd);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
case WM_SIZE:
|
||||
//ui_resize();
|
||||
ui_clear();
|
||||
ui_display_page(0, windowWidth, windowHeight, hWnd);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Meldungshandler für Infofeld.
|
||||
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(lParam);
|
||||
switch (message)
|
||||
{
|
||||
case WM_INITDIALOG:
|
||||
return (INT_PTR)TRUE;
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
const wchar_t CLASS_NAME[] = L"Cyberhex endpoint protection frontend";
|
||||
|
||||
case WM_COMMAND:
|
||||
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
|
||||
{
|
||||
EndDialog(hDlg, LOWORD(wParam));
|
||||
return (INT_PTR)TRUE;
|
||||
}
|
||||
break;
|
||||
WNDCLASS wc = { };
|
||||
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
HWND hWnd = CreateWindowEx(
|
||||
0,
|
||||
CLASS_NAME,
|
||||
L"Cyberhex endpoint protection",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
640,
|
||||
480,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL
|
||||
);
|
||||
|
||||
|
||||
if (hWnd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
return (INT_PTR)FALSE;
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
MSG msg = { };
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
368
src/client_frontend/client_frontend.cpp~RF8ecc27.TMP
Normal file
368
src/client_frontend/client_frontend.cpp~RF8ecc27.TMP
Normal file
@@ -0,0 +1,368 @@
|
||||
#include <Windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "../client_backend/well_known.h"
|
||||
|
||||
#define IDM_SCAN_FILE 101
|
||||
#define IDM_SCAN_FOLDER 102
|
||||
|
||||
|
||||
std::wstring string_to_widestring(const std::string& str) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
void send_command(const std::string& command) {
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << command;
|
||||
outputFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Function to update the content of the text field with the provided text
|
||||
void update_textfield(HWND hWndTextField, const std::string& text) {
|
||||
// Get the current text length
|
||||
int textLength = GetWindowTextLength(hWndTextField);
|
||||
|
||||
// Set the selection to the end of the text field
|
||||
SendMessage(hWndTextField, EM_SETSEL, textLength, textLength);
|
||||
|
||||
// Append the new text
|
||||
SendMessage(hWndTextField, EM_REPLACESEL, FALSE, (LPARAM)string_to_widestring(text).c_str());
|
||||
}
|
||||
|
||||
void scan_file(HWND hWndTextField, const std::string& filePath) {
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
// Display the scanned file path in the window
|
||||
update_textfield(hWndTextField, "Scanning file: " + filePath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
//printf("%d\n",send_to_pipe("scanfile \"" + filePath + "\""));
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfile \"" << filePath << "\"";
|
||||
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;
|
||||
if (inputFile >> status) {
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile.ignore(1); // Ignore starting double quote
|
||||
if (status == "found" || status == "not_found") {
|
||||
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, "File: " + scannedFilePath + " is infected\r\n");
|
||||
update_textfield(hWndTextField, "Hash: " + hash + "\r\n");
|
||||
update_textfield(hWndTextField, "Action taken: " + action + "\r\n");
|
||||
|
||||
}
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
answered = true;
|
||||
update_textfield(hWndTextField, "Error: Unable to talk to daemon!\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------\n");
|
||||
}
|
||||
inputFile.close();
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
// Function to simulate folder scanning
|
||||
void scan_folder(HWND hProgressBar,HWND hWndTextField, const std::string& folderPath) {
|
||||
int num_of_found = 0;
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
// Display the scanned folder path in the window
|
||||
update_textfield(hWndTextField, "Scanning folder: " + folderPath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfolder \"" << folderPath << "\"";
|
||||
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, "File: " + scannedFilePath + " is infected\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 == "progress") {
|
||||
std::string progress;
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile >> progress;
|
||||
MessageBox(NULL, string_to_widestring(progress).c_str(), L"Progress", MB_OK);
|
||||
SendMessage(hProgressBar, PBM_SETPOS, atoi(progress.c_str()), 0);
|
||||
}
|
||||
else if (status == "end")
|
||||
answered = true;
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
Sleep(1000);//only see for new entrys ~ once a second
|
||||
std::ofstream(ANSWER_COM_PATH);//clear the file
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
update_textfield(hWndTextField, "Folder scan completed\r\n");
|
||||
update_textfield(hWndTextField, "Number of infected files: " + std::to_string(num_of_found) + "\r\n");
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string getFolderPath(HWND hWnd) {
|
||||
std::wstring selectedFolderPath;
|
||||
|
||||
// Initialize COM
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
// Display the folder picker dialog
|
||||
BROWSEINFO browseInfo = { 0 };
|
||||
TCHAR selectedPath[MAX_PATH];
|
||||
browseInfo.hwndOwner = hWnd; // Set the owner window
|
||||
browseInfo.pidlRoot = NULL; // Start from the desktop
|
||||
browseInfo.pszDisplayName = selectedPath;
|
||||
browseInfo.lpszTitle = TEXT("Select a folder");
|
||||
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
|
||||
LPITEMIDLIST pidlSelected = SHBrowseForFolder(&browseInfo);
|
||||
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
|
||||
IMalloc* pMalloc;
|
||||
if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
|
||||
pMalloc->Free(pidlSelected);
|
||||
pMalloc->Release();
|
||||
}
|
||||
}
|
||||
|
||||
// Uninitialize COM
|
||||
CoUninitialize();
|
||||
|
||||
return std::string(selectedFolderPath.begin(), selectedFolderPath.end());
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
static HWND hWndTextField;
|
||||
static HWND hProgressBar;
|
||||
static HBRUSH hBackgroundBrush = CreateSolidBrush(RGB(255, 255, 255)); // White color
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
int width = rect.right - rect.left;
|
||||
int height = rect.bottom - rect.top;
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
{
|
||||
|
||||
// Create the "Scan File" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan File",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 10, 100, 30, hWnd, (HMENU)IDM_SCAN_FILE, GetModuleHandle(NULL), NULL);
|
||||
|
||||
// Create the "Scan Folder" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan Folder",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 50, 100, 30, hWnd, (HMENU)IDM_SCAN_FOLDER, 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,
|
||||
140, 10, width-140-20, height-10-50, hWnd, NULL, NULL, NULL);
|
||||
update_textfield(hWndTextField, "Welcome to Cyberhex endpoint protection!\r\n");
|
||||
|
||||
hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
|
||||
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
|
||||
140, height-40, 200, 20, hWnd, NULL, NULL, NULL);
|
||||
SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
||||
SendMessage(hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
}
|
||||
break;
|
||||
case WM_SIZE:
|
||||
{
|
||||
// Resize the text field to fit the window
|
||||
MoveWindow(hWndTextField, 140, 10, width - 140 - 20, height - 10 - 50, TRUE);
|
||||
MoveWindow(hProgressBar, 140, height - 40, 200, 20, TRUE);
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
// Parse the menu selections:
|
||||
switch (wmId) {
|
||||
case IDM_SCAN_FILE:
|
||||
{
|
||||
// Open file dialog to select a file
|
||||
// Call scan_file function in a separate thread
|
||||
OPENFILENAME ofn;
|
||||
WCHAR szFile[MAX_PATH] = L""; // Use WCHAR for Unicode compatibility
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hWnd;
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.lpstrFile[0] = L'\0'; // Use wide character constant L'\0'
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = L"All Files\0*.*\0"; // Use wide character string literal L""
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.lpstrFileTitle = NULL;
|
||||
ofn.lpstrInitialDir = NULL;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||
|
||||
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).detach();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IDM_SCAN_FOLDER:
|
||||
{
|
||||
// Open folder picker dialog
|
||||
// Call scan_folder function in a separate thread
|
||||
std::string selectedFolder = getFolderPath(hWnd);
|
||||
std::thread(scan_folder,hProgressBar, hWndTextField, selectedFolder).detach();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
FillRect(hdc, &rect, hBackgroundBrush); // Fill the entire client area with white color
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
const wchar_t CLASS_NAME[] = L"Cyberhex endpoint protection frontend";
|
||||
|
||||
WNDCLASS wc = { };
|
||||
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
HWND hWnd = CreateWindowEx(
|
||||
0,
|
||||
CLASS_NAME,
|
||||
L"Cyberhex endpoint protection",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
640,
|
||||
480,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL
|
||||
);
|
||||
|
||||
|
||||
if (hWnd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
MSG msg = { };
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
367
src/client_frontend/client_frontend.cpp~RF8fd450.TMP
Normal file
367
src/client_frontend/client_frontend.cpp~RF8fd450.TMP
Normal file
@@ -0,0 +1,367 @@
|
||||
#include <Windows.h>
|
||||
#include <shlobj.h>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "../client_backend/well_known.h"
|
||||
|
||||
#define IDM_SCAN_FILE 101
|
||||
#define IDM_SCAN_FOLDER 102
|
||||
|
||||
|
||||
std::wstring string_to_widestring(const std::string& str) {
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
return converter.from_bytes(str);
|
||||
}
|
||||
void send_command(const std::string& command) {
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << command;
|
||||
outputFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
// Function to update the content of the text field with the provided text
|
||||
void update_textfield(HWND hWndTextField, const std::string& text) {
|
||||
// Get the current text length
|
||||
int textLength = GetWindowTextLength(hWndTextField);
|
||||
|
||||
// Set the selection to the end of the text field
|
||||
SendMessage(hWndTextField, EM_SETSEL, textLength, textLength);
|
||||
|
||||
// Append the new text
|
||||
SendMessage(hWndTextField, EM_REPLACESEL, FALSE, (LPARAM)string_to_widestring(text).c_str());
|
||||
}
|
||||
|
||||
void scan_file(HWND hWndTextField, const std::string& filePath) {
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
// Display the scanned file path in the window
|
||||
update_textfield(hWndTextField, "Scanning file: " + filePath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
//printf("%d\n",send_to_pipe("scanfile \"" + filePath + "\""));
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfile \"" << filePath << "\"";
|
||||
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;
|
||||
if (inputFile >> status) {
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile.ignore(1); // Ignore starting double quote
|
||||
if (status == "found" || status == "not_found") {
|
||||
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, "File: " + scannedFilePath + " is infected\r\n");
|
||||
update_textfield(hWndTextField, "Hash: " + hash + "\r\n");
|
||||
update_textfield(hWndTextField, "Action taken: " + action + "\r\n");
|
||||
|
||||
}
|
||||
else {
|
||||
update_textfield(hWndTextField, "No virus found in file: " + scannedFilePath + "\r\n");
|
||||
}
|
||||
update_textfield(hWndTextField, "------------------------------------------\r\n");
|
||||
}
|
||||
}
|
||||
else {
|
||||
answered = true;
|
||||
update_textfield(hWndTextField, "Error: Unable to talk to daemon!\n");
|
||||
update_textfield(hWndTextField, "------------------------------------------\n");
|
||||
}
|
||||
inputFile.close();
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
// Function to simulate folder scanning
|
||||
void scan_folder(HWND hProgressBar,HWND hWndTextField, const std::string& folderPath) {
|
||||
int num_of_found = 0;
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
// Display the scanned folder path in the window
|
||||
update_textfield(hWndTextField, "Scanning folder: " + folderPath + "\r\n");
|
||||
bool answered = false;
|
||||
// Write command into com file
|
||||
std::ofstream outputFile(MAIN_COM_PATH);
|
||||
if (outputFile.is_open()) {
|
||||
outputFile << "scanfolder \"" << folderPath << "\"";
|
||||
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, "File: " + scannedFilePath + " is infected\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 == "progress") {
|
||||
std::string progress;
|
||||
inputFile.ignore(1); // Ignore space
|
||||
inputFile >> progress;
|
||||
SendMessage(hProgressBar, PBM_SETPOS, atoi(progress.c_str()), 0);
|
||||
}
|
||||
else if (status == "end")
|
||||
answered = true;
|
||||
}
|
||||
}
|
||||
inputFile.close();
|
||||
Sleep(1000);//only see for new entrys ~ once a second
|
||||
std::ofstream(ANSWER_COM_PATH);//clear the file
|
||||
}
|
||||
// Wait for 1 second before checking again
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
update_textfield(hWndTextField, "Folder scan completed\r\n");
|
||||
update_textfield(hWndTextField, "Number of infected files: " + std::to_string(num_of_found) + "\r\n");
|
||||
// Remove the answer file
|
||||
std::remove(ANSWER_COM_PATH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::string getFolderPath(HWND hWnd) {
|
||||
std::wstring selectedFolderPath;
|
||||
|
||||
// Initialize COM
|
||||
CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE);
|
||||
|
||||
// Display the folder picker dialog
|
||||
BROWSEINFO browseInfo = { 0 };
|
||||
TCHAR selectedPath[MAX_PATH];
|
||||
browseInfo.hwndOwner = hWnd; // Set the owner window
|
||||
browseInfo.pidlRoot = NULL; // Start from the desktop
|
||||
browseInfo.pszDisplayName = selectedPath;
|
||||
browseInfo.lpszTitle = TEXT("Select a folder");
|
||||
browseInfo.ulFlags = BIF_RETURNONLYFSDIRS | BIF_NEWDIALOGSTYLE;
|
||||
|
||||
LPITEMIDLIST pidlSelected = SHBrowseForFolder(&browseInfo);
|
||||
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
|
||||
IMalloc* pMalloc;
|
||||
if (SUCCEEDED(SHGetMalloc(&pMalloc))) {
|
||||
pMalloc->Free(pidlSelected);
|
||||
pMalloc->Release();
|
||||
}
|
||||
}
|
||||
|
||||
// Uninitialize COM
|
||||
CoUninitialize();
|
||||
|
||||
return std::string(selectedFolderPath.begin(), selectedFolderPath.end());
|
||||
}
|
||||
|
||||
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
static HWND hWndTextField;
|
||||
static HWND hProgressBar;
|
||||
static HBRUSH hBackgroundBrush = CreateSolidBrush(RGB(255, 255, 255)); // White color
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
int width = rect.right - rect.left;
|
||||
int height = rect.bottom - rect.top;
|
||||
switch (message) {
|
||||
case WM_CREATE:
|
||||
{
|
||||
|
||||
// Create the "Scan File" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan File",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 10, 100, 30, hWnd, (HMENU)IDM_SCAN_FILE, GetModuleHandle(NULL), NULL);
|
||||
|
||||
// Create the "Scan Folder" button
|
||||
CreateWindowEx(NULL, L"BUTTON", L"Scan Folder",
|
||||
WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
|
||||
20, 50, 100, 30, hWnd, (HMENU)IDM_SCAN_FOLDER, 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,
|
||||
140, 10, width-140-20, height-10-50, hWnd, NULL, NULL, NULL);
|
||||
update_textfield(hWndTextField, "Welcome to Cyberhex endpoint protection!\r\n");
|
||||
|
||||
hProgressBar = CreateWindowEx(0, PROGRESS_CLASS, NULL,
|
||||
WS_CHILD | WS_VISIBLE | PBS_SMOOTH,
|
||||
140, height-40, 200, 20, hWnd, NULL, NULL, NULL);
|
||||
SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
|
||||
SendMessage(hProgressBar, PBM_SETSTEP, 1, 0);
|
||||
}
|
||||
break;
|
||||
case WM_SIZE:
|
||||
{
|
||||
// Resize the text field to fit the window
|
||||
MoveWindow(hWndTextField, 140, 10, width - 140 - 20, height - 10 - 50, TRUE);
|
||||
MoveWindow(hProgressBar, 140, height - 40, 200, 20, TRUE);
|
||||
break;
|
||||
}
|
||||
case WM_COMMAND:
|
||||
{
|
||||
int wmId = LOWORD(wParam);
|
||||
// Parse the menu selections:
|
||||
switch (wmId) {
|
||||
case IDM_SCAN_FILE:
|
||||
{
|
||||
// Open file dialog to select a file
|
||||
// Call scan_file function in a separate thread
|
||||
OPENFILENAME ofn;
|
||||
WCHAR szFile[MAX_PATH] = L""; // Use WCHAR for Unicode compatibility
|
||||
|
||||
ZeroMemory(&ofn, sizeof(ofn));
|
||||
ofn.lStructSize = sizeof(ofn);
|
||||
ofn.hwndOwner = hWnd;
|
||||
ofn.lpstrFile = szFile;
|
||||
ofn.lpstrFile[0] = L'\0'; // Use wide character constant L'\0'
|
||||
ofn.nMaxFile = sizeof(szFile);
|
||||
ofn.lpstrFilter = L"All Files\0*.*\0"; // Use wide character string literal L""
|
||||
ofn.nFilterIndex = 1;
|
||||
ofn.lpstrFileTitle = NULL;
|
||||
ofn.lpstrInitialDir = NULL;
|
||||
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST;
|
||||
|
||||
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).detach();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IDM_SCAN_FOLDER:
|
||||
{
|
||||
// Open folder picker dialog
|
||||
// Call scan_folder function in a separate thread
|
||||
std::string selectedFolder = getFolderPath(hWnd);
|
||||
std::thread(scan_folder,hProgressBar, hWndTextField, selectedFolder).detach();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_PAINT:
|
||||
{
|
||||
PAINTSTRUCT ps;
|
||||
HDC hdc = BeginPaint(hWnd, &ps);
|
||||
RECT rect;
|
||||
GetClientRect(hWnd, &rect);
|
||||
FillRect(hdc, &rect, hBackgroundBrush); // Fill the entire client area with white color
|
||||
EndPaint(hWnd, &ps);
|
||||
}
|
||||
break;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
default:
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {
|
||||
const wchar_t CLASS_NAME[] = L"Cyberhex endpoint protection frontend";
|
||||
|
||||
WNDCLASS wc = { };
|
||||
|
||||
wc.lpfnWndProc = WndProc;
|
||||
wc.hInstance = hInstance;
|
||||
wc.lpszClassName = CLASS_NAME;
|
||||
|
||||
RegisterClass(&wc);
|
||||
|
||||
HWND hWnd = CreateWindowEx(
|
||||
0,
|
||||
CLASS_NAME,
|
||||
L"Cyberhex endpoint protection",
|
||||
WS_OVERLAPPEDWINDOW,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
640,
|
||||
480,
|
||||
NULL,
|
||||
NULL,
|
||||
hInstance,
|
||||
NULL
|
||||
);
|
||||
|
||||
|
||||
if (hWnd == NULL) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ShowWindow(hWnd, nCmdShow);
|
||||
UpdateWindow(hWnd);
|
||||
|
||||
MSG msg = { };
|
||||
while (GetMessage(&msg, NULL, 0, 0)) {
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.9.34701.34
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client_frontend", "client_frontend.vcxproj", "{644C9824-2298-46C6-9A62-7E080C98A0BB}"
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "client_frontend", "client_frontend.vcxproj", "{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -13,19 +13,19 @@ Global
|
||||
Release|x86 = Release|x86
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Debug|x64.Build.0 = Debug|x64
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Debug|x86.Build.0 = Debug|Win32
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Release|x64.ActiveCfg = Release|x64
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Release|x64.Build.0 = Release|x64
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Release|x86.ActiveCfg = Release|Win32
|
||||
{644C9824-2298-46C6-9A62-7E080C98A0BB}.Release|x86.Build.0 = Release|Win32
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Debug|x64.ActiveCfg = Debug|x64
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Debug|x64.Build.0 = Debug|x64
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Debug|x86.ActiveCfg = Debug|Win32
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Debug|x86.Build.0 = Debug|Win32
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Release|x64.ActiveCfg = Release|x64
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Release|x64.Build.0 = Release|x64
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Release|x86.ActiveCfg = Release|Win32
|
||||
{4A82AA44-A521-4B6B-99F1-F8F32D7AC57B}.Release|x86.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {F67EF8DC-E0C4-4EE3-9BBA-D7BD7AC687A9}
|
||||
SolutionGuid = {47A5DC0C-22B2-47B0-8C56-FB80E8C063AE}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<PropertyGroup Label="Globals">
|
||||
<VCProjectVersion>17.0</VCProjectVersion>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<ProjectGuid>{644c9824-2298-46c6-9a62-7e080c98a0bb}</ProjectGuid>
|
||||
<ProjectGuid>{4a82aa44-a521-4b6b-99f1-f8f32d7ac57b}</ProjectGuid>
|
||||
<RootNamespace>clientfrontend</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
@@ -127,18 +127,13 @@
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="choose_element.h" />
|
||||
<ClInclude Include="client_frontend.h" />
|
||||
<ClInclude Include="framework.h" />
|
||||
<ClInclude Include="id.h" />
|
||||
<ClInclude Include="Resource.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="ui.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="choose_element.cpp" />
|
||||
<ClCompile Include="client_frontend.cpp" />
|
||||
<ClCompile Include="ui.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="client_frontend.rc" />
|
||||
|
||||
@@ -27,26 +27,11 @@
|
||||
<ClInclude Include="client_frontend.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="id.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="choose_element.h">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="client_frontend.cpp">
|
||||
<Filter>Quelldateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="choose_element.cpp">
|
||||
<Filter>Headerdateien</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ResourceCompile Include="client_frontend.rc">
|
||||
|
||||
Binary file not shown.
@@ -1,2 +1 @@
|
||||
ui.cpp
|
||||
client_frontend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\x64\Debug\client_frontend.exe
|
||||
client_frontend.vcxproj -> C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\x64\Debug\client_frontend.exe
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,3 +1 @@
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\choose_element.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend\x64\Debug\choose_element.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend\x64\Debug\client_frontend.obj
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\ui.cpp;C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend\x64\Debug\ui.obj
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,2 +1,2 @@
|
||||
^C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\CHOOSE_ELEMENT.OBJ|C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\CLIENT_FRONTEND.OBJ|C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\CLIENT_FRONTEND.RES|C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\UI.OBJ
|
||||
^C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\CLIENT_FRONTEND.OBJ|C:\USERS\JANIS\DOCUMENTS\PROJEKTE_MIT_C\MA\MA\SRC\CLIENT_FRONTEND\CLIENT_FRONTEND\X64\DEBUG\CLIENT_FRONTEND.RES
|
||||
C:\Users\janis\Documents\Projekte_mit_c\ma\ma\src\client_frontend\client_frontend\x64\Debug\client_frontend.ilk
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
#define ID_HOME_BUTTON 0
|
||||
#define ID_STARTUP_BUTTON 1
|
||||
#define ID_SCAN_FILE_BUTTON 2
|
||||
#define ID_SCAN_FOLDER_BUTTON 3
|
||||
#define ID_SETTINGS_BUTTON 4
|
||||
|
||||
#define ID_WELCOME_TEXT 1000
|
||||
@@ -1,95 +0,0 @@
|
||||
#include "ui.h"
|
||||
#include "id.h"
|
||||
#include <windows.h>
|
||||
#include "choose_element.h"
|
||||
HWND hwnd_[100];
|
||||
int num_hwnd = 0;
|
||||
|
||||
void draw_main_page(int window_width, int window_height, HWND hwnd);
|
||||
void draw_scan_file_page(int window_width, int window_height, HWND hwnd);
|
||||
|
||||
void ui_display_page(int page_id,int window_width, int window_height, HWND hwnd) {
|
||||
//create one button in middle of screen
|
||||
//hwnd_[num_hwnd] = CreateWindowW(L"BUTTON", L"OK", WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,(window_width-50)/2,(window_height-15)/2, 100, 30, hwnd, (HMENU)ID_STARTUP_BUTTON, NULL, NULL);
|
||||
//num_hwnd++;
|
||||
switch (page_id) {
|
||||
case 0: //main page
|
||||
draw_main_page(window_width,window_height,hwnd);
|
||||
break;
|
||||
case 1: //scan file page
|
||||
draw_scan_file_page(window_width, window_height, hwnd);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ui_clear() {
|
||||
//clear all windows
|
||||
for (int i = 0; i < num_hwnd; i++) {
|
||||
if (hwnd_[i] != NULL) {
|
||||
DestroyWindow(hwnd_[i]);
|
||||
}
|
||||
}
|
||||
num_hwnd = 0;
|
||||
}
|
||||
|
||||
void draw_main_page(int window_width, int window_height, HWND hwnd) {
|
||||
//draw main page
|
||||
hwnd_[num_hwnd] = CreateWindow(L"EDIT",
|
||||
L"Welcome to cyberhex\r\n\r\nPlease select an option:\r\n\r\n",
|
||||
WS_VISIBLE | WS_CHILD | ES_READONLY | ES_MULTILINE,
|
||||
10, 10, window_width - 30, window_height - 200,
|
||||
hwnd, (HMENU)0, NULL, NULL);
|
||||
num_hwnd++;
|
||||
|
||||
hwnd_[num_hwnd]= CreateWindow(L"BUTTON",
|
||||
L"Scan a file",
|
||||
WS_VISIBLE | WS_CHILD | WS_BORDER,
|
||||
(window_width)/4-100, window_height - 150, 200, 30,
|
||||
hwnd, (HMENU)ID_SCAN_FILE_BUTTON, NULL, NULL);
|
||||
num_hwnd++;
|
||||
hwnd_[num_hwnd] = CreateWindow(L"BUTTON",
|
||||
L"Scan a folder",
|
||||
WS_VISIBLE | WS_CHILD | WS_BORDER,
|
||||
(2* window_width) / 4-100, window_height - 150, 200, 30,
|
||||
hwnd, (HMENU)ID_SCAN_FOLDER_BUTTON, NULL, NULL);
|
||||
num_hwnd++;
|
||||
hwnd_[num_hwnd] = CreateWindow(L"BUTTON",
|
||||
L"Settings",
|
||||
WS_VISIBLE | WS_CHILD | WS_BORDER,
|
||||
(3* window_width) / 4-100, window_height - 150, 200, 30,
|
||||
hwnd, (HMENU)ID_SETTINGS_BUTTON, NULL, NULL);
|
||||
num_hwnd++;
|
||||
}
|
||||
|
||||
void draw_scan_file_page(int window_width, int window_height, HWND hwnd) {
|
||||
//draw scan file page
|
||||
std::wstring message = L"File to scan: ";
|
||||
std::wstring path=open_file(hwnd);
|
||||
if (path == L"cancel") {
|
||||
ui_clear();
|
||||
ui_display_page(0, window_width, window_height, hwnd);
|
||||
return;
|
||||
}
|
||||
message += path;
|
||||
hwnd_[num_hwnd] = CreateWindow(L"EDIT",
|
||||
message.c_str(),
|
||||
WS_VISIBLE | WS_CHILD | ES_READONLY | ES_MULTILINE,
|
||||
10, 10, window_width - 30, window_height - 200,
|
||||
hwnd, (HMENU)0, NULL, NULL);
|
||||
num_hwnd++;
|
||||
|
||||
hwnd_[num_hwnd] = CreateWindow(L"BUTTON",
|
||||
L"Home",
|
||||
WS_VISIBLE | WS_CHILD | WS_BORDER,
|
||||
10, window_height - 50, 200, 30,
|
||||
hwnd, (HMENU)ID_HOME_BUTTON, NULL, NULL);
|
||||
num_hwnd++;
|
||||
}
|
||||
|
||||
void update_scan_results(int window_width, int window_height, HWND hwnd,std::wstring& message) {
|
||||
//draw scan results
|
||||
//get value from the text field of draw_scan_file_page
|
||||
//add to thetextfield the string message
|
||||
|
||||
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
#pragma once
|
||||
#include <Windows.h>
|
||||
void ui_display_page(int page_id, int window_width, int window_height, HWND hwnd);
|
||||
void ui_clear();
|
||||
Binary file not shown.
Reference in New Issue
Block a user