6
0
mirror of https://github.com/JKornev/hidden synced 2024-06-29 18:32:00 +00:00
hidden/HiddenCLI/Query.cpp

90 lines
2.6 KiB
C++
Raw 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))
throw WException(-2, L"Error, mismatched argument #1 for command 'query'");
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))
throw WException(-2, 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)
throw WException(-2, L"Error, invalid target pid for command 'query'");
}
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
{
throw WException(-2, 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");
wcerr << L"Driver state:" << (state == HidActiveState::StateEnabled ? L"enabled" : L"disabled") << endl;
wcout << L"status:ok;state:" << (state == HidActiveState::StateEnabled ? 1 : 0) << endl;
}
else if (m_queryType == EQueryType::QueryProcess)
{
HidActiveState excludeState, protectedState;
HidPsInheritTypes excludedInherit, protectedInherit;
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
2016-12-12 20:40:35 +00:00
wcerr << L"Ignored state:" << (excludeState == HidActiveState::StateEnabled ? L"true" : L"false")
<< L", inherit:" << ConvertInheritTypeToUnicode(excludedInherit) << endl;
wcerr << L"Protected state:" << (protectedState == HidActiveState::StateEnabled ? L"true" : L"false")
<< L", inherit:" << ConvertInheritTypeToUnicode(protectedInherit) << endl;
wcout << L"status:ok;ignored:" << excludeState << L"," << excludedInherit
<< L";protected:" << protectedState << L"," << protectedInherit << endl;
}
2016-12-09 20:27:27 +00:00
}
2016-12-14 23:29:27 +00:00
CommandPtr CommandQuery::CreateInstance()
{
return CommandPtr(new CommandQuery());
}