HyperDbg/hyperdbg/libhyperdbg/code/debugger/commands/debugging-commands/load.cpp

133 lines
3.3 KiB
C++
Raw Normal View History

2020-05-27 12:09:57 -07:00
/**
* @file load.cpp
2022-01-18 22:38:56 +03:30
* @author Sina Karvandi (sina@hyperdbg.org)
2020-05-27 12:09:57 -07:00
* @brief load command
* @details
* @version 0.1
* @date 2020-05-27
*
* @copyright This project is released under the GNU Public License v3.
*
*/
#include "pch.h"
2020-05-27 12:09:57 -07:00
//
// Global Variables
//
2020-08-28 04:03:12 -07:00
extern BOOLEAN g_IsConnectedToHyperDbgLocally;
2026-05-29 00:10:44 +02:00
extern BOOLEAN g_IsVmmModuleLoaded;
extern BOOLEAN g_IsHyperTraceModuleLoaded;
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 load command
*
* @return VOID
2020-08-28 04:03:12 -07:00
*/
2023-03-22 17:45:52 +09:00
VOID
CommandLoadHelp()
2021-03-22 18:19:39 +04:30
{
ShowMessages("load : installs the drivers and load the modules.\n\n");
ShowMessages("syntax : \tload [ModuleName (string)]\n");
ShowMessages("\n");
2021-03-22 18:19:39 +04:30
ShowMessages("\t\te.g : load vmm\n");
2026-05-29 00:10:44 +02:00
ShowMessages("\t\te.g : load kd\n");
ShowMessages("\t\te.g : load trace\n");
2020-05-27 12:09:57 -07:00
}
2020-05-27 14:06:27 -07:00
/**
* @brief load command handler
*
2024-07-30 13:17:50 +09:00
* @param CommandTokens
* @param Command
2024-07-30 13:17:50 +09:00
*
* @return VOID
*/
2023-03-22 17:45:52 +09:00
VOID
CommandLoad(vector<CommandToken> CommandTokens, string Command)
2021-03-22 18:19:39 +04:30
{
2024-07-30 13:17:50 +09:00
if (CommandTokens.size() != 2)
2023-03-22 17:45:52 +09:00
{
ShowMessages("incorrect use of the '%s'\n\n",
GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
2021-03-22 18:19:39 +04:30
CommandLoadHelp();
return;
2020-08-28 04:03:12 -07:00
}
2023-03-22 17:45:52 +09:00
if (!g_IsConnectedToHyperDbgLocally)
{
ShowMessages("you're not connected to any instance of HyperDbg, did you "
2021-03-22 18:19:39 +04:30
"use '.connect'? \n");
return;
}
2020-08-28 04:03:12 -07:00
//
2021-03-22 18:19:39 +04:30
// Check for the module
2020-08-28 04:03:12 -07:00
//
2026-05-29 00:10:44 +02:00
if (CompareLowerCaseStrings(CommandTokens.at(1), "vmm") ||
CompareLowerCaseStrings(CommandTokens.at(1), "vm"))
2023-03-22 17:45:52 +09:00
{
//
// Check to make sure that the driver is not already loaded
//
2026-05-29 00:10:44 +02:00
if (g_IsVmmModuleLoaded)
2023-03-22 17:45:52 +09:00
{
2026-05-29 00:10:44 +02:00
ShowMessages("the vmm module is already running, if you use 'load' before, please "
"first unload it using the 'unload' command\n");
return;
}
2021-03-22 18:19:39 +04:30
//
// Load VMM Module
//
2026-05-29 00:10:44 +02:00
ShowMessages("loading the vmm module\n");
2021-03-22 18:19:39 +04:30
if (HyperDbgInstallKdDriver() == 1 || HyperDbgLoadVmmModule() == 1)
2023-03-22 17:45:52 +09:00
{
ShowMessages("failed to install or load the driver\n");
2021-03-22 18:19:39 +04:30
return;
}
2021-05-30 20:25:07 +04:30
//
// If in vmi-mode then initialize and load symbols (pdb)
// for previously downloaded symbols
// When the VMM module is loaded, we use the current
// process (HyperDbg's process) as the base for user-mode
// symbols
2021-05-30 20:25:07 +04:30
//
SymbolLocalReload(GetCurrentProcessId());
2023-03-22 17:45:52 +09:00
}
2026-05-29 00:10:44 +02:00
else if (CompareLowerCaseStrings(CommandTokens.at(1), "trace") ||
CompareLowerCaseStrings(CommandTokens.at(1), "hypertrace"))
2026-05-28 20:26:33 +02:00
{
//
// Check to make sure that the driver is not already loaded
//
2026-05-29 00:10:44 +02:00
if (g_IsHyperTraceModuleLoaded)
2026-05-28 20:26:33 +02:00
{
2026-05-29 00:10:44 +02:00
ShowMessages("the trace module is already running, if you use 'load' before, please "
"first unload it using the 'unload' command\n");
2026-05-28 20:26:33 +02:00
return;
}
//
// Load HyperTrace Module
//
2026-05-29 00:10:44 +02:00
ShowMessages("loading the trace module\n");
2026-05-28 20:26:33 +02:00
if (HyperDbgInstallKdDriver() == 1 || HyperDbgLoadHyperTraceModule() == 1)
{
ShowMessages("failed to install or load the driver\n");
return;
}
}
2023-03-22 17:45:52 +09:00
else
{
2021-03-22 18:19:39 +04:30
//
// Module not found
//
ShowMessages("err, module not found\n");
2021-03-22 18:19:39 +04:30
}
2020-05-27 12:09:57 -07:00
}