Added valid error codes

This commit is contained in:
JKornev 2016-12-27 00:52:27 +03:00
parent 32f2da5145
commit 8a9ba43e23
10 changed files with 66 additions and 65 deletions

View File

@ -68,7 +68,8 @@
- Реализовать steals mode
+ Реализовать поддержку загрузки дефольтных конфигов из реестра
+ Реализовать установку конфигов в реестр через hiddencli
- Привести в порядок вывод статуса в hiddencli
+ Привести в порядок вывод статуса в hiddencli
+ Привести в порядок номер ошибки в hiddencli
- Насодить на ETL и DbgPrintEx
- Добавить SAL на функции драйвера

View File

@ -28,7 +28,7 @@ void LoadCommandsStack(vector<CommandPtr>& stack)
void ICommand::InstallCommand(RegistryKey& configKey)
{
throw WException(-2, L"Error, install mode is not supported");
throw WException(ERROR_UNSUPPORTED_TYPE, L"Error, install mode is not supported");
}
void ICommand::UninstallCommand(RegistryKey& configKey)
@ -42,7 +42,7 @@ CommandMode::CommandMode(Arguments& args) : m_type(CommandModeType::Execute)
wstring mode, all;
if (!args.Probe(mode))
throw WException(-2, L"Error, no command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, no command, please use 'hiddencli /help'");
if (mode == L"/install")
{
@ -60,7 +60,7 @@ CommandMode::CommandMode(Arguments& args) : m_type(CommandModeType::Execute)
if (m_type == CommandModeType::Uninstall)
{
if (!args.Probe(all) || all != L"all")
throw WException(-2, L"Error, invalid '/unistall' format");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid '/unistall' format");
args.SwitchToNext();
}
@ -102,14 +102,14 @@ SingleCommand::SingleCommand(Arguments& args, CommandModeType mode)
if (mode == CommandModeType::Uninstall)
{
if (args.SwitchToNext())
throw WException(-2, L"Error, too many arguments");
throw WException(ERROR_INVALID_PARAMETER, L"Error, too many arguments");
LoadCommandsStack(m_commandsStack);
return;
}
if (!args.GetNext(arg))
throw WException(-2, L"Error, no command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, no command, please use 'hiddencli /help'");
LoadCommandsStack(m_commandsStack);
@ -125,10 +125,10 @@ SingleCommand::SingleCommand(Arguments& args, CommandModeType mode)
}
if (!found)
throw WException(-2, L"Error, unknown command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, unknown command, please use 'hiddencli /help'");
if (args.SwitchToNext())
throw WException(-2, L"Error, too many arguments");
throw WException(ERROR_INVALID_PARAMETER, L"Error, too many arguments");
}
SingleCommand::~SingleCommand()
@ -167,10 +167,10 @@ MultipleCommands::MultipleCommands(Arguments& args, CommandModeType mode)
wstring arg;
if (mode == CommandModeType::Uninstall)
throw WException(-2, L"Error, /uninstall can't be combined with /multi");
throw WException(ERROR_INVALID_PARAMETER, L"Error, /uninstall can't be combined with /multi");
if (!args.GetNext(arg))
throw WException(-2, L"Error, no command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, no command, please use 'hiddencli /help'");
LoadCommandsStack(m_commandsStack);
@ -191,7 +191,7 @@ MultipleCommands::MultipleCommands(Arguments& args, CommandModeType mode)
}
if (!found)
throw WException(-2, L"Error, unknown command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, unknown command, please use 'hiddencli /help'");
}
while (args.GetNext(arg));
}
@ -214,7 +214,7 @@ void MultipleCommands::Install(RegistryKey& configKey)
void MultipleCommands::Uninstall(RegistryKey& configKey)
{
throw WException(-2, L"Error, uninstall mode is not supported");
throw WException(ERROR_UNSUPPORTED_TYPE, L"Error, uninstall mode is not supported");
}
// =================
@ -241,7 +241,7 @@ public:
argv = CommandLineToArgvW(line.c_str(), &argc);
if (!argv)
throw WException(-2, L"Error, invalid command format");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid command format");
try
{
@ -274,13 +274,13 @@ MultipleCommandsFromFile::MultipleCommandsFromFile(Arguments& args, CommandModeT
wstring configFile;
if (mode == CommandModeType::Uninstall)
throw WException(-2, L"Error, /uninstall can't be combined with /config");
throw WException(ERROR_INVALID_PARAMETER, L"Error, /uninstall can't be combined with /config");
if (!args.GetNext(configFile))
throw WException(-2, L"Error, no command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, no command, please use 'hiddencli /help'");
if (args.SwitchToNext())
throw WException(-2, L"Error, too many arguments");
throw WException(ERROR_INVALID_PARAMETER, L"Error, too many arguments");
wifstream fconfig(configFile);
wstring line;
@ -297,7 +297,7 @@ MultipleCommandsFromFile::MultipleCommandsFromFile(Arguments& args, CommandModeT
Arguments lineArgs = parser.GetArgs();
if (!lineArgs.GetNext(arg))
throw WException(-2, L"Error, no command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, no command, please use 'hiddencli /help'");
do
{
@ -316,7 +316,7 @@ MultipleCommandsFromFile::MultipleCommandsFromFile(Arguments& args, CommandModeT
}
if (!found)
throw WException(-2, L"Error, unknown command, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, unknown command, please use 'hiddencli /help'");
}
while (lineArgs.GetNext(arg));
}
@ -341,5 +341,5 @@ void MultipleCommandsFromFile::Install(RegistryKey& configKey)
void MultipleCommandsFromFile::Uninstall(RegistryKey& configKey)
{
throw WException(-2, L"Error, uninstall mode is not supported");
throw WException(ERROR_UNSUPPORTED_TYPE, L"Error, uninstall mode is not supported");
}

View File

@ -16,7 +16,7 @@ Connection::Connection(Arguments& args) :
{
args.SwitchToNext();
if (!args.GetNext(m_deviceName))
throw WException(-2, L"Error, mismatched argument for command 'gate'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument for command 'gate'");
if (m_deviceName.compare(0, 1, L"\\") != 0)
m_deviceName.insert(0, L"\\\\.\\");

View File

@ -251,7 +251,7 @@ HidRegRootTypes GetRegType(wstring& path)
else if (path.compare(0, _countof(regHKU) - 1, regHKU) == 0)
return HidRegRootTypes::RegHKU;
else
throw WException(-2, L"Error, invalid registry prefix");
throw WException(ERROR_INVALID_DATA, L"Error, invalid registry prefix");
}
HidPsInheritTypes LoadInheritOption(Arguments& args, HidPsInheritTypes default)

View File

@ -136,7 +136,7 @@ CommandTemplatePtr LoadCommandsTemplate(Arguments& args, CommandMode& mode)
return CommandTemplatePtr(new SingleCommand(args, mode.GetModeType()));
if (!args.Probe(templateType))
throw WException(-2, L"Error, unknown perform mode, please use 'hiddencli /help'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, unknown perform mode, please use 'hiddencli /help'");
if (templateType == L"/multi")
{
@ -160,7 +160,7 @@ int wmain(int argc, wchar_t* argv[])
if (!arguments.ArgsCount())
throw WException(
-2,
ERROR_INVALID_PARAMETER,
L"Welcome to HiddenCLI, please use 'hiddencli /help'"
);

View File

@ -24,7 +24,7 @@ HidRegRootTypes CommandHide::GetTypeAndNormalizeRegPath(std::wstring& regPath)
HidRegRootTypes type = GetRegType(regPath);
size_t pos = regPath.find(L"\\");
if (pos == wstring::npos)
throw WException(-2, L"Error, invalid registry path");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid registry path");
regPath = std::move(wstring(regPath.c_str() + pos + 1));
return type;
@ -35,10 +35,10 @@ void CommandHide::LoadArgs(Arguments& args, CommandModeType mode)
wstring object;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'hide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'hide'");
if (!args.GetNext(m_path))
throw WException(-2, L"Error, mismatched argument #2 for command 'hide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'hide'");
if (object == L"file")
{
@ -60,7 +60,7 @@ void CommandHide::LoadArgs(Arguments& args, CommandModeType mode)
}
else
{
throw WException(-2, L"Error, invalid argument for command 'hide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid argument for command 'hide'");
}
}
@ -84,7 +84,7 @@ void CommandHide::PerformCommand(Connection& connection)
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'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'hide'");
}
if (!HID_STATUS_SUCCESSFUL(status))
@ -122,7 +122,7 @@ void CommandHide::InstallCommand(RegistryKey& configKey)
status = Hid_NormalizeRegistryPath(m_regRootType, m_path.c_str(), const_cast<wchar_t*>(entry.c_str()), entry.size());
break;
default:
throw WException(-2, L"Internal error, invalid type for command 'hide'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'hide'");
}
configKey.GetMultiStrValue(valueName, commands);
@ -171,10 +171,10 @@ void CommandUnhide::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'unhide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'unhide'");
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'unhide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'unhide'");
if (object == L"file")
{
@ -194,7 +194,7 @@ void CommandUnhide::LoadArgs(Arguments& args, CommandModeType mode)
}
else
{
throw WException(-2, L"Error, invalid argument for command 'unhide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid argument for command 'unhide'");
}
m_targetAll = (target == L"all");
@ -202,7 +202,7 @@ void CommandUnhide::LoadArgs(Arguments& args, CommandModeType mode)
{
m_targetId = _wtoll(target.c_str());
if (!m_targetId)
throw WException(-2, L"Error, invalid target objid for command 'unhide'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target objid for command 'unhide'");
}
}
@ -227,7 +227,7 @@ void CommandUnhide::PerformCommand(Connection& connection)
status = Hid_RemoveAllHiddenRegValues(connection.GetContext());
break;
default:
throw WException(-2, L"Internal error #1, invalid type for command 'unhide'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error #1, invalid type for command 'unhide'");
}
}
else
@ -247,7 +247,7 @@ void CommandUnhide::PerformCommand(Connection& connection)
status = Hid_RemoveHiddenRegValue(connection.GetContext(), m_targetId);
break;
default:
throw WException(-2, L"Internal error #2, invalid type for command 'unhide'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error #2, invalid type for command 'unhide'");
}
}

View File

@ -23,7 +23,7 @@ void CommandIgnore::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'ignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'ignore'");
if (object == L"image")
{
@ -32,13 +32,13 @@ void CommandIgnore::LoadArgs(Arguments& args, CommandModeType mode)
else if (object == L"pid")
{
if (!CommandModeType::Execute)
throw WException(-2, L"Error, target 'pid' isn't allowed");
throw WException(ERROR_INVALID_PARAMETER, L"Error, target 'pid' isn't allowed");
m_procType = EProcTypes::TypeProcessId;
}
else
{
throw WException(-2, L"Error, invalid object type in command 'ignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid object type in command 'ignore'");
}
m_inheritType = LoadInheritOption(args, HidPsInheritTypes::WithoutInherit);
@ -48,7 +48,7 @@ void CommandIgnore::LoadArgs(Arguments& args, CommandModeType mode)
m_applyByDefault = LoadApplyOption(args, m_applyByDefault);
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'ignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'ignore'");
if (m_procType == EProcTypes::TypeImage)
{
@ -58,7 +58,7 @@ void CommandIgnore::LoadArgs(Arguments& args, CommandModeType mode)
{
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
throw WException(-2, L"Error, invalid target pid for command 'ignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target pid for command 'ignore'");
}
}
@ -76,7 +76,7 @@ void CommandIgnore::PerformCommand(Connection& connection)
status = Hid_AddExcludedImage(connection.GetContext(), m_targetImage.c_str(), m_inheritType, m_applyByDefault, &objId);
break;
default:
throw WException(-2, L"Internal error, invalid type for command 'ignore'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'ignore'");
}
if (!HID_STATUS_SUCCESSFUL(status))
@ -142,21 +142,21 @@ void CommandUnignore::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (mode != CommandModeType::Execute)
throw WException(-2, L"Error, install/uninstall mode isn't supported for this command");
throw WException(ERROR_INVALID_PARAMETER, L"Error, install/uninstall mode isn't supported for this command");
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'unignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'unignore'");
if (object == L"pid")
{
m_targetType = ETargetIdType::ProcId;
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'unignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'unignore'");
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
throw WException(-2, L"Error, invalid target ruleid for command 'unignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target ruleid for command 'unignore'");
}
else if (object == L"all")
{
@ -168,7 +168,7 @@ void CommandUnignore::LoadArgs(Arguments& args, CommandModeType mode)
m_targetId = _wtoll(object.c_str());
if (!m_targetId)
throw WException(-2, L"Error, invalid target ruleid for command 'unignore'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target ruleid for command 'unignore'");
}
}
@ -188,7 +188,7 @@ void CommandUnignore::PerformCommand(Connection& connection)
status = Hid_RemoveExcludedImage(connection.GetContext(), m_targetId);
break;
default:
throw WException(-2, L"Internal error, invalid type for command 'unignore'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'unignore'");
}
if (!HID_STATUS_SUCCESSFUL(status))

View File

@ -23,7 +23,7 @@ void CommandProtect::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'protect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'protect'");
if (object == L"image")
{
@ -32,13 +32,13 @@ void CommandProtect::LoadArgs(Arguments& args, CommandModeType mode)
else if (object == L"pid")
{
if (!CommandModeType::Execute)
throw WException(-2, L"Error, target 'pid' isn't allowed");
throw WException(ERROR_INVALID_PARAMETER, L"Error, target 'pid' isn't allowed");
m_procType = EProcTypes::TypeProcessId;
}
else
{
throw WException(-2, L"Error, invalid object type in command 'protect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid object type in command 'protect'");
}
m_inheritType = LoadInheritOption(args, HidPsInheritTypes::WithoutInherit);
@ -48,7 +48,7 @@ void CommandProtect::LoadArgs(Arguments& args, CommandModeType mode)
m_applyByDefault = LoadApplyOption(args, m_applyByDefault);
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'protect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'protect'");
if (m_procType == EProcTypes::TypeImage)
{
@ -58,7 +58,7 @@ void CommandProtect::LoadArgs(Arguments& args, CommandModeType mode)
{
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
throw WException(-2, L"Error, invalid target pid for command 'protect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target pid for command 'protect'");
}
}
@ -76,7 +76,7 @@ void CommandProtect::PerformCommand(Connection& connection)
status = Hid_AddProtectedImage(connection.GetContext(), m_targetImage.c_str(), m_inheritType, m_applyByDefault, &objId);
break;
default:
throw WException(-2, L"Internal error, invalid type for command 'protect'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'protect'");
}
if (!HID_STATUS_SUCCESSFUL(status))
@ -142,21 +142,21 @@ void CommandUnprotect::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (mode != CommandModeType::Execute)
throw WException(-2, L"Error, install/uninstall mode isn't supported for this command");
throw WException(ERROR_INVALID_PARAMETER, L"Error, install/uninstall mode isn't supported for this command");
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'unprotect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'unprotect'");
if (object == L"pid")
{
m_targetType = ETargetIdType::ProcId;
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'unprotect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'unprotect'");
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
throw WException(-2, L"Error, invalid target ruleid for command 'unprotect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target ruleid for command 'unprotect'");
}
else if (object == L"all")
{
@ -168,7 +168,7 @@ void CommandUnprotect::LoadArgs(Arguments& args, CommandModeType mode)
m_targetId = _wtoll(object.c_str());
if (!m_targetId)
throw WException(-2, L"Error, invalid target ruleid for command 'unprotect'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target ruleid for command 'unprotect'");
}
}
@ -188,7 +188,7 @@ void CommandUnprotect::PerformCommand(Connection& connection)
status = Hid_RemoveProtectedImage(connection.GetContext(), m_targetId);
break;
default:
throw WException(-2, L"Internal error, invalid type for command 'unprotect'");
throw WException(ERROR_UNKNOWN_COMPONENT, L"Internal error, invalid type for command 'unprotect'");
}
if (!HID_STATUS_SUCCESSFUL(status))

View File

@ -21,18 +21,18 @@ void CommandQuery::LoadArgs(Arguments& args, CommandModeType mode)
wstring object, target;
if (!args.GetNext(object))
throw WException(-2, L"Error, mismatched argument #1 for command 'query'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'query'");
if (object == L"process")
{
m_queryType = EQueryType::QueryProcess;
if (!args.GetNext(target))
throw WException(-2, L"Error, mismatched argument #2 for command 'query'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'query'");
m_targetProcId = _wtol(target.c_str());
if (!m_targetProcId)
throw WException(-2, L"Error, invalid target pid for command 'query'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid target pid for command 'query'");
}
else if (object == L"state")
{
@ -41,7 +41,7 @@ void CommandQuery::LoadArgs(Arguments& args, CommandModeType mode)
else
{
throw WException(-2, L"Error, invalid object type for command 'query'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, invalid object type for command 'query'");
}
}

View File

@ -21,14 +21,14 @@ void CommandState::LoadArgs(Arguments& args, CommandModeType mode)
wstring state, enable;
if (!args.GetNext(state))
throw WException(-2, L"Error, mismatched argument #1 for command 'state'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #1 for command 'state'");
if (state == L"on")
m_state = true;
else if (state == L"off")
m_state = false;
else
throw WException(-2, L"Error, mismatched argument #2 for command 'state'");
throw WException(ERROR_INVALID_PARAMETER, L"Error, mismatched argument #2 for command 'state'");
}
void CommandState::PerformCommand(Connection& connection)