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

prealloc command More...

#include "pch.h"

Functions

VOID CommandPreallocHelp ()
 help of the prealloc command
VOID CommandPrealloc (vector< CommandToken > CommandTokens, string Command)
 prealloc command handler

Variables

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

Detailed Description

prealloc command

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

Function Documentation

◆ CommandPrealloc()

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

prealloc command handler

Parameters
CommandTokens
Command
Returns
VOID
61{
62 BOOL Status;
63 ULONG ReturnedLength;
64 UINT64 Count;
65 DEBUGGER_PREALLOC_COMMAND PreallocRequest = {};
66 string SecondParam;
67
68 if (CommandTokens.size() != 3)
69 {
70 ShowMessages("incorrect use of the '%s'\n\n",
71 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(0)).c_str());
73 return;
74 }
75
76 SecondParam = GetLowerStringFromCommandToken(CommandTokens.at(1));
77
78 //
79 // Set the type of pre-allocation
80 //
81 if (!SecondParam.compare("thread-interception"))
82 {
84 }
85 else if (!SecondParam.compare("monitor") || !SecondParam.compare("!monitor"))
86 {
88 }
89 else if (!SecondParam.compare("epthook") || !SecondParam.compare("!epthook"))
90 {
92 }
93 else if (!SecondParam.compare("epthook2") || !SecondParam.compare("!epthook2"))
94 {
96 }
97 else if (!SecondParam.compare("regular-event"))
98 {
100 }
101 else if (!SecondParam.compare("big-event"))
102 {
104 }
105 else if (!SecondParam.compare("regular-safe-buffer"))
106 {
108 }
109 else if (!SecondParam.compare("big-safe-buffer"))
110 {
112 }
113 else
114 {
115 //
116 // Couldn't resolve or unknown parameter
117 //
118 ShowMessages("err, couldn't resolve error at '%s'\n",
119 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(1)).c_str());
120 return;
121 }
122
123 //
124 // Get the count of needed pre-allocated buffers
125 //
127 {
128 //
129 // Couldn't resolve or unknown parameter
130 //
131 ShowMessages("err, couldn't resolve error at '%s'\n",
132 GetCaseSensitiveStringFromCommandToken(CommandTokens.at(2)).c_str());
133 return;
134 }
135
136 //
137 // Set the counter
138 //
139 PreallocRequest.Count = (UINT32)Count;
140
142
143 //
144 // Send IOCTL
145 //
147 g_DeviceHandle, // Handle to device
148 IOCTL_RESERVE_PRE_ALLOCATED_POOLS, // IO Control Code (IOCTL)
149 &PreallocRequest, // Input Buffer to driver.
150 SIZEOF_DEBUGGER_PREALLOC_COMMAND, // Input buffer length
151 &PreallocRequest, // Output Buffer from driver.
152 SIZEOF_DEBUGGER_PREALLOC_COMMAND, // Length of output
153 // buffer in bytes.
154 &ReturnedLength, // Bytes placed in buffer.
155 NULL // synchronous call
156 );
157
158 if (!Status)
159 {
160 ShowMessages("ioctl failed with code 0x%x\n", PlatformGetLastError());
161 return;
162 }
163
164 if (PreallocRequest.KernelStatus == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
165 {
166 ShowMessages("the requested pools are allocated and reserved\n");
167 }
168 else
169 {
170 //
171 // An err occurred, no results
172 //
173 ShowErrorMessage(PreallocRequest.KernelStatus);
174 }
175}
int BOOL
Definition BasicTypes.h:25
unsigned int UINT32
Definition BasicTypes.h:54
unsigned long ULONG
Definition BasicTypes.h:31
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_RESERVE_PRE_ALLOCATED_POOLS
ioctl, to reserve pre-allocated pools
Definition Ioctls.h:277
#define SIZEOF_DEBUGGER_PREALLOC_COMMAND
Definition RequestStructures.h:194
struct _DEBUGGER_PREALLOC_COMMAND DEBUGGER_PREALLOC_COMMAND
requests for the 'prealloc' command
@ DEBUGGER_PREALLOC_COMMAND_TYPE_MONITOR
Definition RequestStructures.h:184
@ DEBUGGER_PREALLOC_COMMAND_TYPE_EPTHOOK2
Definition RequestStructures.h:186
@ DEBUGGER_PREALLOC_COMMAND_TYPE_BIG_EVENT
Definition RequestStructures.h:188
@ DEBUGGER_PREALLOC_COMMAND_TYPE_REGULAR_EVENT
Definition RequestStructures.h:187
@ DEBUGGER_PREALLOC_COMMAND_TYPE_THREAD_INTERCEPTION
Definition RequestStructures.h:183
@ DEBUGGER_PREALLOC_COMMAND_TYPE_BIG_SAFE_BUFFER
Definition RequestStructures.h:190
@ DEBUGGER_PREALLOC_COMMAND_TYPE_REGULAR_SAFE_BUFFER
Definition RequestStructures.h:189
@ DEBUGGER_PREALLOC_COMMAND_TYPE_EPTHOOK
Definition RequestStructures.h:185
std::string GetCaseSensitiveStringFromCommandToken(CommandToken TargetToken)
Get case sensitive string from command token.
Definition common.cpp:467
std::string GetLowerStringFromCommandToken(CommandToken TargetToken)
Get lower case string from command token.
Definition common.cpp:484
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:40
#define ASSERT_MESSAGE_KD_NOT_LOADED
Definition common.h:29
#define AssertShowMessageReturnStmt(expr1, expr2, message1, message2, rc)
Definition common.h:59
#define AssertReturn
Definition common.h:19
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:27
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:481
BOOLEAN g_IsKdModuleLoaded
shows whether the kernel debugger (KD) module is loaded or not
Definition globals.h:22
BOOL PlatformDeviceIoControl(HANDLE Device, DWORD IoControlCode, LPVOID InBuffer, DWORD InBufferSize, LPVOID OutBuffer, DWORD OutBufferSize, LPDWORD BytesReturned, LPVOID Overlapped)
DWORD PlatformGetLastError(VOID)
Platform independent wrapper for GetLastError.
Definition platform-lib-calls.c:350
VOID CommandPreallocHelp()
help of the prealloc command
Definition prealloc.cpp:25
DEBUGGER_PREALLOC_COMMAND_TYPE Type
Definition RequestStructures.h:203
UINT32 KernelStatus
Definition RequestStructures.h:205
UINT32 Count
Definition RequestStructures.h:204
BOOLEAN SymbolConvertNameOrExprToAddress(const string &TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for symbol object names and eval...
Definition symbol.cpp:359

◆ CommandPreallocHelp()

VOID CommandPreallocHelp ( )

help of the prealloc command

Returns
VOID
26{
27 ShowMessages("prealloc : pre-allocates buffer for special purposes.\n\n");
28
29 ShowMessages("syntax : \tprealloc [Type (string)] [Count (hex)]\n");
30
31 ShowMessages("\n");
32 ShowMessages("\t\te.g : prealloc thread-interception 8\n");
33 ShowMessages("\t\te.g : prealloc monitor 10\n");
34 ShowMessages("\t\te.g : prealloc epthook 5\n");
35 ShowMessages("\t\te.g : prealloc epthook2 3\n");
36 ShowMessages("\t\te.g : prealloc regular-event 12\n");
37 ShowMessages("\t\te.g : prealloc big-safe-buffert 1\n");
38
39 ShowMessages("\n");
40 ShowMessages("type of allocations:\n");
41 ShowMessages("\tthread-interception: used for pre-allocations of the thread holders for the thread interception mechanism\n");
42 ShowMessages("\tmonitor: used for pre-allocations of the '!monitor' EPT hooks\n");
43 ShowMessages("\tepthook: used for pre-allocations of the '!epthook' EPT hooks\n");
44 ShowMessages("\tepthook2: used for pre-allocations of the '!epthook2' EPT hooks\n");
45 ShowMessages("\tregular-event: used for pre-allocations of regular instant events\n");
46 ShowMessages("\tbig-event: used for pre-allocations of big instant events\n");
47 ShowMessages("\tregular-safe-buffer: used for pre-allocations of the regular event safe buffers ($buffer) for instant events\n");
48 ShowMessages("\tbig-safe-buffer: used for pre-allocations of the big event safe buffers ($buffer) for instant events\n");
49}

Variable Documentation

◆ g_IsKdModuleLoaded

BOOLEAN g_IsKdModuleLoaded
extern

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