6
0
mirror of https://github.com/JKornev/hidden synced 2024-06-20 14:08:05 +00:00

Design for the commands

This commit is contained in:
JKornev 2016-12-06 01:37:18 +03:00
parent 96c5e6eb40
commit 1358effe89
13 changed files with 326 additions and 5 deletions

@ -44,6 +44,7 @@
+ Добавить поддержку флага автоприсвоение состояния существующим процессам для Hid_AddExcludedImage\Hid_AddProtectedImage
+ Проверить как ведёт себя файловый фильтр с файлами открытыми по ID или по короткому пути
- Реализовать HiddenCLI
- Реализовать функционал вкл\выкл драйвера через IOCTL
+ Портировать драйвер под архитектуру x64
+ Портировать под версии Windows 8, 8.1, 10
+ Залить проект на Git

@ -1,2 +1,45 @@
#include "Commands.h"
#include "Hide.h"
using namespace std;
// =================
Commands::Commands(Arguments& args)
{
wstring arg;
if (!args.GetNext(arg))
throw WException(-2, L"Error, no command, please use 'hiddencli help'");
LoadCommandsStack();
do
{
for (auto it = m_commandsStack.begin(); it != m_commandsStack.end(); it++)
{
if ((*it)->CompareCommand(arg))
{
(*it)->LoadArgs(args);
break;
}
}
}
while (args.GetNext(arg));
}
Commands::~Commands()
{
}
void Commands::LoadCommandsStack()
{
m_commandsStack.push_back(new CommandHide());
m_commandsStack.push_back(new CommandUnhide());
}
void Commands::Perform(Connection& connection)
{
}

@ -1,9 +1,29 @@
#pragma once
#include "Helper.h"
#include "Connection.h"
class ICommand
{
public:
virtual ~ICommand() {};
virtual bool CompareCommand(std::wstring& command) = 0;
virtual void LoadArgs(Arguments& args) = 0;
virtual void PerformCommand(Connection& connection) = 0;
};
class Commands
{
std::vector<ICommand*> m_commandsStack;
void LoadCommandsStack();
public:
Commands(Arguments& args){}
Commands(Arguments& args);
~Commands();
void Perform(Connection& connection);
};

@ -1,2 +1,52 @@
#include "Connection.h"
using namespace std;
Connection::Connection(Arguments& args) :
m_context(nullptr)
{
wstring arg;
if (!args.Probe(arg))
return;
do
{
if (arg == L"gate")
{
args.SwitchToNext();
if (!args.GetNext(m_deviceName))
throw WException(-2, L"Error, mismatched argument for command 'gate'");
}
else
{
break;
}
}
while (args.Probe(arg));
}
Connection::~Connection()
{
if (m_context)
Hid_Destroy(m_context);
}
void Connection::Open()
{
HidStatus status;
const wchar_t* deviceName = nullptr;
if (m_deviceName.size())
deviceName = m_deviceName.c_str();
//status = Hid_Initialize(&m_context, deviceName);
//if (!HID_STATUS_SUCCESSFUL(status))
// throw WException(HID_STATUS_CODE(status), L"Error, can't connect to gate");
}
HidContext Connection::GetContext()
{
return m_context;
}

@ -1,9 +1,22 @@
#pragma once
#include "Helper.h"
#include "../HiddenLib/HiddenLib.h"
class Connection
{
private:
HidContext m_context;
std::wstring m_deviceName;
public:
Connection(Arguments& args){}
Connection(Arguments& args);
~Connection();
void Open();
HidContext GetContext();
};

@ -37,6 +37,24 @@ size_t Arguments::ArgsCount()
return m_arguments.size();
}
bool Arguments::Probe(std::wstring& arg)
{
if (m_argPointer >= m_arguments.size())
return false;
arg = m_arguments[m_argPointer];
return true;
}
bool Arguments::SwitchToNext()
{
if (m_argPointer >= m_arguments.size())
return false;
m_argPointer++;
return true;
}
bool Arguments::GetNext(wstring& arg)
{
if (m_argPointer >= m_arguments.size())

@ -30,7 +30,8 @@ public:
size_t ArgsCount();
bool ProbNext(std::wstring& arg);
bool Probe(std::wstring& arg);
bool SwitchToNext();
bool GetNext(std::wstring& arg);
};

@ -14,6 +14,7 @@ int wmain(int argc, wchar_t* argv[])
try
{
Arguments arguments(argc, argv);
Connection connection(arguments);
if (!arguments.ArgsCount())
throw WException(
@ -21,9 +22,12 @@ int wmain(int argc, wchar_t* argv[])
L"Welcome to HiddenCLI, please use 'hiddencli help'"
);
Connection connection(arguments);
Commands commands(arguments);
{
Commands commands(arguments);
connection.Open();
commands.Perform(connection);
}
}
catch (WException& exception)
{

@ -155,11 +155,13 @@
<ClCompile Include="Connection.cpp" />
<ClCompile Include="Helper.cpp" />
<ClCompile Include="HiddenCLI.cpp" />
<ClCompile Include="Hide.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Commands.h" />
<ClInclude Include="Connection.h" />
<ClInclude Include="Helper.h" />
<ClInclude Include="Hide.h" />
</ItemGroup>
<ItemGroup>
<Text Include="cli.txt" />

@ -2,5 +2,27 @@
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ClCompile Include="HiddenCLI.cpp" />
<ClCompile Include="Helper.cpp" />
<ClCompile Include="Connection.cpp" />
<ClCompile Include="Commands.cpp" />
<ClCompile Include="Hide.cpp">
<Filter>Commands</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Text Include="cli.txt" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Helper.h" />
<ClInclude Include="Connection.h" />
<ClInclude Include="Commands.h" />
<ClInclude Include="Hide.h">
<Filter>Commands</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Filter Include="Commands">
<UniqueIdentifier>{680a2e80-be0d-4ac2-8a4a-d59b67e55c61}</UniqueIdentifier>
</Filter>
</ItemGroup>
</Project>

99
HiddenCLI/Hide.cpp Normal file

@ -0,0 +1,99 @@
#include "Hide.h"
using namespace std;
// =================
CommandHide::CommandHide() : m_command(L"hide")
{
}
CommandHide::~CommandHide()
{
}
bool CommandHide::CompareCommand(std::wstring& command)
{
return (command == m_command);
}
void CommandHide::LoadArgs(Arguments& args)
{
wstring object;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'hide'");
if (!args.GetNext(m_path))
throw WException(-2, L"Error, mismatched argument #2 for command 'hide'");
if (object == L"file")
{
m_hideType = EHideTypes::TypeFile;
}
else if (object == L"dir")
{
m_hideType = EHideTypes::TypeDir;
}
else if (object == L"regkey")
{
m_hideType = EHideTypes::TypeRegKey;
m_regRootType = GetRegType(m_path);
}
else if (object == L"regval")
{
m_hideType = EHideTypes::TypeRegVal;
m_regRootType = GetRegType(m_path);
}
else
{
throw WException(-2, L"Error, invalid argument for command 'hide'");
}
}
void CommandHide::PerformCommand(Connection& connection)
{
}
HidRegRootTypes CommandHide::GetRegType(wstring& path)
{
static wchar_t regHKLM[] = L"HKLM\\";
static wchar_t regHKCU[] = L"HKCU\\";
static wchar_t regHKU[] = L"HKU\\";
if (path.compare(0, _countof(regHKLM) - 1, regHKLM) == 0)
return HidRegRootTypes::RegHKLM;
else if (path.compare(0, _countof(regHKCU) - 1, regHKCU) == 0)
return HidRegRootTypes::RegHKCU;
else if (path.compare(0, _countof(regHKU) - 1, regHKU) == 0)
return HidRegRootTypes::RegHKU;
else
throw WException(-2, L"Error, invalid registry prefix");
}
// =================
CommandUnhide::CommandUnhide() : m_command(L"unhide")
{
}
CommandUnhide::~CommandUnhide()
{
}
bool CommandUnhide::CompareCommand(std::wstring& command)
{
return (command == m_command);
}
void CommandUnhide::LoadArgs(Arguments& args)
{
}
void CommandUnhide::PerformCommand(Connection& connection)
{
}

45
HiddenCLI/Hide.h Normal file

@ -0,0 +1,45 @@
#pragma once
#include "Commands.h"
enum EHideTypes {
TypeFile,
TypeDir,
TypeRegKey,
TypeRegVal,
TypeUnknown,
};
class CommandHide : public ICommand
{
const wchar_t* m_command = nullptr;
EHideTypes m_hideType;
HidRegRootTypes m_regRootType;
std::wstring m_path;
HidRegRootTypes GetRegType(std::wstring& path);
public:
CommandHide();
virtual ~CommandHide();
virtual bool CompareCommand(std::wstring& command);
virtual void LoadArgs(Arguments& args);
virtual void PerformCommand(Connection& connection);
};
class CommandUnhide : public ICommand
{
const wchar_t* m_command = nullptr;
public:
CommandUnhide();
virtual ~CommandUnhide();
virtual bool CompareCommand(std::wstring& command);
virtual void LoadArgs(Arguments& args);
virtual void PerformCommand(Connection& connection);
};

@ -2,6 +2,9 @@
hiddencli [connection] <command>
connection:
gate <%name%>
Set specific connection gate name (driver device name)
commands: