HyperDbg Debugger
Loading...
Searching...
No Matches
Process.c File Reference

Implementation of kernel debugger functions for processes. More...

#include "pch.h"

Functions

VOID ProcessTriggerCr3ProcessChange (UINT32 CoreId)
 handle process changes for cr3 registers
 
BOOLEAN ProcessHandleProcessChange (PROCESSOR_DEBUGGING_STATE *DbgState)
 handle process changes
 
BOOLEAN ProcessSwitch (PROCESSOR_DEBUGGING_STATE *DbgState, UINT32 ProcessId, PEPROCESS EProcess, BOOLEAN IsSwitchByClockIntrrupt)
 make evnvironment ready to change the process
 
VOID ProcessDetectChangeByInterceptingClockInterrupts (PROCESSOR_DEBUGGING_STATE *DbgState, BOOLEAN Enable)
 Enable or disable the process change monitoring detection on the running core based on intercepting clock interrupts.
 
VOID ProcessDetectChangeByMov2Cr3Vmexits (PROCESSOR_DEBUGGING_STATE *DbgState, BOOLEAN Enable)
 Enable or disable the process change monitoring detection on the running core based on mov-to-cr3 vm-exits.
 
VOID ProcessEnableOrDisableThreadChangeMonitor (PROCESSOR_DEBUGGING_STATE *DbgState, BOOLEAN Enable, BOOLEAN IsSwitchByClockIntrrupt)
 Enable or disable the process change monitoring detection on the running core.
 
BOOLEAN ProcessCheckIfEprocessIsValid (UINT64 Eprocess, UINT64 ActiveProcessHead, ULONG ActiveProcessLinksOffset)
 checks whether the given nt!_EPROCESS is valid or not
 
BOOLEAN ProcessShowList (PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS PorcessListSymbolInfo, DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTIONS QueryAction, UINT32 *CountOfProcesses, PVOID ListSaveBuffer, UINT64 ListSaveBuffSize)
 shows the processes list
 
BOOLEAN ProcessInterpretProcess (PROCESSOR_DEBUGGING_STATE *DbgState, PDEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET PidRequest)
 change the current process @detail ONLY TO BE USED IN KD STUFFS
 
BOOLEAN ProcessQueryCount (PDEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS DebuggerUsermodeProcessOrThreadQueryRequest)
 Query process details (count)
 
BOOLEAN ProcessQueryList (PDEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS DebuggerUsermodeProcessOrThreadQueryRequest, PVOID AddressToSaveDetail, UINT32 BufferSize)
 Query process details (list)
 
BOOLEAN ProcessQueryDetails (PDEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET GetInformationProcessRequest)
 Query process details.
 

Detailed Description

Implementation of kernel debugger functions for processes.

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

Function Documentation

◆ ProcessCheckIfEprocessIsValid()

BOOLEAN ProcessCheckIfEprocessIsValid ( UINT64 Eprocess,
UINT64 ActiveProcessHead,
ULONG ActiveProcessLinksOffset )

checks whether the given nt!_EPROCESS is valid or not

Parameters
Eprocesstarget nt!_EPROCESS
ActiveProcessHeadnt!PsActiveProcessHead
ActiveProcessLinksOffsetnt!_EPROCESS.ActiveProcessLinks
Returns
BOOLEAN
265{
266 UINT64 Process;
267 LIST_ENTRY ActiveProcessLinks = {0};
268
269 //
270 // Dirty validation of parameters
271 //
272 if (ActiveProcessHead == NULL64_ZERO ||
273 ActiveProcessLinksOffset == NULL_ZERO)
274 {
275 return FALSE;
276 }
277
278 //
279 // Check if address is valid
280 //
281 if (CheckAccessValidityAndSafety(ActiveProcessHead, sizeof(BYTE)))
282 {
283 //
284 // Show processes list, we read everything from the view of system
285 // process
286 //
287 MemoryMapperReadMemorySafe(ActiveProcessHead, &ActiveProcessLinks, sizeof(ActiveProcessLinks));
288
289 //
290 // Find the top of EPROCESS from nt!_EPROCESS.ActiveProcessLinks
291 //
292 Process = (UINT64)ActiveProcessLinks.Flink - ActiveProcessLinksOffset;
293
294 do
295 {
296 //
297 // Read the next process
298 //
299 MemoryMapperReadMemorySafe(Process + ActiveProcessLinksOffset,
300 &ActiveProcessLinks,
301 sizeof(ActiveProcessLinks));
302
303 //
304 // Check if we find the process
305 //
306 if (Process == Eprocess)
307 {
308 return TRUE;
309 }
310
311 //
312 // Find the next process from the list of this process
313 //
314 Process = (UINT64)ActiveProcessLinks.Flink - ActiveProcessLinksOffset;
315
316 } while ((UINT64)ActiveProcessLinks.Flink != ActiveProcessHead);
317 }
318 else
319 {
320 //
321 // An invalid address is specified
322 //
323 return FALSE;
324 }
325
326 return FALSE;
327}
BOOLEAN CheckAccessValidityAndSafety(UINT64 TargetAddress, UINT32 Size)
Check the safety to access the memory.
Definition AddressCheck.c:156
#define NULL_ZERO
Definition BasicTypes.h:51
unsigned char BYTE
Definition BasicTypes.h:24
#define NULL64_ZERO
Definition BasicTypes.h:52
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned __int64 UINT64
Definition BasicTypes.h:21
_Use_decl_annotations_ BOOLEAN MemoryMapperReadMemorySafe(UINT64 VaAddressToRead, PVOID BufferToSaveMemory, SIZE_T SizeToRead)
Read memory safely by mapping the buffer (It's a wrapper)
Definition MemoryMapper.c:1101

◆ ProcessDetectChangeByInterceptingClockInterrupts()

VOID ProcessDetectChangeByInterceptingClockInterrupts ( PROCESSOR_DEBUGGING_STATE * DbgState,
BOOLEAN Enable )

Enable or disable the process change monitoring detection on the running core based on intercepting clock interrupts.

should be called on vmx root

Parameters
DbgStateThe state of the debugger on the current core
Enable
Returns
VOID
140{
141 if (Enable)
142 {
143 //
144 // Indicate that we're waiting for clock interrupt vm-exits
145 //
147
148 //
149 // Set external-interrupt vm-exits
150 //
152 }
153 else
154 {
155 //
156 // Indicate that we're not waiting for clock interrupt vm-exits
157 //
159
160 //
161 // Unset external-interrupt vm-exits
162 //
164 }
165}
VOID VmFuncSetExternalInterruptExiting(UINT32 CoreId, BOOLEAN Set)
Set the External Interrupt Exiting.
Definition Export.c:280
BOOLEAN InterceptClockInterruptsForProcessChange
Definition State.h:63
UINT32 CoreId
Definition State.h:169
DEBUGGEE_PROCESS_OR_THREAD_TRACING_DETAILS ThreadOrProcessTracingDetails
Definition State.h:178

◆ ProcessDetectChangeByMov2Cr3Vmexits()

VOID ProcessDetectChangeByMov2Cr3Vmexits ( PROCESSOR_DEBUGGING_STATE * DbgState,
BOOLEAN Enable )

Enable or disable the process change monitoring detection on the running core based on mov-to-cr3 vm-exits.

should be called on vmx root

Parameters
DbgStateThe state of the debugger on the current core
Enable
Returns
VOID
179{
180 if (Enable)
181 {
182 //
183 // Indicate that we're waiting for mov-to-cr3 vm-exits
184 //
186
187 //
188 // Set mov to cr3 vm-exit, this flag is also use to remove the
189 // mov 2 cr3 on next halt
190 //
192 }
193 else
194 {
195 //
196 // Indicate that we're not waiting for mov-to-cr3 vm-exits
197 //
199
200 //
201 // Unset mov to cr3 vm-exit, this flag is also use to remove the
202 // mov 2 cr3 on next halt
203 //
205 }
206}
VOID VmFuncSetMovToCr3Vmexit(UINT32 CoreId, BOOLEAN Set)
Set vm-exit for mov-to-cr3.
Definition Export.c:177
BOOLEAN IsWatingForMovCr3VmExits
Definition State.h:62

◆ ProcessEnableOrDisableThreadChangeMonitor()

VOID ProcessEnableOrDisableThreadChangeMonitor ( PROCESSOR_DEBUGGING_STATE * DbgState,
BOOLEAN Enable,
BOOLEAN IsSwitchByClockIntrrupt )

Enable or disable the process change monitoring detection on the running core.

should be called on vmx root

Parameters
DbgStateThe state of the debugger on the current core
Enable
IsSwitchByClockIntrrupt
Returns
VOID
223{
224 if (Enable)
225 {
226 //
227 // Set indicator process interception on the target core
228 //
230 DbgState->ThreadOrProcessTracingDetails.InitialSetByClockInterrupt = IsSwitchByClockIntrrupt;
231 }
232 else
233 {
234 //
235 // Avoid future sets/unsets
236 //
239 }
240
241 //
242 // Check whether we should intercept mov-to-cr3 vm-exits or intercept
243 // the clock interrupts
244 //
245 if (!IsSwitchByClockIntrrupt)
246 {
247 ProcessDetectChangeByMov2Cr3Vmexits(DbgState, Enable);
248 }
249 else
250 {
252 }
253}
VOID ProcessDetectChangeByMov2Cr3Vmexits(PROCESSOR_DEBUGGING_STATE *DbgState, BOOLEAN Enable)
Enable or disable the process change monitoring detection on the running core based on mov-to-cr3 vm-...
Definition Process.c:177
VOID ProcessDetectChangeByInterceptingClockInterrupts(PROCESSOR_DEBUGGING_STATE *DbgState, BOOLEAN Enable)
Enable or disable the process change monitoring detection on the running core based on intercepting c...
Definition Process.c:138
BOOLEAN InitialSetByClockInterrupt
Definition State.h:50
BOOLEAN InitialSetProcessChangeEvent
Definition State.h:47

◆ ProcessHandleProcessChange()

BOOLEAN ProcessHandleProcessChange ( PROCESSOR_DEBUGGING_STATE * DbgState)

handle process changes

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
43{
44 //
45 // Check if we reached to the target process or not
46 //
47 if ((g_ProcessSwitch.ProcessId != NULL_ZERO && g_ProcessSwitch.ProcessId == HANDLE_TO_UINT32(PsGetCurrentProcessId())) ||
48 (g_ProcessSwitch.Process != (UINT64)NULL && g_ProcessSwitch.Process == PsGetCurrentProcess()))
49 {
51
52 //
53 // Found
54 //
55 return TRUE;
56 }
57
58 //
59 // Not found
60 //
61 return FALSE;
62}
@ DEBUGGEE_PAUSING_REASON_DEBUGGEE_PROCESS_SWITCHED
Definition Connection.h:32
_Use_decl_annotations_ VOID KdHandleBreakpointAndDebugBreakpoints(PROCESSOR_DEBUGGING_STATE *DbgState, DEBUGGEE_PAUSING_REASON Reason, PDEBUGGER_TRIGGERED_EVENT_DETAILS EventDetails)
Handle #DBs and #BPs for kernel debugger.
Definition Kd.c:1214
#define HANDLE_TO_UINT32(_var)
Definition MetaMacros.h:39
DEBUGGEE_REQUEST_TO_CHANGE_PROCESS g_ProcessSwitch
Process switch to EPROCESS or Process ID.
Definition Global.h:67
UINT32 ProcessId
Definition Kd.h:40
PVOID Process
Definition Kd.h:41

◆ ProcessInterpretProcess()

BOOLEAN ProcessInterpretProcess ( PROCESSOR_DEBUGGING_STATE * DbgState,
PDEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET PidRequest )

change the current process @detail ONLY TO BE USED IN KD STUFFS

Parameters
DbgStateThe state of the debugger on the current core
PidRequest
Returns
BOOLEAN
526{
527 switch (PidRequest->ActionType)
528 {
530
531 //
532 // Debugger wants to know current pid, nt!_EPROCESS and process name
533 //
534 PidRequest->ProcessId = HANDLE_TO_UINT32(PsGetCurrentProcessId());
535 PidRequest->Process = (UINT64)PsGetCurrentProcess();
537
538 //
539 // Operation was successful
540 //
542
543 break;
544
546
547 //
548 // Perform the process switch
549 //
550 if (!ProcessSwitch(DbgState, PidRequest->ProcessId, (PEPROCESS)PidRequest->Process, PidRequest->IsSwitchByClkIntr))
551 {
553 break;
554 }
555
556 //
557 // Operation was successful
558 //
560
561 break;
562
564
565 //
566 // Show the process list
567 //
568 if (!ProcessShowList(&PidRequest->ProcessListSymDetails,
570 NULL,
571 NULL,
572 (UINT64)NULL))
573 {
575 break;
576 }
577
578 //
579 // Operation was successful
580 //
582
583 break;
584
585 default:
586
587 //
588 // Invalid type of action
589 //
591
592 break;
593 }
594
595 //
596 // Check if the above operation contains error
597 //
598 if (PidRequest->Result == DEBUGGER_OPERATION_WAS_SUCCESSFUL)
599 {
600 return TRUE;
601 }
602 else
603 {
604 return FALSE;
605 }
606}
#define DEBUGGER_ERROR_DETAILS_OR_SWITCH_PROCESS_INVALID_PARAMETER
error, for process switch or process details, invalid parameter
Definition ErrorCodes.h:233
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
BOOLEAN ProcessSwitch(PROCESSOR_DEBUGGING_STATE *DbgState, UINT32 ProcessId, PEPROCESS EProcess, BOOLEAN IsSwitchByClockIntrrupt)
make evnvironment ready to change the process
Definition Process.c:75
BOOLEAN ProcessShowList(PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS PorcessListSymbolInfo, DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTIONS QueryAction, UINT32 *CountOfProcesses, PVOID ListSaveBuffer, UINT64 ListSaveBuffSize)
shows the processes list
Definition Process.c:340
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_GET_PROCESS_DETAILS
Definition RequestStructures.h:912
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_GET_PROCESS_LIST
Definition RequestStructures.h:913
@ DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PERFORM_SWITCH
Definition RequestStructures.h:914
@ DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTION_SHOW_INSTANTLY
Definition RequestStructures.h:672
PCHAR CommonGetProcessNameFromProcessControlBlock(PEPROCESS Eprocess)
Get process name by eprocess.
Definition Common.c:48
DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS ProcessListSymDetails
Definition RequestStructures.h:930
UINT32 ProcessId
Definition RequestStructures.h:926
UINT64 Process
Definition RequestStructures.h:927
DEBUGGEE_DETAILS_AND_SWITCH_PROCESS_TYPE ActionType
Definition RequestStructures.h:925
UINT32 Result
Definition RequestStructures.h:931
BOOLEAN IsSwitchByClkIntr
Definition RequestStructures.h:928
UCHAR ProcessName[16]
Definition RequestStructures.h:929

◆ ProcessQueryCount()

BOOLEAN ProcessQueryCount ( PDEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS DebuggerUsermodeProcessOrThreadQueryRequest)

Query process details (count)

Parameters
DebuggerUsermodeProcessOrThreadQueryRequest
Returns
BOOLEAN
617{
618 BOOLEAN Result = FALSE;
619
620 //
621 // Getting the count results
622 //
623 Result = ProcessShowList(&DebuggerUsermodeProcessOrThreadQueryRequest->ProcessListNeededDetails,
625 &DebuggerUsermodeProcessOrThreadQueryRequest->Count,
626 NULL,
627 (UINT64)NULL);
628
629 if (Result && DebuggerUsermodeProcessOrThreadQueryRequest->Count != 0)
630 {
631 DebuggerUsermodeProcessOrThreadQueryRequest->Result = DEBUGGER_OPERATION_WAS_SUCCESSFUL;
632 return TRUE;
633 }
634
635 DebuggerUsermodeProcessOrThreadQueryRequest->Result = DEBUGGER_ERROR_UNABLE_TO_QUERY_COUNT_OF_PROCESSES_OR_THREADS;
636 return FALSE;
637}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define DEBUGGER_ERROR_UNABLE_TO_QUERY_COUNT_OF_PROCESSES_OR_THREADS
error, unable to query count of processes or threads
Definition ErrorCodes.h:386
@ DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTION_QUERY_COUNT
Definition RequestStructures.h:673
UINT32 Count
Definition RequestStructures.h:747
UINT64 Result
Definition RequestStructures.h:748
DEBUGGEE_PROCESS_LIST_NEEDED_DETAILS ProcessListNeededDetails
Definition RequestStructures.h:743

◆ ProcessQueryDetails()

BOOLEAN ProcessQueryDetails ( PDEBUGGEE_DETAILS_AND_SWITCH_PROCESS_PACKET GetInformationProcessRequest)

Query process details.

Parameters
GetInformationProcessRequest
Returns
BOOLEAN
676{
677 GetInformationProcessRequest->ProcessId = HANDLE_TO_UINT32(PsGetCurrentProcessId());
678 GetInformationProcessRequest->Process = (UINT64)PsGetCurrentProcess();
679 RtlCopyMemory(&GetInformationProcessRequest->ProcessName,
680 CommonGetProcessNameFromProcessControlBlock(PsGetCurrentProcess()),
681 15);
682
683 GetInformationProcessRequest->Result = DEBUGGER_OPERATION_WAS_SUCCESSFUL;
684
685 return TRUE;
686}

◆ ProcessQueryList()

BOOLEAN ProcessQueryList ( PDEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS DebuggerUsermodeProcessOrThreadQueryRequest,
PVOID AddressToSaveDetail,
UINT32 BufferSize )

Query process details (list)

Parameters
DebuggerUsermodeProcessOrThreadQueryRequest
AddressToSaveDetail
BufferSize
Returns
BOOLEAN
652{
653 BOOLEAN Result = FALSE;
654
655 //
656 // Getting the count results
657 //
658 Result = ProcessShowList(&DebuggerUsermodeProcessOrThreadQueryRequest->ProcessListNeededDetails,
660 NULL,
661 AddressToSaveDetail,
662 BufferSize);
663
664 return Result;
665}
@ DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTION_QUERY_SAVE_DETAILS
Definition RequestStructures.h:674

◆ ProcessShowList()

BOOLEAN ProcessShowList ( PDEBUGGEE_PROCESS_LIST_NEEDED_DETAILS PorcessListSymbolInfo,
DEBUGGER_QUERY_ACTIVE_PROCESSES_OR_THREADS_ACTIONS QueryAction,
UINT32 * CountOfProcesses,
PVOID ListSaveBuffer,
UINT64 ListSaveBuffSize )

shows the processes list

Parameters
PorcessListSymbolInfo
QueryAction
CountOfProcesses
ListSaveBuffer
ListSaveBuffSize
Returns
BOOLEAN
345{
346 UINT64 Process;
347 UINT64 UniquePid = 0;
348 LIST_ENTRY ActiveProcessLinks = {0};
349 UCHAR ImageFileName[15] = {0};
350 CR3_TYPE ProcessCr3 = {0};
351 UINT32 EnumerationCount = 0;
352 UINT32 MaximumBufferCount = 0;
353 PDEBUGGEE_PROCESS_LIST_DETAILS_ENTRY SavingEntries = ListSaveBuffer;
354
355 //
356 // validate parameters
357 //
359 CountOfProcesses == NULL)
360 {
361 return FALSE;
362 }
363
365 (ListSaveBuffer == NULL || ListSaveBuffSize == 0))
366 {
367 return FALSE;
368 }
369
370 //
371 // compute size to avoid overflow
372 //
374 {
375 MaximumBufferCount = (UINT32)(ListSaveBuffSize / sizeof(DEBUGGEE_PROCESS_LIST_DETAILS_ENTRY));
376 }
377
378 //
379 // Set the details derived from the symbols
380 //
381 UINT64 ActiveProcessHead = PorcessListSymbolInfo->PsActiveProcessHead; // nt!PsActiveProcessHead
382 ULONG ImageFileNameOffset = PorcessListSymbolInfo->ImageFileNameOffset; // nt!_EPROCESS.ImageFileName
383 ULONG UniquePidOffset = PorcessListSymbolInfo->UniquePidOffset; // nt!_EPROCESS.UniqueProcessId
384 ULONG ActiveProcessLinksOffset = PorcessListSymbolInfo->ActiveProcessLinksOffset; // nt!_EPROCESS.ActiveProcessLinks
385
386 //
387 // Dirty validation of parameters
388 //
389 if (ActiveProcessHead == NULL64_ZERO ||
390 ImageFileNameOffset == NULL_ZERO ||
391 UniquePidOffset == NULL_ZERO ||
392 ActiveProcessLinksOffset == NULL_ZERO)
393 {
394 return FALSE;
395 }
396
397 //
398 // Check if address is valid
399 //
400 if (CheckAccessValidityAndSafety(ActiveProcessHead, sizeof(BYTE)))
401 {
402 //
403 // Show processes list, we read everything from the view of system
404 // process
405 //
406 MemoryMapperReadMemorySafe(ActiveProcessHead, &ActiveProcessLinks, sizeof(ActiveProcessLinks));
407
408 //
409 // Find the top of EPROCESS from nt!_EPROCESS.ActiveProcessLinks
410 //
411 Process = (UINT64)ActiveProcessLinks.Flink - ActiveProcessLinksOffset;
412
413 do
414 {
415 //
416 // Read Process name, Process ID, CR3 of the target process
417 //
418 MemoryMapperReadMemorySafe(Process + ImageFileNameOffset,
419 &ImageFileName,
420 sizeof(ImageFileName));
421
422 MemoryMapperReadMemorySafe(Process + UniquePidOffset,
423 &UniquePid,
424 sizeof(UniquePid));
425
426 MemoryMapperReadMemorySafe(Process + ActiveProcessLinksOffset,
427 &ActiveProcessLinks,
428 sizeof(ActiveProcessLinks));
429
430 //
431 // Get the kernel CR3 for the target process
432 //
433 NT_KPROCESS * CurrentProcess = (NT_KPROCESS *)(Process);
434 ProcessCr3.Flags = CurrentProcess->DirectoryTableBase;
435
436 //
437 // Show the list of process
438 //
439 switch (QueryAction)
440 {
442
443 Log("PROCESS\t%llx\n\tProcess Id: %04x\tDirBase (Kernel Cr3): %016llx\tImage: %s\n\n",
444 Process,
445 UniquePid,
446 ProcessCr3.Flags,
447 ImageFileName);
448
450
451 EnumerationCount++;
452
453 break;
454
456
457 EnumerationCount++;
458
459 //
460 // Check to avoid overflow
461 //
462 if (EnumerationCount == MaximumBufferCount - 1)
463 {
464 //
465 // buffer is full
466 //
467 goto ReturnEnd;
468 }
469
470 //
471 // Save the details
472 //
473 SavingEntries[EnumerationCount - 1].Eprocess = Process;
474 SavingEntries[EnumerationCount - 1].ProcessId = (UINT32)UniquePid;
475 SavingEntries[EnumerationCount - 1].Cr3 = ProcessCr3.Flags;
476 RtlCopyMemory(&SavingEntries[EnumerationCount - 1].ImageFileName, ImageFileName, 15);
477
478 break;
479
480 default:
481
482 LogError("Err, invalid action specified for process enumeration");
483
484 break;
485 }
486
487 //
488 // Find the next process from the list of this process
489 //
490 Process = (UINT64)ActiveProcessLinks.Flink - ActiveProcessLinksOffset;
491
492 } while ((UINT64)ActiveProcessLinks.Flink != ActiveProcessHead);
493 }
494 else
495 {
496 //
497 // An invalid address is specified by the debugger
498 //
499 return FALSE;
500 }
501
502ReturnEnd:
503
504 //
505 // In case of query count of processes, we'll set this parameter
506 //
508 {
509 *CountOfProcesses = EnumerationCount;
510 }
511
512 return TRUE;
513}
unsigned char UCHAR
Definition BasicTypes.h:35
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#define Log(format,...)
Log without any prefix.
Definition HyperDbgHyperLogIntrinsics.h:129
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113
CR3 Structure.
Definition BasicTypes.h:130
UINT64 Flags
Definition BasicTypes.h:133
The structure showing list of processes (details of each entry)
Definition RequestStructures.h:714
UINT64 Cr3
Definition RequestStructures.h:717
UINT32 ProcessId
Definition RequestStructures.h:716
UINT64 Eprocess
Definition RequestStructures.h:715
ULONG UniquePidOffset
Definition RequestStructures.h:687
ULONG ImageFileNameOffset
Definition RequestStructures.h:686
ULONG ActiveProcessLinksOffset
Definition RequestStructures.h:688
UINT64 PsActiveProcessHead
Definition RequestStructures.h:685
KPROCESS Brief structure.
Definition Common.h:265
ULONG_PTR DirectoryTableBase
Definition Common.h:268

◆ ProcessSwitch()

BOOLEAN ProcessSwitch ( PROCESSOR_DEBUGGING_STATE * DbgState,
UINT32 ProcessId,
PEPROCESS EProcess,
BOOLEAN IsSwitchByClockIntrrupt )

make evnvironment ready to change the process

Parameters
DbgStateThe state of the debugger on the current core
ProcessId
EProcess
IsSwitchByClockIntrrupt
Returns
BOOLEAN
79{
80 //
81 // Initialized with NULL
82 //
85
86 //
87 // Check to avoid invalid switch
88 //
89 if (ProcessId == NULL_ZERO && EProcess == (PEPROCESS)NULL)
90 {
91 return FALSE;
92 }
93
94 //
95 // Set the target process id, eprocess to switch
96 //
97 if (EProcess != NULL)
98 {
99 if (CheckAccessValidityAndSafety((UINT64)EProcess, sizeof(BYTE)))
100 {
101 g_ProcessSwitch.Process = (PVOID)EProcess;
102 }
103 else
104 {
105 //
106 // An invalid address is specified by user
107 //
108 return FALSE;
109 }
110 }
111 else if (ProcessId != NULL_ZERO)
112 {
113 g_ProcessSwitch.ProcessId = ProcessId;
114 }
115
116 //
117 // Send request for the target task to the halted cores (synchronized)
118 //
121 TRUE,
122 TRUE,
123 (PVOID)IsSwitchByClockIntrrupt);
124
125 return TRUE;
126}
BOOLEAN HaltedCoreBroadcastTaskAllCores(PROCESSOR_DEBUGGING_STATE *DbgState, UINT64 TargetTask, BOOLEAN LockAgainAfterTask, BOOLEAN Synchronize, PVOID Context)
Broadcast tasks to halted cores.
Definition HaltedCore.c:399
#define DEBUGGER_HALTED_CORE_TASK_SET_PROCESS_INTERCEPTION
Halted core task for setting process interception.
Definition HaltedCore.h:34
NULL()
Definition test-case-generator.py:530

◆ ProcessTriggerCr3ProcessChange()

VOID ProcessTriggerCr3ProcessChange ( UINT32 CoreId)

handle process changes for cr3 registers

Parameters
CoreId
Returns
VOID
23{
24 PROCESSOR_DEBUGGING_STATE * DbgState = &g_DbgState[CoreId];
25
26 //
27 // Call kernel debugger handler for mov to cr3 in kernel debugger
28 //
30 {
32 }
33}
BOOLEAN ProcessHandleProcessChange(PROCESSOR_DEBUGGING_STATE *DbgState)
handle process changes
Definition Process.c:42
PROCESSOR_DEBUGGING_STATE * g_DbgState
Save the state and variables related to debugging on each to logical core.
Definition Global.h:17
Saves the debugger state.
Definition State.h:165