HyperDbg Debugger
Loading...
Searching...
No Matches
unload.cpp File Reference

unload command More...

#include "pch.h"

Functions

VOID CommandUnloadHelp ()
 help of the unload command
BOOLEAN CommandUnloadCheckEnvironment ()
 check the environment for unload command
VOID CommandUnload (vector< CommandToken > CommandTokens, string Command)
 unload command handler

Variables

BOOLEAN g_IsConnectedToHyperDbgLocally
 Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.
BOOLEAN g_IsKdModuleLoaded
 shows whether the kernel debugger (KD) module is loaded or not
BOOLEAN g_IsVmmModuleLoaded
 shows whether the VMM module is loaded or not
BOOLEAN g_IsHyperTraceModuleLoaded
 shows whether the HyperTrace module is loaded or not
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
 Shows if the debugger was connected to remote debuggee over (A remote guest).
BOOLEAN g_IsSerialConnectedToRemoteDebugger
 Shows if the debugger was connected to remote debugger (A remote host).

Detailed Description

unload command

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.1
Date
2020-05-27

Function Documentation

◆ CommandUnload()

VOID CommandUnload ( vector< CommandToken > CommandTokens,
string Command )

unload command handler

Parameters
CommandTokens
Command
Returns
VOID
83{
84 if (CommandTokens.size() != 2 && CommandTokens.size() != 3)
85 {
86 ShowMessages("incorrect use of the '%s'\n\n",
87 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
89 return;
90 }
91
92 //
93 // Check for the module
94 //
95 if (CommandTokens.size() == 2 &&
96 (CompareLowerCaseStrings(CommandTokens.at(1), "vmm") || CompareLowerCaseStrings(CommandTokens.at(1), "vm")))
97 {
98 //
99 // Check the environment
100 //
102 {
103 return;
104 }
105
107 {
109
110 HyperDbgUnloadKd(); // Test: Should be removed
111 }
112 else
113 {
114 ShowMessages("the vmm module is not loadedd\n");
115 }
116 }
117 else if (CommandTokens.size() == 2 &&
118 (CompareLowerCaseStrings(CommandTokens.at(1), "trace") || CompareLowerCaseStrings(CommandTokens.at(1), "hypertrace")))
119 {
120 //
121 // Check the environment
122 //
124 {
125 return;
126 }
127
129 {
131 }
132 else
133 {
134 ShowMessages("the trace (hypertrace) module is not loadedd\n");
135 }
136 }
137 else if (CommandTokens.size() == 2 &&
138 (CompareLowerCaseStrings(CommandTokens.at(1), "kd") || CompareLowerCaseStrings(CommandTokens.at(1), "dbg") ||
139 CompareLowerCaseStrings(CommandTokens.at(1), "debugger") || CompareLowerCaseStrings(CommandTokens.at(1), "debug") ||
140 CompareLowerCaseStrings(CommandTokens.at(1), "kerneldebugger") || CompareLowerCaseStrings(CommandTokens.at(1), "kerneldebug")))
141 {
142 //
143 // Check the environment
144 //
146 {
147 return;
148 }
149
151 {
153 }
154 else
155 {
156 ShowMessages("the kd (kernel debugger) module is not loadedd\n");
157 }
158 }
159 else if (CommandTokens.size() == 2 &&
160 (CompareLowerCaseStrings(CommandTokens.at(1), "all") || CompareLowerCaseStrings(CommandTokens.at(1), ".")))
161 {
162 //
163 // Check the environment
164 //
166 {
167 return;
168 }
169
170 //
171 // Check if any module is loaded
172 //
174 {
175 ShowMessages("no module is loaded\n");
176 return;
177 }
178
179 ShowMessages("unloading all modules\n");
180
181 //
182 // Unload all modules
183 //
184 if (HyperDbgUnloadAllModules() != 0)
185 {
186 ShowMessages("err, failed to unload all modules\n");
187 return;
188 }
189 else
190 {
191 ShowMessages("all modules are unloaded\n");
192 }
193 }
194 else if (CommandTokens.size() == 3 && CompareLowerCaseStrings(CommandTokens.at(1), "remove") &&
195 (CompareLowerCaseStrings(CommandTokens.at(2), "all") ||
196 CompareLowerCaseStrings(CommandTokens.at(2), ".") ||
197 CompareLowerCaseStrings(CommandTokens.at(2), "vmm") ||
198 CompareLowerCaseStrings(CommandTokens.at(2), "vm")))
199 {
200 //
201 // Check the environment
202 //
204 {
205 return;
206 }
207
208 //
209 // Unload all modules before removing the driver
210 //
212 {
213 ShowMessages("err, failed to unload all modules\n");
214 return;
215 }
216
217 //
218 // Stop the driver
219 //
221 {
222 ShowMessages("err, failed to stop driver\n");
223 return;
224 }
225
226 //
227 // Uninstall the driver
228 //
230 {
231 ShowMessages("err, failed to uninstall the driver\n");
232 return;
233 }
234
235 ShowMessages("all drivers are removed\n");
236 }
237 else
238 {
239 //
240 // Module not found
241 //
242 ShowMessages("err, module not found\n");
243 }
244}
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
BOOLEAN CompareLowerCaseStrings(CommandToken TargetToken, const CHAR *StringToCompare)
Compare lower case strings.
Definition common.cpp:503
BOOLEAN g_IsHyperTraceModuleLoaded
shows whether the HyperTrace module is loaded or not
Definition lbrdump.cpp:19
INT HyperDbgUnloadVmm()
Unload VMM module.
Definition libhyperdbg.cpp:388
BOOLEAN HyperDbgIsAnyModuleLoaded()
check if any module is loaded (KD, VMM, HyperTrace, etc.)
Definition libhyperdbg.cpp:604
INT HyperDbgUnloadHyperTrace()
Unload HyperTrace module.
Definition libhyperdbg.cpp:457
INT HyperDbgStopKdDriver()
Stop KD driver.
Definition libhyperdbg.cpp:144
BOOLEAN g_IsKdModuleLoaded
shows whether the kernel debugger (KD) module is loaded or not
Definition globals.h:22
INT HyperDbgUnloadKd()
Unload KD driver.
Definition libhyperdbg.cpp:505
INT HyperDbgUnloadAllModules()
unload all modules (KD, VMM, HyperTrace, etc.)
Definition libhyperdbg.cpp:628
INT HyperDbgUninstallKdDriver()
Remove the KD (Kernel Debugger) driver.
Definition libhyperdbg.cpp:178
BOOLEAN g_IsVmmModuleLoaded
shows whether the VMM module is loaded or not
Definition globals.h:28
VOID CommandUnloadHelp()
help of the unload command
Definition unload.cpp:30
BOOLEAN CommandUnloadCheckEnvironment()
check the environment for unload command
Definition unload.cpp:51

◆ CommandUnloadCheckEnvironment()

BOOLEAN CommandUnloadCheckEnvironment ( )

check the environment for unload command

Returns
BOOLEAN
52{
54 {
55 ShowMessages("you're not connected to any instance of HyperDbg, did you "
56 "use '.connect'? \n");
57 return FALSE;
58 }
59
60 //
61 // Check to avoid using this command in debugger-mode
62 //
64 {
65 ShowMessages("you're connected to a an instance of HyperDbg, please use "
66 "'.debug close' command\n");
67 return FALSE;
68 }
69
70 return TRUE;
71}
BOOLEAN g_IsSerialConnectedToRemoteDebuggee
Shows if the debugger was connected to remote debuggee over (A remote guest).
Definition globals.h:253
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
BOOLEAN g_IsConnectedToHyperDbgLocally
Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machi...
Definition globals.h:89
BOOLEAN g_IsSerialConnectedToRemoteDebugger
Shows if the debugger was connected to remote debugger (A remote host).
Definition rev.cpp:18

◆ CommandUnloadHelp()

VOID CommandUnloadHelp ( )

help of the unload command

Returns
VOID
31{
32 ShowMessages("unload : unloads the kernel modules and uninstalls drivers.\n\n");
33
34 ShowMessages("syntax : \tunload [ModuleNameOrAll (string)]\n");
35 ShowMessages("syntax : \tunload [remove] [all]\n");
36
37 ShowMessages("\n");
38 ShowMessages("\t\te.g : unload vmm\n");
39 ShowMessages("\t\te.g : unload trace\n");
40 ShowMessages("\t\te.g : unload kd\n");
41 ShowMessages("\t\te.g : unload all\n");
42 ShowMessages("\t\te.g : unload remove all\n");
43}

Variable Documentation

◆ g_IsConnectedToHyperDbgLocally

BOOLEAN g_IsConnectedToHyperDbgLocally
extern

Shows whether the user is allowed to use 'load' command to load modules locally in VMI (virtual machine introspection) mode.

◆ g_IsHyperTraceModuleLoaded

BOOLEAN g_IsHyperTraceModuleLoaded
extern

shows whether the HyperTrace module is loaded or not

◆ g_IsKdModuleLoaded

BOOLEAN g_IsKdModuleLoaded
extern

shows whether the kernel debugger (KD) module is loaded or not

◆ g_IsSerialConnectedToRemoteDebuggee

BOOLEAN g_IsSerialConnectedToRemoteDebuggee
extern

Shows if the debugger was connected to remote debuggee over (A remote guest).

◆ g_IsSerialConnectedToRemoteDebugger

BOOLEAN g_IsSerialConnectedToRemoteDebugger
extern

Shows if the debugger was connected to remote debugger (A remote host).

◆ g_IsVmmModuleLoaded

BOOLEAN g_IsVmmModuleLoaded
extern

shows whether the VMM module is loaded or not