From 935ffa787f93d156bea674a7793b10f6ce927dcf Mon Sep 17 00:00:00 2001 From: JKornev <8bit.dosninja@gmail.com> Date: Sun, 11 Sep 2016 14:42:37 +0300 Subject: [PATCH] Added the HiddenTests project that contain different tests for this solution --- Hidden.sln | 29 +++ HiddenTests/HiddenTests.cpp | 297 ++++++++++++++++++++++++ HiddenTests/HiddenTests.vcxproj | 89 +++++++ HiddenTests/HiddenTests.vcxproj.filters | 6 + 4 files changed, 421 insertions(+) create mode 100644 HiddenTests/HiddenTests.cpp create mode 100644 HiddenTests/HiddenTests.vcxproj create mode 100644 HiddenTests/HiddenTests.vcxproj.filters diff --git a/Hidden.sln b/Hidden.sln index 6235a22..5cbeff8 100644 --- a/Hidden.sln +++ b/Hidden.sln @@ -17,6 +17,11 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HiddenCLI", "HiddenCLI\Hidd {EFECF76B-C3A8-4444-9314-70F72A0A48D8} = {EFECF76B-C3A8-4444-9314-70F72A0A48D8} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HiddenTests", "HiddenTests\HiddenTests.vcxproj", "{023C63A1-726C-48D9-AA17-E62A7EFD862D}" + ProjectSection(ProjectDependencies) = postProject + {EFECF76B-C3A8-4444-9314-70F72A0A48D8} = {EFECF76B-C3A8-4444-9314-70F72A0A48D8} + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -193,6 +198,30 @@ Global {E6A7AAAD-4877-4F05-A5A1-F42707895996}.Win8.1 Release|Win32.Build.0 = Release|Win32 {E6A7AAAD-4877-4F05-A5A1-F42707895996}.Win8.1 Release|Win32.Deploy.0 = Release|Win32 {E6A7AAAD-4877-4F05-A5A1-F42707895996}.Win8.1 Release|x64.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Debug|Win32.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Debug|Win32.Build.0 = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Debug|x64.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Release|Win32.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Release|Win32.Build.0 = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Release|x64.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Debug|Win32.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Debug|Win32.Build.0 = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Debug|x64.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Release|Win32.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Release|Win32.Build.0 = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win7 Release|x64.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Debug|Win32.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Debug|Win32.Build.0 = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Debug|x64.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Release|Win32.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Release|Win32.Build.0 = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8 Release|x64.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Debug|Win32.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Debug|Win32.Build.0 = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Debug|x64.ActiveCfg = Debug|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Release|Win32.ActiveCfg = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Release|Win32.Build.0 = Release|Win32 + {023C63A1-726C-48D9-AA17-E62A7EFD862D}.Win8.1 Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/HiddenTests/HiddenTests.cpp b/HiddenTests/HiddenTests.cpp new file mode 100644 index 0000000..6b3a4cb --- /dev/null +++ b/HiddenTests/HiddenTests.cpp @@ -0,0 +1,297 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../HiddenLib/HiddenLib.h" + +using namespace std; + +class CHandle +{ +private: + DWORD m_error; + HANDLE m_handle; + +public: + CHandle(HANDLE handle) : m_handle(handle), m_error(GetLastError()) { } + ~CHandle() { if (m_handle != INVALID_HANDLE_VALUE) CloseHandle(m_handle); } + + HANDLE get() { return m_handle; } + DWORD error() { return m_error; } +}; + +void GenTempPath(wstring& path) +{ + wchar_t temp_file[MAX_PATH]; + wchar_t temp_dir[MAX_PATH]; + + unsigned int error_code; + + if (::GetTempPathW(_countof(temp_dir), temp_dir) == 0) + { + error_code = GetLastError(); + wcout << L"Error, GetTempPathW() failed with code: " << error_code << endl; + throw exception(); + } + + if (::GetTempFileNameW(temp_dir, L"hfs", rand(), temp_file) == 0) + { + error_code = GetLastError(); + wcout << L"Error, GetTempFileNameW() failed with code: " << error_code << endl; + throw exception(); + } + + path = temp_file; +} + +void do_fsmon_tests(HidContext context) +{ + HidStatus hid_status; + HidObjId objId[3]; + unsigned int error_code; + wstring file_path, dir_path, file_paths[2]; + + wcout << L"--------------------------------" << endl; + wcout << L"File-System monitor tests result:" << endl; + wcout << L"--------------------------------" << endl; + + try + { + // Test 1 + wcout << L"Test 1: create single file, hide it, unhide it" << endl; + + GenTempPath(file_path); + + CHandle hfile( + ::CreateFileW( + file_path.c_str(), + FILE_READ_ACCESS | FILE_WRITE_ACCESS, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_FLAG_DELETE_ON_CLOSE, + NULL + ) + ); + if (hfile.get() == INVALID_HANDLE_VALUE) + { + wcout << L"Error, CreateFileW() failed with code: " << hfile.error() << endl; + throw exception(); + } + + hid_status = Hid_AddHiddenFile(context, file_path.c_str(), &objId[0]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_AddHiddenFile failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + + if (::GetFileAttributesW(file_path.c_str()) != INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, hidden file has been found" << hfile.error() << endl; + throw exception(); + } + + hid_status = Hid_RemoveHiddenFile(context, objId[0]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_RemoveHiddenFile failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + + if (::GetFileAttributesW(file_path.c_str()) == INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, unhidden file hasn't been found" << hfile.error() << endl; + throw exception(); + } + + wcout << L" successful!" << endl; + + // Test 2 + wcout << L"Test 2: create single directory, hide it, unhide it" << endl; + + GenTempPath(dir_path); + + if (::CreateDirectoryW(dir_path.c_str(), NULL) == 0) + { + error_code = GetLastError(); + wcout << L"Error, CreateDirectoryExW() failed with code: " << error_code << endl; + throw exception(); + } + + CHandle hdir( + ::CreateFileW( + dir_path.c_str(), + FILE_READ_ACCESS, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + OPEN_EXISTING, + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_DELETE_ON_CLOSE, + NULL + ) + ); + if (hdir.get() == INVALID_HANDLE_VALUE) + { + wcout << L"Error, CreateFileW() failed with code: " << hdir.error() << endl; + throw exception(); + } + + hid_status = Hid_AddHiddenDir(context, dir_path.c_str(), &objId[1]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_AddHiddenDir failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + if (::GetFileAttributesW(dir_path.c_str()) != INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, hidden file has been found" << hfile.error() << endl; + throw exception(); + } + + hid_status = Hid_RemoveHiddenDir(context, objId[1]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_RemoveHiddenDir failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + + if (::GetFileAttributesW(dir_path.c_str()) == INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, unhidden dir hasn't been found" << hfile.error() << endl; + throw exception(); + } + + wcout << L" successful!" << endl; + + // Test 3 + wcout << L"Test 3: create two files, hide them, unhide using unhide all feature" << endl; + + GenTempPath(file_paths[0]); + GenTempPath(file_paths[1]); + + CHandle hfile2( + ::CreateFileW( + file_paths[0].c_str(), + FILE_READ_ACCESS | FILE_WRITE_ACCESS, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_FLAG_DELETE_ON_CLOSE, + NULL + ) + ); + if (hfile.get() == INVALID_HANDLE_VALUE) + { + wcout << L"Error, CreateFileW() failed with code: " << hfile.error() << endl; + throw exception(); + } + + CHandle hfile3( + ::CreateFileW( + file_paths[1].c_str(), + FILE_READ_ACCESS | FILE_WRITE_ACCESS, + FILE_SHARE_READ | FILE_SHARE_WRITE, + NULL, + CREATE_ALWAYS, + FILE_FLAG_DELETE_ON_CLOSE, + NULL + ) + ); + if (hfile.get() == INVALID_HANDLE_VALUE) + { + wcout << L"Error, CreateFileW() failed with code: " << hfile.error() << endl; + throw exception(); + } + + hid_status = Hid_AddHiddenFile(context, file_paths[0].c_str(), &objId[0]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_AddHiddenFile failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + + hid_status = Hid_AddHiddenFile(context, file_paths[1].c_str(), &objId[0]); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + wcout << L"Error, Hid_AddHiddenFile failed with code: " << HID_STATUS_CODE(hid_status) << endl; + throw exception(); + } + + if (::GetFileAttributesW(file_paths[0].c_str()) != INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, hidden file has been found" << hfile.error() << endl; + throw exception(); + } + + if (::GetFileAttributesW(file_paths[1].c_str()) != INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, hidden file has been found" << hfile.error() << endl; + throw exception(); + } + + hid_status = Hid_RemoveAllHiddenFiles(context); + + if (::GetFileAttributesW(file_paths[0].c_str()) == INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, unhidden file hasn't been found" << hfile.error() << endl; + throw exception(); + } + + if (::GetFileAttributesW(file_paths[1].c_str()) == INVALID_FILE_ATTRIBUTES) + { + wcout << L"Error, unhidden file hasn't been found" << hfile.error() << endl; + throw exception(); + } + + wcout << L" successful!" << endl; + } + catch (exception&) + { + wcout << L" failed!" << endl; + return; + } +} + +void do_regmon_tests(HidContext context) +{ + //HidStatus hid_status; + wcout << L"--------------------------------" << endl; + wcout << L"Registry monitor tests result:" << endl; + wcout << L"--------------------------------" << endl; +} + +void do_psmon_tests(HidContext context) +{ + //HidStatus hid_status; + wcout << L"--------------------------------" << endl; + wcout << L"Process monitor tests result:" << endl; + wcout << L"--------------------------------" << endl; +} + +int wmain(int argc, wchar_t* argv[]) +{ + HidContext hid_context; + HidStatus hid_status; + + srand(time(0)); + + hid_status = Hid_Initialize(&hid_context); + if (!HID_STATUS_SUCCESSFUL(hid_status)) + { + cout << "Error, HiddenLib initialization failed with code: " << HID_STATUS_CODE(hid_status) << endl; + return 1; + } + + do_fsmon_tests(hid_context); + do_regmon_tests(hid_context); + do_psmon_tests(hid_context); + + //Hid_Destroy(hid_context); + + return 0; +} diff --git a/HiddenTests/HiddenTests.vcxproj b/HiddenTests/HiddenTests.vcxproj new file mode 100644 index 0000000..57529a9 --- /dev/null +++ b/HiddenTests/HiddenTests.vcxproj @@ -0,0 +1,89 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {023C63A1-726C-48D9-AA17-E62A7EFD862D} + Win32Proj + HiddenTests + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + MultiThreadedDebug + + + Console + true + HiddenLib.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + HiddenLib.lib;%(AdditionalDependencies) + $(SolutionDir)$(Configuration)\ + + + + + + + + + \ No newline at end of file diff --git a/HiddenTests/HiddenTests.vcxproj.filters b/HiddenTests/HiddenTests.vcxproj.filters new file mode 100644 index 0000000..558ff40 --- /dev/null +++ b/HiddenTests/HiddenTests.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file