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.
|
|
|
|
|
*
|
|
|
|
|
*/
|
2022-05-04 16:38:21 -07:00
|
|
|
#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
|
2020-12-28 13:16:49 -08:00
|
|
|
*
|
|
|
|
|
* @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");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
2022-02-08 16:06:26 +03:30
|
|
|
ShowMessages("syntax : \tload [ModuleName (string)]\n");
|
2022-04-17 23:05:24 +04:30
|
|
|
|
|
|
|
|
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");
|
2026-05-26 19:52:04 +02:00
|
|
|
ShowMessages("\t\te.g : load trace\n");
|
2020-05-27 12:09:57 -07:00
|
|
|
}
|
2020-05-27 14:06:27 -07:00
|
|
|
|
2020-12-28 13:16:49 -08:00
|
|
|
/**
|
|
|
|
|
* @brief load command handler
|
|
|
|
|
*
|
2024-07-30 13:17:50 +09:00
|
|
|
* @param CommandTokens
|
2024-07-31 14:08:14 +09:00
|
|
|
* @param Command
|
2024-07-30 13:17:50 +09:00
|
|
|
*
|
2020-12-28 13:16:49 -08:00
|
|
|
* @return VOID
|
|
|
|
|
*/
|
2023-03-22 17:45:52 +09:00
|
|
|
VOID
|
2024-07-31 14:08:14 +09:00
|
|
|
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
|
|
|
{
|
2024-07-31 18:21:23 +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)
|
|
|
|
|
{
|
2021-04-11 22:21:22 +04:30
|
|
|
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-12-28 13:16:49 -08:00
|
|
|
|
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
|
|
|
{
|
2021-04-02 01:12:32 +04:30
|
|
|
//
|
|
|
|
|
// 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");
|
2021-04-02 01:12:32 +04:30
|
|
|
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
|
|
|
|
2026-05-26 19:52:04 +02:00
|
|
|
if (HyperDbgInstallKdDriver() == 1 || HyperDbgLoadVmmModule() == 1)
|
2023-03-22 17:45:52 +09:00
|
|
|
{
|
2021-04-11 22:21:22 +04:30
|
|
|
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
|
|
|
|
|
|
|
|
//
|
2021-06-21 15:15:28 +04:30
|
|
|
// If in vmi-mode then initialize and load symbols (pdb)
|
|
|
|
|
// for previously downloaded symbols
|
2022-02-17 03:27:50 +03:30
|
|
|
// 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
|
|
|
//
|
2022-02-17 03:27:50 +03: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
|
|
|
|
|
//
|
2023-02-02 16:02:16 +09:00
|
|
|
ShowMessages("err, module not found\n");
|
2021-03-22 18:19:39 +04:30
|
|
|
}
|
2020-05-27 12:09:57 -07:00
|
|
|
}
|