mirror of https://github.com/JKornev/hidden
Added the HiddenTests project that contain different tests for this solution
This commit is contained in:
parent
184312875d
commit
935ffa787f
29
Hidden.sln
29
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
|
||||
|
|
|
@ -0,0 +1,297 @@
|
|||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <thread>
|
||||
#include <mutex>
|
||||
#include <stdio.h>
|
||||
|
||||
#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;
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{023C63A1-726C-48D9-AA17-E62A7EFD862D}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>HiddenTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v120</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalDependencies>HiddenLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)\</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalDependencies>HiddenLib.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration)\</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="HiddenTests.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<ClCompile Include="HiddenTests.cpp" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue