2020-05-27 12:09:57 -07:00
|
|
|
/**
|
|
|
|
|
* @file exit.cpp
|
2022-01-18 22:38:56 +03:30
|
|
|
* @author Sina Karvandi (sina@hyperdbg.org)
|
2020-05-27 12:09:57 -07:00
|
|
|
* @brief exit command
|
|
|
|
|
* @details
|
|
|
|
|
* @version 0.1
|
|
|
|
|
* @date 2020-05-27
|
|
|
|
|
*
|
|
|
|
|
* @copyright This project is released under the GNU Public License v3.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#include "pch.h"
|
2020-05-27 12:09:57 -07:00
|
|
|
|
|
|
|
|
//
|
|
|
|
|
// Global Variables
|
|
|
|
|
//
|
2023-10-12 23:28:02 +08:00
|
|
|
extern HANDLE g_DeviceHandle;
|
|
|
|
|
extern BOOLEAN g_IsConnectedToHyperDbgLocally;
|
|
|
|
|
extern BOOLEAN g_IsSerialConnectedToRemoteDebuggee;
|
2026-06-06 17:18:14 +02:00
|
|
|
extern BOOLEAN g_IsKdModuleLoaded;
|
|
|
|
|
extern BOOLEAN g_IsVmmModuleLoaded;
|
2020-05-27 12:09:57 -07:00
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
/**
|
2023-07-13 16:05:42 +09:00
|
|
|
* @brief help of the exit command
|
2021-02-10 15:19:01 -08:00
|
|
|
*
|
|
|
|
|
* @return VOID
|
2020-08-28 04:03:12 -07:00
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
|
|
|
|
CommandExitHelp()
|
|
|
|
|
{
|
|
|
|
|
ShowMessages(
|
2022-04-10 22:24:56 +04:30
|
|
|
"exit : unloads and uninstalls the drivers and closes the debugger.\n\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
ShowMessages("syntax : \texit\n");
|
2020-05-27 12:09:57 -07:00
|
|
|
}
|
2020-05-27 14:06:27 -07:00
|
|
|
|
2020-08-28 04:03:12 -07:00
|
|
|
/**
|
|
|
|
|
* @brief exit command handler
|
2021-02-10 15:19:01 -08:00
|
|
|
*
|
2024-07-29 19:40:24 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-29 19:40:24 +09:00
|
|
|
*
|
2021-02-10 15:19:01 -08:00
|
|
|
* @return VOID
|
2020-08-28 04:03:12 -07:00
|
|
|
*/
|
2021-03-22 18:19:39 +04:30
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
CommandExit(vector<CommandToken> CommandTokens, string Command)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-07-29 19:40:24 +09:00
|
|
|
if (CommandTokens.size() != 1)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2024-07-29 19:40:24 +09:00
|
|
|
ShowMessages("incorrect use of the '%s'\n\n",
|
|
|
|
|
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
|
2021-03-22 18:19:39 +04:30
|
|
|
CommandExitHelp();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-27 12:09:57 -07:00
|
|
|
|
2023-10-12 23:28:02 +08:00
|
|
|
if (g_IsConnectedToHyperDbgLocally)
|
2021-03-22 18:19:39 +04:30
|
|
|
{
|
2023-10-12 23:28:02 +08:00
|
|
|
//
|
|
|
|
|
// It is in VMI mode
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
//
|
2026-06-06 17:18:14 +02:00
|
|
|
// unload and exit if the any module is loaded
|
2023-10-12 23:28:02 +08:00
|
|
|
//
|
|
|
|
|
if (g_DeviceHandle)
|
|
|
|
|
{
|
2026-05-31 21:03:02 +02:00
|
|
|
//
|
2026-06-06 17:18:14 +02:00
|
|
|
// Unload all modules
|
2026-05-31 21:03:02 +02:00
|
|
|
//
|
2026-06-06 17:18:14 +02:00
|
|
|
HyperDbgUnloadAllModules();
|
2023-10-12 23:28:02 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (g_IsSerialConnectedToRemoteDebuggee)
|
|
|
|
|
{
|
|
|
|
|
//
|
|
|
|
|
// It is in debugger mode
|
|
|
|
|
//
|
|
|
|
|
|
|
|
|
|
KdCloseConnection();
|
2020-05-27 12:09:57 -07:00
|
|
|
}
|
|
|
|
|
|
2021-03-22 18:19:39 +04:30
|
|
|
exit(0);
|
2020-05-27 12:09:57 -07:00
|
|
|
}
|