mirror of
https://github.com/JKornev/hidden
synced 2024-06-20 22:18:04 +00:00
Added hiddencli commands 'hide' and 'unhide'
This commit is contained in:
parent
1358effe89
commit
93a78b2680
@ -16,30 +16,37 @@ Commands::Commands(Arguments& args)
|
||||
|
||||
do
|
||||
{
|
||||
bool found = false;
|
||||
|
||||
for (auto it = m_commandsStack.begin(); it != m_commandsStack.end(); it++)
|
||||
{
|
||||
if ((*it)->CompareCommand(arg))
|
||||
{
|
||||
(*it)->LoadArgs(args);
|
||||
m_current = *it;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found)
|
||||
throw WException(-2, L"Error, unknown command, please use 'hiddencli help'");
|
||||
}
|
||||
while (args.GetNext(arg));
|
||||
|
||||
}
|
||||
|
||||
Commands::~Commands()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Commands::LoadCommandsStack()
|
||||
{
|
||||
m_commandsStack.push_back(new CommandHide());
|
||||
m_commandsStack.push_back(new CommandUnhide());
|
||||
m_commandsStack.push_back(CommandPtr(new CommandHide()));
|
||||
m_commandsStack.push_back(CommandPtr(new CommandUnhide()));
|
||||
}
|
||||
|
||||
void Commands::Perform(Connection& connection)
|
||||
{
|
||||
|
||||
m_current->PerformCommand(connection);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include "Helper.h"
|
||||
#include "Connection.h"
|
||||
#include <memory>
|
||||
|
||||
class ICommand
|
||||
{
|
||||
@ -16,7 +17,10 @@ public:
|
||||
|
||||
class Commands
|
||||
{
|
||||
std::vector<ICommand*> m_commandsStack;
|
||||
typedef std::shared_ptr<ICommand> CommandPtr;
|
||||
|
||||
std::vector<CommandPtr> m_commandsStack;
|
||||
CommandPtr m_current;
|
||||
|
||||
void LoadCommandsStack();
|
||||
|
||||
|
@ -12,7 +12,7 @@ Connection::Connection(Arguments& args) :
|
||||
|
||||
do
|
||||
{
|
||||
if (arg == L"gate")
|
||||
if (arg == L"/gate")
|
||||
{
|
||||
args.SwitchToNext();
|
||||
if (!args.GetNext(m_deviceName))
|
||||
|
@ -1,10 +1,11 @@
|
||||
#include "Hide.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
// =================
|
||||
|
||||
CommandHide::CommandHide() : m_command(L"hide")
|
||||
CommandHide::CommandHide() : m_command(L"/hide")
|
||||
{
|
||||
}
|
||||
|
||||
@ -54,7 +55,32 @@ void CommandHide::LoadArgs(Arguments& args)
|
||||
|
||||
void CommandHide::PerformCommand(Connection& connection)
|
||||
{
|
||||
HidStatus status;
|
||||
HidObjId objId;
|
||||
|
||||
switch (m_hideType)
|
||||
{
|
||||
case EHideTypes::TypeFile:
|
||||
status = Hid_AddHiddenFile(connection.GetContext(), m_path.c_str(), &objId);
|
||||
break;
|
||||
case EHideTypes::TypeDir:
|
||||
status = Hid_AddHiddenDir(connection.GetContext(), m_path.c_str(), &objId);
|
||||
break;
|
||||
case EHideTypes::TypeRegKey:
|
||||
status = Hid_AddHiddenRegKey(connection.GetContext(), m_regRootType, m_path.c_str(), &objId);
|
||||
break;
|
||||
case EHideTypes::TypeRegVal:
|
||||
status = Hid_AddHiddenRegValue(connection.GetContext(), m_regRootType, m_path.c_str(), &objId);
|
||||
break;
|
||||
default:
|
||||
throw WException(-2, L"Internal error, invalid type for command 'hide'");
|
||||
}
|
||||
|
||||
if (!HID_STATUS_SUCCESSFUL(status))
|
||||
throw WException(HID_STATUS_CODE(status), L"Error, command 'hide' rejected");
|
||||
|
||||
wcerr << L"Command 'hide' successful" << endl;
|
||||
wcout << L"status:ok;id:" << objId << endl;
|
||||
}
|
||||
|
||||
HidRegRootTypes CommandHide::GetRegType(wstring& path)
|
||||
@ -75,8 +101,9 @@ HidRegRootTypes CommandHide::GetRegType(wstring& path)
|
||||
|
||||
// =================
|
||||
|
||||
CommandUnhide::CommandUnhide() : m_command(L"unhide")
|
||||
CommandUnhide::CommandUnhide() : m_command(L"/unhide")
|
||||
{
|
||||
m_targetId = 0;
|
||||
}
|
||||
|
||||
CommandUnhide::~CommandUnhide()
|
||||
@ -90,10 +117,92 @@ bool CommandUnhide::CompareCommand(std::wstring& command)
|
||||
|
||||
void CommandUnhide::LoadArgs(Arguments& args)
|
||||
{
|
||||
wstring object, target;
|
||||
|
||||
if (!args.GetNext(object))
|
||||
throw WException(-2, L"Error, mismatched argument #1 for command 'unhide'");
|
||||
|
||||
if (!args.GetNext(target))
|
||||
throw WException(-2, L"Error, mismatched argument #2 for command 'unhide'");
|
||||
|
||||
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;
|
||||
}
|
||||
else if (object == L"regval")
|
||||
{
|
||||
m_hideType = EHideTypes::TypeRegVal;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw WException(-2, L"Error, invalid argument for command 'unhide'");
|
||||
}
|
||||
|
||||
m_targetAll = (target == L"all");
|
||||
if (!m_targetAll)
|
||||
{
|
||||
m_targetId = _wtoll(target.c_str());
|
||||
if (!m_targetId)
|
||||
throw WException(-2, L"Error, invalid target id for command 'unhide'");
|
||||
}
|
||||
}
|
||||
|
||||
void CommandUnhide::PerformCommand(Connection& connection)
|
||||
{
|
||||
HidStatus status;
|
||||
|
||||
if (m_targetAll)
|
||||
{
|
||||
switch (m_hideType)
|
||||
{
|
||||
case EHideTypes::TypeFile:
|
||||
status = Hid_RemoveAllHiddenFiles(connection.GetContext());
|
||||
break;
|
||||
case EHideTypes::TypeDir:
|
||||
status = Hid_RemoveAllHiddenDirs(connection.GetContext());
|
||||
break;
|
||||
case EHideTypes::TypeRegKey:
|
||||
status = Hid_RemoveAllHiddenRegKeys(connection.GetContext());
|
||||
break;
|
||||
case EHideTypes::TypeRegVal:
|
||||
status = Hid_RemoveAllHiddenRegValues(connection.GetContext());
|
||||
break;
|
||||
default:
|
||||
throw WException(-2, L"Internal error #1, invalid type for command 'unhide'");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (m_hideType)
|
||||
{
|
||||
case EHideTypes::TypeFile:
|
||||
status = Hid_RemoveHiddenFile(connection.GetContext(), m_targetId);
|
||||
break;
|
||||
case EHideTypes::TypeDir:
|
||||
status = Hid_RemoveHiddenDir(connection.GetContext(), m_targetId);
|
||||
break;
|
||||
case EHideTypes::TypeRegKey:
|
||||
status = Hid_RemoveHiddenRegKey(connection.GetContext(), m_targetId);
|
||||
break;
|
||||
case EHideTypes::TypeRegVal:
|
||||
status = Hid_RemoveHiddenRegValue(connection.GetContext(), m_targetId);
|
||||
break;
|
||||
default:
|
||||
throw WException(-2, L"Internal error #2, invalid type for command 'unhide'");
|
||||
}
|
||||
}
|
||||
|
||||
if (!HID_STATUS_SUCCESSFUL(status))
|
||||
throw WException(HID_STATUS_CODE(status), L"Error, command 'hide' rejected");
|
||||
|
||||
wcerr << L"Command 'unhide' successful" << endl;
|
||||
wcout << L"status:ok" << endl;
|
||||
}
|
||||
|
@ -34,6 +34,9 @@ class CommandUnhide : public ICommand
|
||||
{
|
||||
const wchar_t* m_command = nullptr;
|
||||
|
||||
EHideTypes m_hideType;
|
||||
HidObjId m_targetId;
|
||||
bool m_targetAll;
|
||||
public:
|
||||
|
||||
CommandUnhide();
|
||||
|
Loading…
Reference in New Issue
Block a user