6
0
mirror of https://github.com/JKornev/hidden synced 2024-06-27 09:28:04 +00:00
hidden/HiddenCLI/Query.cpp

97 lines
3.4 KiB
C++
Raw Permalink Normal View History

2016-12-09 20:27:27 +00:00
#include "Query.h"
#include <iostream>
using namespace std;
CommandQuery::CommandQuery() : m_command(L"/query")
{
}
CommandQuery::~CommandQuery()
{
}
bool CommandQuery::CompareCommand(std::wstring& command)
{
return (command == m_command);
}
void CommandQuery::LoadArgs(Arguments& args, CommandModeType mode)
2016-12-09 20:27:27 +00:00
{
wstring object, target;
if (!args.GetNext(object))
2016-12-26 21:52:27 +00:00
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'query'");
2016-12-09 20:27:27 +00:00
2016-12-12 20:40:35 +00:00
if (object == L"process")
{
m_queryType = EQueryType::QueryProcess;
2016-12-09 20:27:27 +00:00
2016-12-12 20:40:35 +00:00
if (!args.GetNext(target))
2016-12-26 21:52:27 +00:00
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'query'");
2016-12-09 20:27:27 +00:00
2016-12-12 20:40:35 +00:00
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
2016-12-26 21:52:27 +00:00
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target pid for command 'query'");
2016-12-12 20:40:35 +00:00
}
else if (object == L"state")
2016-12-09 20:27:27 +00:00
{
2016-12-12 20:40:35 +00:00
m_queryType = EQueryType::QueryState;
}
else
{
2016-12-26 21:52:27 +00:00
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid object type for command 'query'");
2016-12-09 20:27:27 +00:00
}
}
void CommandQuery::PerformCommand(Connection& connection)
{
HidStatus status;
2016-12-12 20:40:35 +00:00
if (m_queryType == EQueryType::QueryState)
{
HidActiveState state;
status = Hid_GetState(connection.GetContext(), &state);
if (!HID_STATUS_SUCCESSFUL(status))
throw WException(HID_STATUS_CODE(status), L"Error, query state rejected");
2016-12-26 21:33:16 +00:00
g_stderr << L"Driver state:" << (state == HidActiveState::StateEnabled ? L"enabled" : L"disabled") << endl;
g_stdout << L"state:" << (state == HidActiveState::StateEnabled ? 1 : 0) << endl;
2016-12-12 20:40:35 +00:00
}
else if (m_queryType == EQueryType::QueryProcess)
{
2021-07-29 13:53:08 +00:00
HidActiveState excludeState, protectedState, hiddenState;
HidPsInheritTypes excludedInherit, protectedInherit, hiddenInherit;
2016-12-09 20:27:27 +00:00
2016-12-12 20:40:35 +00:00
status = Hid_GetExcludedState(connection.GetContext(), m_targetProcId, &excludeState, &excludedInherit);
if (!HID_STATUS_SUCCESSFUL(status))
throw WException(HID_STATUS_CODE(status), L"Error, query ignored state rejected");
2016-12-09 20:27:27 +00:00
2016-12-12 20:40:35 +00:00
status = Hid_GetProtectedState(connection.GetContext(), m_targetProcId, &protectedState, &protectedInherit);
if (!HID_STATUS_SUCCESSFUL(status))
throw WException(HID_STATUS_CODE(status), L"Error, query protected state rejected");
2016-12-09 20:27:27 +00:00
2021-07-29 13:53:08 +00:00
status = Hid_GetHiddenState(connection.GetContext(), m_targetProcId, &hiddenState, &hiddenInherit);
if (!HID_STATUS_SUCCESSFUL(status))
throw WException(HID_STATUS_CODE(status), L"Error, query hidden state rejected");
2016-12-26 21:33:16 +00:00
g_stderr << L"Ignored state:" << (excludeState == HidActiveState::StateEnabled ? L"true" : L"false")
2021-07-29 13:53:08 +00:00
<< L", inherit:" << ConvertInheritTypeToUnicode(excludedInherit) << endl;
2016-12-26 21:33:16 +00:00
g_stderr << L"Protected state:" << (protectedState == HidActiveState::StateEnabled ? L"true" : L"false")
2021-07-29 13:53:08 +00:00
<< L", inherit:" << ConvertInheritTypeToUnicode(protectedInherit) << endl;
g_stderr << L"Hidden state:" << (hiddenState == HidActiveState::StateEnabled ? L"true" : L"false")
<< L", inherit:" << ConvertInheritTypeToUnicode(hiddenInherit) << endl;
2016-12-12 20:40:35 +00:00
g_stdout << L"ignored:" << static_cast<unsigned short>(excludeState) << L"," << static_cast<unsigned short>(excludedInherit)
2021-07-29 13:53:08 +00:00
<< L";protected:" << static_cast<unsigned short>(protectedState) << L"," << static_cast<unsigned short>(protectedInherit)
<< L";hidden:" << static_cast<unsigned short>(hiddenState) << L"," << static_cast<unsigned short>(hiddenInherit) << endl;
2016-12-12 20:40:35 +00:00
}
2016-12-09 20:27:27 +00:00
}
2016-12-14 23:29:27 +00:00
CommandPtr CommandQuery::CreateInstance()
{
return CommandPtr(new CommandQuery());
}