HyperDbg Debugger
Loading...
Searching...
No Matches
Common.h File Reference

Routines for common tasks in debugger. More...

Go to the source code of this file.

Classes

struct  _NT_KPROCESS
 KPROCESS Brief structure. More...
 

Macros

#define KGDT64_NULL   (0 * 16)
 
#define KGDT64_R0_CODE   (1 * 16)
 
#define KGDT64_R0_DATA   (1 * 16) + 8
 
#define KGDT64_R3_CMCODE   (2 * 16)
 
#define KGDT64_R3_DATA   (2 * 16) + 8
 
#define KGDT64_R3_CODE   (3 * 16)
 
#define KGDT64_SYS_TSS   (4 * 16)
 
#define KGDT64_R3_CMTEB   (5 * 16)
 
#define KGDT64_R0_CMCODE   (6 * 16)
 
#define KGDT64_LAST   (7 * 16)
 

Typedefs

typedef struct _NT_KPROCESS NT_KPROCESS
 KPROCESS Brief structure.
 
typedef struct _NT_KPROCESSPNT_KPROCESS
 
typedef enum _PROCESS_KILL_METHODS PROCESS_KILL_METHODS
 Different methods of killing a process.
 

Enumerations

enum  _PROCESS_KILL_METHODS { PROCESS_KILL_METHOD_1 = 0 , PROCESS_KILL_METHOD_2 , PROCESS_KILL_METHOD_3 }
 Different methods of killing a process. More...
 

Functions

UCHARPsGetProcessImageFileName (IN PEPROCESS Process)
 
PVOID PsGetProcessSectionBaseAddress (PEPROCESS Process)
 
NTKERNELAPI NTSTATUS NTAPI SeCreateAccessState (PACCESS_STATE AccessState, PVOID AuxData, ACCESS_MASK DesiredAccess, PGENERIC_MAPPING Mapping)
 
NTKERNELAPI VOID NTAPI SeDeleteAccessState (PACCESS_STATE AccessState)
 
NTSTATUS MmUnmapViewOfSection (PEPROCESS Process, PVOID BaseAddress)
 
BOOLEAN CommonIsProcessExist (UINT32 ProcId)
 Checks whether the process with ProcId exists or not.
 
PCHAR CommonGetProcessNameFromProcessControlBlock (PEPROCESS Eprocess)
 Get process name by eprocess.
 
BOOLEAN CommonKillProcess (UINT32 ProcessId, PROCESS_KILL_METHODS KillingMethod)
 Kill a user-mode process with different methods.
 
BOOLEAN CommonValidateCoreNumber (UINT32 CoreNumber)
 Validate core number.
 

Detailed Description

Routines for common tasks in debugger.

Author
Sina Karvandi (sina@.nosp@m.hype.nosp@m.rdbg..nosp@m.org)
Version
0.2
Date
2023-01-22

Macro Definition Documentation

◆ KGDT64_LAST

#define KGDT64_LAST   (7 * 16)

◆ KGDT64_NULL

#define KGDT64_NULL   (0 * 16)

◆ KGDT64_R0_CMCODE

#define KGDT64_R0_CMCODE   (6 * 16)

◆ KGDT64_R0_CODE

#define KGDT64_R0_CODE   (1 * 16)

◆ KGDT64_R0_DATA

#define KGDT64_R0_DATA   (1 * 16) + 8

◆ KGDT64_R3_CMCODE

#define KGDT64_R3_CMCODE   (2 * 16)

◆ KGDT64_R3_CMTEB

#define KGDT64_R3_CMTEB   (5 * 16)

◆ KGDT64_R3_CODE

#define KGDT64_R3_CODE   (3 * 16)

◆ KGDT64_R3_DATA

#define KGDT64_R3_DATA   (2 * 16) + 8

◆ KGDT64_SYS_TSS

#define KGDT64_SYS_TSS   (4 * 16)

Typedef Documentation

◆ NT_KPROCESS

typedef struct _NT_KPROCESS NT_KPROCESS

KPROCESS Brief structure.

◆ PNT_KPROCESS

typedef struct _NT_KPROCESS * PNT_KPROCESS

◆ PROCESS_KILL_METHODS

Different methods of killing a process.

Enumeration Type Documentation

◆ _PROCESS_KILL_METHODS

Different methods of killing a process.

Enumerator
PROCESS_KILL_METHOD_1 
PROCESS_KILL_METHOD_2 
PROCESS_KILL_METHOD_3 
64{
68
@ PROCESS_KILL_METHOD_2
Definition Common.h:66
@ PROCESS_KILL_METHOD_1
Definition Common.h:65
@ PROCESS_KILL_METHOD_3
Definition Common.h:67
enum _PROCESS_KILL_METHODS PROCESS_KILL_METHODS
Different methods of killing a process.

Function Documentation

◆ CommonGetProcessNameFromProcessControlBlock()

PCHAR CommonGetProcessNameFromProcessControlBlock ( PEPROCESS Eprocess)

Get process name by eprocess.

Parameters
EprocessProcess eprocess
Returns
PCHAR Returns a pointer to the process name
49{
50 PCHAR Result = 0;
51
52 //
53 // We can't use PsLookupProcessByProcessId as in pageable and not
54 // work on vmx-root
55 //
56 Result = (CHAR *)PsGetProcessImageFileName(Eprocess);
57
58 return Result;
59}
char CHAR
Definition BasicTypes.h:31
UCHAR * PsGetProcessImageFileName(IN PEPROCESS Process)

◆ CommonIsProcessExist()

BOOLEAN CommonIsProcessExist ( UINT32 ProcId)

Checks whether the process with ProcId exists or not.

this function should NOT be called from vmx-root mode

Parameters
UINT32ProcId
Returns
BOOLEAN Returns true if the process exists and false if it the process doesn't exist
25{
26 PEPROCESS TargetEprocess;
27
28 if (PsLookupProcessByProcessId((HANDLE)ProcId, &TargetEprocess) != STATUS_SUCCESS)
29 {
30 //
31 // There was an error, probably the process id was not found
32 //
33 return FALSE;
34 }
35 else
36 {
37 ObDereferenceObject(TargetEprocess);
38
39 return TRUE;
40 }
41}
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54

◆ CommonKillProcess()

BOOLEAN CommonKillProcess ( UINT32 ProcessId,
PROCESS_KILL_METHODS KillingMethod )

Kill a user-mode process with different methods.

Parameters
ProcessId
KillingMethod
Returns
BOOLEAN
160{
161 NTSTATUS Status = STATUS_SUCCESS;
162 HANDLE ProcessHandle = NULL;
163 PEPROCESS Process = NULL;
164
165 if (ProcessId == NULL_ZERO)
166 {
167 return FALSE;
168 }
169
170 switch (KillingMethod)
171 {
173
174 Status = CommonGetHandleFromProcess(ProcessId, &ProcessHandle);
175
176 if (!NT_SUCCESS(Status) || ProcessHandle == NULL)
177 {
178 return FALSE;
179 }
180
181 //
182 // Call ZwTerminateProcess with NULL handle
183 //
184 Status = ZwTerminateProcess(ProcessHandle, 0);
185
186 if (!NT_SUCCESS(Status))
187 {
188 return FALSE;
189 }
190
191 break;
192
194
196 &ProcessHandle,
197 PROCESS_ALL_ACCESS,
198 (HANDLE)ProcessId,
199 KernelMode);
200
201 if (ProcessHandle == NULL)
202 {
203 return FALSE;
204 }
205
206 //
207 // Call ZwTerminateProcess with NULL handle
208 //
209 Status = ZwTerminateProcess(ProcessHandle, 0);
210
211 if (!NT_SUCCESS(Status))
212 {
213 return FALSE;
214 }
215
216 break;
217
219
220 //
221 // Get the base address of process's executable image and unmap it
222 //
223 Status = MmUnmapViewOfSection(Process, PsGetProcessSectionBaseAddress(Process));
224
225 //
226 // Dereference the target process
227 //
228 ObDereferenceObject(Process);
229
230 break;
231
232 default:
233
234 //
235 // Unknown killing method
236 //
237 return FALSE;
238 break;
239 }
240
241 //
242 // If we reached here, it means the functionality of
243 // the above codes was successful
244 //
245 return TRUE;
246}
#define NULL_ZERO
Definition BasicTypes.h:51
_Use_decl_annotations_ NTSTATUS CommonGetHandleFromProcess(UINT32 ProcessId, PHANDLE Handle)
Get handle from Process Id.
Definition Common.c:52
NTSTATUS CommonUndocumentedNtOpenProcess(PHANDLE ProcessHandle, ACCESS_MASK DesiredAccess, HANDLE ProcessId, KPROCESSOR_MODE AccessMode)
The undocumented way of NtOpenProcess.
Definition Common.c:98
NTSTATUS MmUnmapViewOfSection(PEPROCESS Process, PVOID BaseAddress)
PVOID PsGetProcessSectionBaseAddress(PEPROCESS Process)
NULL()
Definition test-case-generator.py:530

◆ CommonValidateCoreNumber()

BOOLEAN CommonValidateCoreNumber ( UINT32 CoreNumber)

Validate core number.

Parameters
CoreNumber
Returns
BOOLEAN
257{
258 ULONG ProcessorsCount;
259
260 ProcessorsCount = KeQueryActiveProcessorCount(0);
261
262 if (CoreNumber >= ProcessorsCount)
263 {
264 return FALSE;
265 }
266 else
267 {
268 return TRUE;
269 }
270}
unsigned long ULONG
Definition BasicTypes.h:37

◆ MmUnmapViewOfSection()

NTSTATUS MmUnmapViewOfSection ( PEPROCESS Process,
PVOID BaseAddress )

◆ PsGetProcessImageFileName()

UCHAR * PsGetProcessImageFileName ( IN PEPROCESS Process)

◆ PsGetProcessSectionBaseAddress()

PVOID PsGetProcessSectionBaseAddress ( PEPROCESS Process)

◆ SeCreateAccessState()

NTKERNELAPI NTSTATUS NTAPI SeCreateAccessState ( PACCESS_STATE AccessState,
PVOID AuxData,
ACCESS_MASK DesiredAccess,
PGENERIC_MAPPING Mapping )

◆ SeDeleteAccessState()

NTKERNELAPI VOID NTAPI SeDeleteAccessState ( PACCESS_STATE AccessState)