diff --git a/Raccine.vcxproj b/Raccine.vcxproj index a1bfe92..70d3f0b 100644 --- a/Raccine.vcxproj +++ b/Raccine.vcxproj @@ -88,12 +88,13 @@ - Level3 + Level4 true WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest MultiThreadedDebug + true Console @@ -102,7 +103,7 @@ - Level3 + Level4 true true true @@ -110,6 +111,7 @@ _UNICODE;UNICODE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS stdcpplatest MultiThreaded + true Console @@ -120,12 +122,13 @@ - Level3 + Level4 true _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpplatest MultiThreadedDebug + true Console @@ -134,7 +137,7 @@ - Level3 + Level4 true true true @@ -142,6 +145,7 @@ _UNICODE;UNICODE;%(PreprocessorDefinitions);_CRT_SECURE_NO_WARNINGS stdcpplatest MultiThreaded + true Console diff --git a/source/RaccineLib/RaccineLib.vcxproj b/source/RaccineLib/RaccineLib.vcxproj index 9c79694..c4a22df 100644 --- a/source/RaccineLib/RaccineLib.vcxproj +++ b/source/RaccineLib/RaccineLib.vcxproj @@ -84,7 +84,7 @@ - Level3 + Level4 true WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) true @@ -92,6 +92,7 @@ pch.h stdcpplatest MultiThreadedDebug + true @@ -101,7 +102,7 @@ - Level3 + Level4 true true true @@ -111,6 +112,7 @@ pch.h stdcpplatest MultiThreaded + true @@ -122,7 +124,7 @@ - Level3 + Level4 true _DEBUG;_LIB;%(PreprocessorDefinitions) true @@ -130,6 +132,7 @@ pch.h stdcpplatest MultiThreadedDebug + true @@ -139,7 +142,7 @@ - Level3 + Level4 true true true @@ -149,6 +152,7 @@ pch.h stdcpplatest MultiThreaded + true diff --git a/source/RaccineLib/raccine.cpp b/source/RaccineLib/raccine.cpp index a971380..0c6b68d 100644 --- a/source/RaccineLib/raccine.cpp +++ b/source/RaccineLib/raccine.cpp @@ -287,7 +287,8 @@ bool isAllowListed(DWORD pid) } // Kill a process -BOOL killProcess(DWORD dwProcessId, UINT uExitCode) { +BOOL killProcess(DWORD dwProcessId, UINT uExitCode) +{ constexpr DWORD dwDesiredAccess = PROCESS_TERMINATE; constexpr BOOL bInheritHandle = FALSE; ProcessHandleWrapper hProcess = OpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId); @@ -299,7 +300,8 @@ BOOL killProcess(DWORD dwProcessId, UINT uExitCode) { } // Get timestamp -std::string getTimeStamp() { +std::string getTimeStamp() +{ struct tm buf {}; auto time = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now() - std::chrono::hours(24)); localtime_s(&buf, &time); @@ -310,7 +312,8 @@ std::string getTimeStamp() { } // Format a log lines -std::wstring logFormat(const std::wstring& cmdLine, const std::wstring& comment) { +std::wstring logFormat(const std::wstring& cmdLine, const std::wstring& comment) +{ const std::string timeString = getTimeStamp(); const std::wstring timeStringW(timeString.cbegin(), timeString.cend()); std::wstring logLine = timeStringW + L" DETECTED_CMD: '" + cmdLine + L" COMMENT: " + comment + L"\n"; diff --git a/tests/Raccine-Test/Raccine-Test.vcxproj b/tests/Raccine-Test/Raccine-Test.vcxproj index 7b4a7a8..0098dd4 100644 --- a/tests/Raccine-Test/Raccine-Test.vcxproj +++ b/tests/Raccine-Test/Raccine-Test.vcxproj @@ -65,8 +65,9 @@ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - Level3 + Level4 stdcpplatest + true true @@ -81,8 +82,9 @@ X64;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) EnableFastChecks MultiThreadedDebug - Level3 + Level4 stdcpplatest + true true @@ -95,9 +97,10 @@ pch.h WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded - Level3 + Level4 ProgramDatabase stdcpplatest + true true @@ -112,9 +115,10 @@ pch.h X64;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) MultiThreaded - Level3 + Level4 ProgramDatabase stdcpplatest + true true diff --git a/tests/Raccine-Test/pch.h b/tests/Raccine-Test/pch.h index 29c81ff..fad6c5c 100644 --- a/tests/Raccine-Test/pch.h +++ b/tests/Raccine-Test/pch.h @@ -5,4 +5,6 @@ #pragma once +#pragma warning(push, 3) #include "gtest/gtest.h" +#pragma warning(pop) diff --git a/tests/Raccine-Test/test.cpp b/tests/Raccine-Test/test.cpp index 99669c4..fa6bf7e 100644 --- a/tests/Raccine-Test/test.cpp +++ b/tests/Raccine-Test/test.cpp @@ -1,5 +1,9 @@ #include "pch.h" + + +#include "../../source/RaccineLib/HandleWrapper.h" +#include "../../source/RaccineLib/Raccine.h" #include "../../source/RaccineLib/Utils.h" TEST(TestUtils, ToLower) @@ -7,4 +11,47 @@ TEST(TestUtils, ToLower) const std::wstring input = L"HellO WoRld"; std::wstring excepted_output = L"hello world"; EXPECT_EQ(excepted_output, utils::to_lower(input)); -} \ No newline at end of file +} + +TEST(TestGetImageName, System) +{ + std::wstring image_name = getImageName(4); + ASSERT_EQ(image_name, L"System"); +} + +TEST(TestGetImageName, NonExistant) +{ + std::wstring image_name = getImageName(3); + ASSERT_EQ(image_name, L"(unavailable)"); +} + +TEST(TestGetImageName, CurrentProcess) +{ + std::wstring image_name = getImageName(GetCurrentProcessId()); + ASSERT_EQ(image_name, L"Raccine-Test.exe"); +} + +TEST(TestGetParentPid, System) +{ + DWORD parent_pid = getParentPid(4); + ASSERT_EQ(parent_pid, 0); +} + +TEST(TestGetParentPid, NonExistant) +{ + DWORD parent_pid = getParentPid(3); + ASSERT_EQ(parent_pid, 0); +} + +TEST(TestGetIntegrityLevel, CurrentProcess) +{ + ProcessHandleWrapper hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, + FALSE, + GetCurrentProcessId()); + if (!hProcess) { + FAIL() << "Failed to open process"; + } + + Integrity integrity = getIntegrityLevel(hProcess); + ASSERT_EQ(integrity, Integrity::Medium); +}