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

107 lines
2.4 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
//
2023-03-22 17:45:52 +09:00
extern HANDLE g_IsDriverLoadedSuccessfully;
extern HANDLE g_DeviceHandle;
2020-08-28 04:03:12 -07:00
extern BOOLEAN g_IsConnectedToHyperDbgLocally;
2020-05-27 14:06:27 -07:00
extern BOOLEAN g_IsDebuggerModulesLoaded;
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");
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
//
2024-07-30 13:17:50 +09:00
if (CompareLowerCaseStrings(CommandTokens.at(1), "vmm"))
2023-03-22 17:45:52 +09:00
{
//
// Check to make sure that the driver is not already loaded
//
2023-03-22 17:45:52 +09:00
if (g_DeviceHandle)
{
2021-04-19 02:54:38 +04:30
ShowMessages("handle of the driver found, if you use 'load' before, please "
2021-04-18 23:22:28 +04:30
"first unload it then call 'unload'\n");
return;
}
2021-03-22 18:19:39 +04:30
//
// Load VMM Module
//
2021-04-24 16:50:12 +04:30
ShowMessages("loading the vmm driver\n");
2021-03-22 18:19:39 +04:30
2024-07-03 19:16:14 +09:00
if (HyperDbgInstallVmmDriver() == 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
}
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
}