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< string > SplitCommand, string Command)
 prealloc command handler
 

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< string > SplitCommand,
string Command )

prealloc command handler

Parameters
SplitCommand
Command
Returns
VOID
55{
56 BOOL Status;
57 ULONG ReturnedLength;
58 UINT64 Count;
59 DEBUGGER_PREALLOC_COMMAND PreallocRequest = {0};
60
61 if (SplitCommand.size() != 3)
62 {
63 ShowMessages("incorrect use of the 'prealloc'\n\n");
65 return;
66 }
67
68 //
69 // Set the type of pre-allocation
70 //
71 if (!SplitCommand.at(1).compare("thread-interception"))
72 {
74 }
75 else if (!SplitCommand.at(1).compare("monitor") || !SplitCommand.at(1).compare("!monitor"))
76 {
78 }
79 else if (!SplitCommand.at(1).compare("epthook") || !SplitCommand.at(1).compare("!epthook"))
80 {
82 }
83 else if (!SplitCommand.at(1).compare("epthook2") || !SplitCommand.at(1).compare("!epthook2"))
84 {
86 }
87 else if (!SplitCommand.at(1).compare("regular-event"))
88 {
90 }
91 else if (!SplitCommand.at(1).compare("big-event"))
92 {
94 }
95 else if (!SplitCommand.at(1).compare("regular-safe-buffer"))
96 {
98 }
99 else if (!SplitCommand.at(1).compare("big-safe-buffer"))
100 {
102 }
103 else
104 {
105 //
106 // Couldn't resolve or unknown parameter
107 //
108 ShowMessages("err, couldn't resolve error at '%s'\n",
109 SplitCommand.at(1).c_str());
110 return;
111 }
112
113 //
114 // Get the count of needed pre-allocated buffers
115 //
116 if (!SymbolConvertNameOrExprToAddress(SplitCommand.at(2), &Count))
117 {
118 //
119 // Couldn't resolve or unknown parameter
120 //
121 ShowMessages("err, couldn't resolve error at '%s'\n",
122 SplitCommand.at(2).c_str());
123 return;
124 }
125
126 //
127 // Set the counter
128 //
129 PreallocRequest.Count = (UINT32)Count;
130
132
133 //
134 // Send IOCTL
135 //
136 Status = DeviceIoControl(
137 g_DeviceHandle, // Handle to device
138 IOCTL_RESERVE_PRE_ALLOCATED_POOLS, // IO Control Code (IOCTL)
139 &PreallocRequest, // Input Buffer to driver.
140 SIZEOF_DEBUGGER_PREALLOC_COMMAND, // Input buffer length
141 &PreallocRequest, // Output Buffer from driver.
142 SIZEOF_DEBUGGER_PREALLOC_COMMAND, // Length of output
143 // buffer in bytes.
144 &ReturnedLength, // Bytes placed in buffer.
145 NULL // synchronous call
146 );
147
148 if (!Status)
149 {
150 ShowMessages("ioctl failed with code 0x%x\n", GetLastError());
151 return;
152 }
153
154 if (PreallocRequest.KernelStatus == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
155 {
156 ShowMessages("the requested pools are allocated and reserved\n");
157 }
158 else
159 {
160 //
161 // An err occurred, no results
162 //
163 ShowErrorMessage(PreallocRequest.KernelStatus);
164 }
165}
int BOOL
Definition BasicTypes.h:23
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#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:219
#define SIZEOF_DEBUGGER_PREALLOC_COMMAND
Definition RequestStructures.h:166
@ DEBUGGER_PREALLOC_COMMAND_TYPE_MONITOR
Definition RequestStructures.h:156
@ DEBUGGER_PREALLOC_COMMAND_TYPE_EPTHOOK2
Definition RequestStructures.h:158
@ DEBUGGER_PREALLOC_COMMAND_TYPE_BIG_EVENT
Definition RequestStructures.h:160
@ DEBUGGER_PREALLOC_COMMAND_TYPE_REGULAR_EVENT
Definition RequestStructures.h:159
@ DEBUGGER_PREALLOC_COMMAND_TYPE_THREAD_INTERCEPTION
Definition RequestStructures.h:155
@ DEBUGGER_PREALLOC_COMMAND_TYPE_BIG_SAFE_BUFFER
Definition RequestStructures.h:162
@ DEBUGGER_PREALLOC_COMMAND_TYPE_REGULAR_SAFE_BUFFER
Definition RequestStructures.h:161
@ DEBUGGER_PREALLOC_COMMAND_TYPE_EPTHOOK
Definition RequestStructures.h:157
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:38
#define AssertShowMessageReturnStmt(expr, message, rc)
Definition common.h:51
#define AssertReturn
Definition common.h:19
#define ASSERT_MESSAGE_DRIVER_NOT_LOADED
Definition common.h:25
HANDLE g_DeviceHandle
Holds the global handle of device which is used to send the request to the kernel by IOCTL,...
Definition globals.h:471
VOID ShowMessages(const char *Fmt,...)
Show messages.
Definition libhyperdbg.cpp:96
VOID CommandPreallocHelp()
help of the prealloc command
Definition prealloc.cpp:20
requests for the 'prealloc' command
Definition RequestStructures.h:174
DEBUGGER_PREALLOC_COMMAND_TYPE Type
Definition RequestStructures.h:175
UINT32 KernelStatus
Definition RequestStructures.h:177
UINT32 Count
Definition RequestStructures.h:176
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:360

◆ CommandPreallocHelp()

VOID CommandPreallocHelp ( )

help of the prealloc command

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