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

Header for attaching and detaching for debugging user-mode processes. More...

Go to the source code of this file.

Macros

#define MAX_USER_ACTIONS_FOR_THREADS   3
 Maximum actions in paused threads storage.
#define MAX_THREADS_IN_A_PROCESS_HOLDER   100
 Maximum threads that a process thread holder might have.

Functions

BOOLEAN AttachingInitialize ()
 Initialize the attaching mechanism.
BOOLEAN AttachingCheckThreadInterceptionWithUserDebugger (UINT32 CoreId)
 Check thread interceptions with user-mode debugger.
BOOLEAN AttachingConfigureInterceptingThreads (UINT64 ProcessDebuggingToken, BOOLEAN Enable)
 Enable or disable the thread intercepting phase.
VOID AttachingTargetProcess (PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS Request)
 Dispatch and perform attaching tasks.
VOID AttachingHandleEntrypointInterception (PROCESSOR_DEBUGGING_STATE *DbgState)
 Handle the interception of finding the entrypoint on attaching to user-mode process.
VOID AttachingRemoveAndFreeAllProcessDebuggingDetails ()
 Remove and deallocate all thread debuggig details.
PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByToken (UINT64 Token)
 Find user-mode debugging details for threads by token.
PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByProcessId (UINT32 ProcessId)
 Find user-mode debugging details for threads by process Id.
BOOLEAN AttachingQueryDetailsOfActiveDebuggingThreadsAndProcesses (PVOID BufferToStoreDetails, UINT32 BufferSize)
 Query details of active debugging threads.
BOOLEAN AttachingCheckUnhandledEptViolation (UINT32 CoreId, UINT64 ViolationQualification, UINT64 GuestPhysicalAddr)
 handling unhandled EPT violations
BOOLEAN AttachingReachedToValidLoadedModule (PROCESSOR_DEBUGGING_STATE *DbgState, PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
 Handle cases where we reached to the valid loaded module The main module should be loaded once we reach to this function.

Detailed Description

Header for attaching and detaching for debugging user-mode processes.

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

Macro Definition Documentation

◆ MAX_THREADS_IN_A_PROCESS_HOLDER

#define MAX_THREADS_IN_A_PROCESS_HOLDER   100

Maximum threads that a process thread holder might have.

◆ MAX_USER_ACTIONS_FOR_THREADS

#define MAX_USER_ACTIONS_FOR_THREADS   3

Maximum actions in paused threads storage.

Function Documentation

◆ AttachingCheckThreadInterceptionWithUserDebugger()

BOOLEAN AttachingCheckThreadInterceptionWithUserDebugger ( UINT32 CoreId)

Check thread interceptions with user-mode debugger.

Parameters
CoreId
Returns
BOOLEAN if TRUE show that the thread interceptin is handled otherwise FALSE
626{
627 PROCESSOR_DEBUGGING_STATE * DbgState = &g_DbgState[CoreId];
628 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail;
629
630 //
631 // Check whether user-debugger is initialized or not
632 //
634 {
635 return FALSE;
636 }
637
638 ProcessDebuggingDetail = AttachingFindProcessDebuggingDetailsByProcessId(HANDLE_TO_UINT32(PsGetCurrentProcessId()));
639
640 //
641 // Check if the process debugging detail is found
642 //
643 if (!ProcessDebuggingDetail)
644 {
645 //
646 // not related to user debugger
647 //
648 return FALSE;
649 }
650
651 //
652 // Check if thread is in the intercepting phase
653 //
654 if (ProcessDebuggingDetail->IsOnThreadInterceptingPhase)
655 {
656 //
657 // Handling state through the user-mode debugger
658 //
661 NULL))
662 {
663 //
664 // Check for possible commands that need to be executed
665 //
666 UdCheckForCommand(DbgState, ProcessDebuggingDetail);
667
668 return TRUE;
669 }
670 }
671
672 //
673 // this thread is not in intercepting phase
674 //
675 return FALSE;
676}
PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByProcessId(UINT32 ProcessId)
Find user-mode debugging details for threads by process Id.
Definition Attaching.c:184
#define HANDLE_TO_UINT32(_var)
Definition MetaMacros.h:39
BOOLEAN UdCheckForCommand(PROCESSOR_DEBUGGING_STATE *DbgState, PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
Check for the user-mode commands.
Definition Ud.c:558
BOOLEAN UdCheckAndHandleBreakpointsAndDebugBreaks(PROCESSOR_DEBUGGING_STATE *DbgState, DEBUGGEE_PAUSING_REASON Reason, PDEBUGGER_TRIGGERED_EVENT_DETAILS EventDetails)
Handle DBs and BPs for kernel debugger.
Definition Ud.c:812
#define TRUE
Definition BasicTypes.h:114
#define FALSE
Definition BasicTypes.h:113
@ DEBUGGEE_PAUSING_REASON_DEBUGGEE_GENERAL_THREAD_INTERCEPTED
Definition Connection.h:42
PROCESSOR_DEBUGGING_STATE * g_DbgState
Save the state and variables related to debugging on each to logical core.
Definition Global.h:17
BOOLEAN g_UserDebuggerState
shows whether the user debugger is enabled or disabled
Definition Global.h:157
struct _PROCESSOR_DEBUGGING_STATE PROCESSOR_DEBUGGING_STATE
Saves the debugger state.
struct _USERMODE_DEBUGGING_PROCESS_DETAILS * PUSERMODE_DEBUGGING_PROCESS_DETAILS
BOOLEAN IsOnThreadInterceptingPhase
Definition Ud.h:38

◆ AttachingCheckUnhandledEptViolation()

BOOLEAN AttachingCheckUnhandledEptViolation ( UINT32 CoreId,
UINT64 ViolationQualification,
UINT64 GuestPhysicalAddr )

handling unhandled EPT violations

Parameters
CoreId
ViolationQualification
GuestPhysicalAddr
Returns
BOOLEAN
979{
980 UNREFERENCED_PARAMETER(CoreId);
981 UNREFERENCED_PARAMETER(ViolationQualification);
982 UNREFERENCED_PARAMETER(GuestPhysicalAddr);
983
984 //
985 // Not handled here
986 //
987 return FALSE;
988}

◆ AttachingConfigureInterceptingThreads()

BOOLEAN AttachingConfigureInterceptingThreads ( UINT64 ProcessDebuggingToken,
BOOLEAN Enable )

Enable or disable the thread intercepting phase.

this function should be called in vmx non-root

Parameters
ProcessDebuggingToken
Enable
Returns
BOOLEAN
688{
689 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail;
690
691 //
692 // Get the current process debugging detail
693 //
694 ProcessDebuggingDetail = AttachingFindProcessDebuggingDetailsByToken(ProcessDebuggingToken);
695
696 if (!ProcessDebuggingDetail)
697 {
698 return FALSE;
699 }
700
701 //
702 // If the thread is already in intercepting phase, we should return,
703 //
704 if (Enable && ProcessDebuggingDetail->IsOnThreadInterceptingPhase)
705 {
706 LogError("Err, thread is already in intercepting phase");
707 return FALSE;
708 }
709
710 //
711 // We're or we're not in thread intercepting phase now
712 //
713 ProcessDebuggingDetail->IsOnThreadInterceptingPhase = Enable;
714
715 //
716 // Intercepting threads is enabled
717 //
718 if (Enable)
719 {
720 //
721 // Add the process to the watching list to be able to intercept the threads
722 //
724 }
725 else
726 {
727 //
728 // Unpause the threads of the target process
729 //
730 ThreadHolderUnpauseAllThreadsInProcess(ProcessDebuggingDetail);
731
732 //
733 // Remove the process from the watching list
734 //
736 }
737
738 return TRUE;
739}
PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByToken(UINT64 Token)
Find user-mode debugging details for threads by token.
Definition Attaching.c:161
BOOLEAN ThreadHolderUnpauseAllThreadsInProcess(PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
Unpause all threads in the process debugging details.
Definition ThreadHolder.c:108
#define LogError(format,...)
Log in the case of error.
Definition HyperDbgHyperLogIntrinsics.h:113
IMPORT_EXPORT_VMM BOOLEAN ConfigureExecTrapAddProcessToWatchingList(UINT32 ProcessId)
Add the target process to the watching list.
Definition Configuration.c:67
IMPORT_EXPORT_VMM BOOLEAN ConfigureExecTrapRemoveProcessFromWatchingList(UINT32 ProcessId)
Remove the target process from the watching list.
Definition Configuration.c:79
UINT32 ProcessId
Definition Ud.h:35

◆ AttachingFindProcessDebuggingDetailsByProcessId()

PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByProcessId ( UINT32 ProcessId)

Find user-mode debugging details for threads by process Id.

Parameters
ProcessId
Returns
PUSERMODE_DEBUGGING_PROCESS_DETAILS
185{
187 {
188 //
189 // Check if we found the target thread and if it's enabled
190 //
191 if (ProcessDebuggingDetails->ProcessId == ProcessId && ProcessDebuggingDetails->Enabled)
192 {
193 return ProcessDebuggingDetails;
194 }
195 }
196
197 return NULL;
198}
#define LIST_FOR_EACH_LINK(_head, _struct_type, _member, _var)
Definition MetaMacros.h:34
LIST_ENTRY g_ProcessDebuggingDetailsListHead
List header of thread debugging details.
Definition Global.h:200
struct _USERMODE_DEBUGGING_PROCESS_DETAILS USERMODE_DEBUGGING_PROCESS_DETAILS
Description of each active thread in user-mode attaching mechanism.
NULL()
Definition test-case-generator.py:530

◆ AttachingFindProcessDebuggingDetailsByToken()

PUSERMODE_DEBUGGING_PROCESS_DETAILS AttachingFindProcessDebuggingDetailsByToken ( UINT64 Token)

Find user-mode debugging details for threads by token.

Parameters
Token
Returns
PUSERMODE_DEBUGGING_PROCESS_DETAILS
162{
164 {
165 //
166 // Check if we found the target thread and if it's enabled
167 //
168 if (ProcessDebuggingDetails->Token == Token && ProcessDebuggingDetails->Enabled)
169 {
170 return ProcessDebuggingDetails;
171 }
172 }
173
174 return NULL;
175}

◆ AttachingHandleEntrypointInterception()

VOID AttachingHandleEntrypointInterception ( PROCESSOR_DEBUGGING_STATE * DbgState)

Handle the interception of finding the entrypoint on attaching to user-mode process.

Parameters
DbgStateThe state of the debugger on the current core
Returns
VOID
442{
443 PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail = NULL;
444 PAGE_FAULT_EXCEPTION PageFaultErrorCode = {0};
445
446 //
447 // Not increment the RIP register as no instruction is intended to go
448 //
450
451 ProcessDebuggingDetail = AttachingFindProcessDebuggingDetailsByProcessId(HANDLE_TO_UINT32(PsGetCurrentProcessId()));
452
453 //
454 // Check to only break on the target process id and thread id and when
455 // the entrypoint is not called, if the thread debugging detail is found
456 //
457 if (ProcessDebuggingDetail != NULL)
458 {
460 {
461 //
462 // Show a message that we reached to the entrypoint
463 //
464 // Log("Reached to the main module entrypoint (%016llx)\n", VmFuncGetLastVmexitRip(DbgState->CoreId));
465
466 //
467 // Not waiting for these event anymore
468 //
470
471 //
472 // Whenever Windows calls the start entrypoint of the target PE, initially,
473 // the module is not loaded in the memory, thus a page-fault will happen and
474 // the page-fault handler will bring the module content to the memory and after
475 // that, the start entrypoint of PE is called again
476 // It's not possible for us to handle everything here without checking for the
477 // possible page-fault, it is because the first instruction is not available to be
478 // read from the memory, thus, it shows a wrong instruction and the user might not
479 // use the instrumentation step-in from the start up of the entrypoint.
480 // Because if the user uses the instrumentation step-in command then it should go
481 // the page-fault handler routine in the kernel and it's not what the user expects
482 // we inject a #PF here and let the Windows handle the page-fault. Meanwhile, we
483 // set the hardware debug breakpoint again at the start of the entrypoint, so, the
484 // next time that the instruction is about to be fetched, a vm-exit happens as a
485 // result of intercepting #DBs
486 // In some cases, there is no need to inject #PF to the guest. One example is when
487 // the target page is already available in the memory like the same process is also
488 // open in the debuggee. In these cases, we handle the break directly without injecting
489 // any page-fault
490 //
491
492 if (!CheckAccessValidityAndSafety(ProcessDebuggingDetail->EntrypointOfMainModule, sizeof(CHAR)))
493 {
494 // LogInfo("Injecting #PF for entrypoint at : %llx", ProcessDebuggingDetail->EntrypointOfMainModule);
495
496 //
497 // We're waiting for this pointer to be called again after handling page-fault
498 //
500
501 //
502 // Create page-fault error code (user, fetch #PF)
503 //
504 PageFaultErrorCode.AsUInt = 0x14;
505
506 //
507 // Inject the page-fault
508 //
510 ProcessDebuggingDetail->EntrypointOfMainModule,
511 PageFaultErrorCode.AsUInt);
512
513 //
514 // Also, set the RFLAGS.TF to intercept the process (thread) again after inject #PF
515 //
517
518 //
519 // Indicate that we should set the trap flag to the FALSE next time on
520 // the same process/thread
521 //
522 if (!BreakpointRestoreTheTrapFlagOnceTriggered(HANDLE_TO_UINT32(PsGetCurrentProcessId()), HANDLE_TO_UINT32(PsGetCurrentThreadId())))
523 {
524 LogWarning("Warning, it is currently not possible to add the current process/thread to the list of processes "
525 "where the trap flag should be masked. Please ensure that you manually unset the trap flag");
526 }
527 }
528 else
529 {
530 //
531 // Address is valid, probably the module is previously loaded
532 // or another process with same image is currently running
533 // Thus, there is no need to inject #PF, we'll handle it in debugger
534 //
535 AttachingReachedToValidLoadedModule(DbgState, ProcessDebuggingDetail);
536 }
537 }
539 {
540 //
541 // not waiting for a break after the page-fault anymore
542 //
544
545 //
546 // We reached here as a result of setting the trap flag after
547 // injecting a page-fault
548 //
549 AttachingReachedToValidLoadedModule(DbgState, ProcessDebuggingDetail);
550 }
551 }
552}
BOOLEAN AttachingReachedToValidLoadedModule(PROCESSOR_DEBUGGING_STATE *DbgState, PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
Handle cases where we reached to the valid loaded module The main module should be loaded once we rea...
Definition Attaching.c:345
BOOLEAN BreakpointRestoreTheTrapFlagOnceTriggered(UINT32 ProcessId, UINT32 ThreadId)
This function makes sure to unset the RFLAGS.TF on next trigger of DB on the target process/thread.
Definition BreakpointCommands.c:174
char CHAR
Definition BasicTypes.h:33
#define LogWarning(format,...)
Log in the case of warning.
Definition HyperDbgHyperLogIntrinsics.h:99
IMPORT_EXPORT_VMM VOID VmFuncSetRflagTrapFlag(BOOLEAN Set)
Set Rflag's trap flag.
Definition Export.c:123
IMPORT_EXPORT_VMM BOOLEAN CheckAccessValidityAndSafety(UINT64 TargetAddress, UINT32 Size)
Check the safety to access the memory.
Definition AddressCheck.c:318
IMPORT_EXPORT_VMM VOID VmFuncSuppressRipIncrement(UINT32 CoreId)
Suppress the incrementation of RIP.
Definition Export.c:34
IMPORT_EXPORT_VMM VOID VmFuncEventInjectPageFaultWithCr2(UINT32 CoreId, UINT64 Address, UINT32 PageFaultCode)
Inject PF and configure CR2 register.
Definition Export.c:900
BOOLEAN g_IsWaitingForReturnAndRunFromPageFault
Whether the thread attaching mechanism is waiting for a page-fault finish or not.
Definition Global.h:194
BOOLEAN g_IsWaitingForUserModeProcessEntryToBeCalled
Whether the thread attaching mechanism is waiting for DB or not.
Definition Global.h:206
UINT32 CoreId
Definition State.h:168
UINT64 EntrypointOfMainModule
Definition Ud.h:32

◆ AttachingInitialize()

BOOLEAN AttachingInitialize ( )

Initialize the attaching mechanism.

as we use the functionalities for these functions, we initialize them from the debugger at start up of debugger (not initialization of user-debugger)

Returns
BOOLEAN
23{
24 UNICODE_STRING FunctionName;
25
26 //
27 // Find address of PsGetProcessPeb
28 //
29 if (g_PsGetProcessPeb == NULL)
30 {
31 RtlInitUnicodeString(&FunctionName, L"PsGetProcessPeb");
32 g_PsGetProcessPeb = (PsGetProcessPeb)MmGetSystemRoutineAddress(&FunctionName);
33
34 if (g_PsGetProcessPeb == NULL)
35 {
36 LogError("Err, cannot resolve PsGetProcessPeb");
37
38 //
39 // Won't fail the entire debugger for not finding this
40 //
41 // return FALSE;
42 }
43 }
44
45 //
46 // Find address of PsGetProcessWow64Process
47 //
49 {
50 RtlInitUnicodeString(&FunctionName, L"PsGetProcessWow64Process");
51 g_PsGetProcessWow64Process = (PsGetProcessWow64Process)MmGetSystemRoutineAddress(&FunctionName);
52
54 {
55 LogError("Err, cannot resolve PsGetProcessPeb");
56
57 //
58 // Won't fail the entire debugger for not finding this
59 //
60 // return FALSE;
61 }
62 }
63
64 //
65 // Find address of ZwQueryInformationProcess
66 //
68 {
69 UNICODE_STRING RoutineName;
70
71 RtlInitUnicodeString(&RoutineName, L"ZwQueryInformationProcess");
72
73 g_ZwQueryInformationProcess = (ZwQueryInformationProcess)MmGetSystemRoutineAddress(&RoutineName);
74
76 {
77 LogError("Err, cannot resolve ZwQueryInformationProcess");
78
79 //
80 // Won't fail the entire debugger for not finding this
81 //
82 // return FALSE;
83 }
84 }
85
86 return TRUE;
87}
ZwQueryInformationProcess g_ZwQueryInformationProcess
Address of ZwQueryInformationProcess.
Definition UserAccess.h:187
PsGetProcessPeb g_PsGetProcessPeb
Address of PsGetProcessPeb.
Definition UserAccess.h:193
PPEB32(NTAPI * PsGetProcessWow64Process)(PEPROCESS Process)
Definition UserAccess.h:177
PsGetProcessWow64Process g_PsGetProcessWow64Process
Address of PsGetProcessWow64Process.
Definition UserAccess.h:199
NTSTATUS(* ZwQueryInformationProcess)(__in HANDLE ProcessHandle, __in PROCESSINFOCLASS ProcessInformationClass, __out_bcount(ProcessInformationLength) PVOID ProcessInformation, __in ULONG ProcessInformationLength, __out_opt PULONG ReturnLength)
Definition UserAccess.h:168
PPEB(NTAPI * PsGetProcessPeb)(PEPROCESS Process)
Definition UserAccess.h:175
struct _UNICODE_STRING UNICODE_STRING

◆ AttachingQueryDetailsOfActiveDebuggingThreadsAndProcesses()

BOOLEAN AttachingQueryDetailsOfActiveDebuggingThreadsAndProcesses ( PVOID BufferToStoreDetails,
UINT32 BufferSize )

Query details of active debugging threads.

Parameters
BufferToStoreDetails
BufferSize
Returns
BOOLEAN
1394{
1395 UINT32 CountOfProcessesAndThreadsToStore;
1396
1397 CountOfProcessesAndThreadsToStore = BufferSize / SIZEOF_USERMODE_DEBUGGING_THREAD_OR_PROCESS_STATE_DETAILS;
1398
1399 if (CountOfProcessesAndThreadsToStore == 0)
1400 {
1401 //
1402 // No active thread or process
1403 //
1404 return FALSE;
1405 }
1406
1407 // LogInfo("Count of active process and threads : %x", CountOfProcessesAndThreadsToStore);
1408
1409 //
1410 // Get the results
1411 //
1412 ThreadHolderQueryDetailsOfActiveDebuggingThreadsAndProcesses(BufferToStoreDetails, CountOfProcessesAndThreadsToStore);
1413
1414 return TRUE;
1415}
VOID ThreadHolderQueryDetailsOfActiveDebuggingThreadsAndProcesses(USERMODE_DEBUGGING_THREAD_OR_PROCESS_STATE_DETAILS *BufferToStoreDetails, UINT32 MaxCount)
Query details of active debugging threads and processes.
Definition ThreadHolder.c:585
unsigned int UINT32
Definition BasicTypes.h:54
#define SIZEOF_USERMODE_DEBUGGING_THREAD_OR_PROCESS_STATE_DETAILS
Definition RequestStructures.h:860

◆ AttachingReachedToValidLoadedModule()

BOOLEAN AttachingReachedToValidLoadedModule ( PROCESSOR_DEBUGGING_STATE * DbgState,
PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail )

Handle cases where we reached to the valid loaded module The main module should be loaded once we reach to this function.

Parameters
DbgStateThe state of the debugger on the current core
ProcessDebuggingDetail
Returns
BOOLEAN
347{
348 DEBUGGEE_BP_PACKET BpRequest = {0};
349
350 //
351 // Double check to make sure the main module is loaded
352 //
353 if (!CheckAccessValidityAndSafety(ProcessDebuggingDetail->EntrypointOfMainModule, sizeof(CHAR)))
354 {
355 LogError("Err, the main module is not loaded or the main entrypoint is not valid");
356 return FALSE;
357 }
358
359 //
360 // Setting a breakpoint to the main entrypoint of the module
361 //
362 BpRequest.Address = ProcessDebuggingDetail->EntrypointOfMainModule;
366
367 //
368 // Remove the breakpoint after hit
369 //
370 BpRequest.RemoveAfterHit = TRUE;
371
372 //
373 // Check if the process needs to check for callbacks for the very first instruction
374 //
375 if (ProcessDebuggingDetail->CheckCallBackForInterceptingFirstInstruction)
376 {
377 //
378 // This breakpoint should check for callbacks
379 //
380 BpRequest.CheckForCallbacks = TRUE;
381 }
382
383 //
384 // Register the breakpoint
385 // Note that, even though it's a user-mode breakpoint, we are currently
386 // in the memory layout of the target process, thus, no switching memory
387 // layout is needed
388 //
389 if (!BreakpointAddNew(&BpRequest, FALSE))
390 {
391 LogError("Err, unable to set breakpoint on the entrypoint module");
392 return FALSE;
393 }
394
395 //
396 // Finish the starting point of the thread
397 //
399
400 //
401 // Check if we're connect to the kHyperDbg or uHyperDbg
402 //
404 {
405 //
406 // Handling state through the kernel-mode debugger
407 //
410 NULL);
411 }
412 else if (g_UserDebuggerState)
413 {
414 //
415 // Handling state through the user-mode debugger
416 //
417 UdHandleInstantBreak(DbgState,
419 ProcessDebuggingDetail);
420 }
421 else
422 {
423 LogError("Err, no debugger is attached to handle the entrypoint interception");
424 return FALSE;
425 }
426
427 //
428 // Handled successfully
429 //
430 return TRUE;
431}
BOOLEAN AttachingSetStartingPhaseOfProcessDebuggingDetailsByToken(BOOLEAN Set, UINT64 Token)
Set the start up phase of a debugging thread buffer by its token.
Definition Attaching.c:297
BOOLEAN BreakpointAddNew(PDEBUGGEE_BP_PACKET BpDescriptorArg, BOOLEAN SwitchToTargetMemoryLayout)
Add new breakpoints.
Definition BreakpointCommands.c:950
_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:1291
BOOLEAN UdHandleInstantBreak(PROCESSOR_DEBUGGING_STATE *DbgState, DEBUGGEE_PAUSING_REASON Reason, PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
Handle cases where we instant break is needed on the user debugger.
Definition Ud.c:122
@ DEBUGGEE_PAUSING_REASON_DEBUGGEE_STARTING_MODULE_LOADED
Definition Connection.h:36
#define DEBUGGEE_BP_APPLY_TO_ALL_PROCESSES
The constant to apply to all processes for bp command.
Definition Constants.h:781
#define DEBUGGEE_BP_APPLY_TO_ALL_THREADS
The constant to apply to all threads for bp command.
Definition Constants.h:787
#define DEBUGGEE_BP_APPLY_TO_ALL_CORES
The constant to apply to all cores for bp command.
Definition Constants.h:775
struct _DEBUGGEE_BP_PACKET DEBUGGEE_BP_PACKET
The structure of bp command packet in HyperDbg.
BOOLEAN g_KernelDebuggerState
shows whether the kernel debugger is enabled or disabled
Definition Global.h:151
UINT32 Tid
Definition RequestStructures.h:1519
BOOLEAN RemoveAfterHit
Definition RequestStructures.h:1521
UINT32 Core
Definition RequestStructures.h:1520
BOOLEAN CheckForCallbacks
Definition RequestStructures.h:1522
UINT64 Address
Definition RequestStructures.h:1517
UINT32 Pid
Definition RequestStructures.h:1518
UINT64 Token
Definition Ud.h:25
BOOLEAN CheckCallBackForInterceptingFirstInstruction
Definition Ud.h:39

◆ AttachingRemoveAndFreeAllProcessDebuggingDetails()

VOID AttachingRemoveAndFreeAllProcessDebuggingDetails ( )

Remove and deallocate all thread debuggig details.

Returns
VOID
227{
229 {
230 //
231 // Free the thread holding structure(s)
232 //
233 ThreadHolderFreeHoldingStructures(ProcessDebuggingDetails);
234
235 //
236 // Remove thread debugging detail from the list active threads
237 //
238 RemoveEntryList(&ProcessDebuggingDetails->AttachedProcessList);
239
240 //
241 // Unallocate the pool
242 //
243 PlatformMemFreePool(ProcessDebuggingDetails);
244 }
245}
PVOID PlatformMemFreePool(PVOID BufferAddress)
Frees a memory pool.
Definition PlatformMem.c:269
VOID ThreadHolderFreeHoldingStructures(PUSERMODE_DEBUGGING_PROCESS_DETAILS ProcessDebuggingDetail)
Free all of thread holder structures.
Definition ThreadHolder.c:501

◆ AttachingTargetProcess()

VOID AttachingTargetProcess ( PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS Request)

Dispatch and perform attaching tasks.

this function should not be called in vmx-root

Parameters
AttachRequest
Returns
VOID
1426{
1427 //
1428 // As we're here, we need to initialize the user-mode debugger
1429 //
1431 {
1433 return;
1434 }
1435
1436 switch (Request->Action)
1437 {
1439
1441
1442 break;
1443
1445
1446 AttachingPerformDetach(Request);
1447
1448 break;
1449
1451
1452 AttachingRemoveHooks(Request);
1453
1454 break;
1455
1457
1458 AttachingKillProcess(Request);
1459
1460 break;
1461
1463
1464 AttachingContinueProcess(Request);
1465
1466 break;
1467
1469
1470 AttachingPauseProcess(Request);
1471
1472 break;
1473
1475
1476 AttachingSwitchProcess(Request);
1477
1478 break;
1479
1481
1483
1484 break;
1485
1486 default:
1487
1489
1490 break;
1491 }
1492}
BOOLEAN AttachingSwitchProcess(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS SwitchRequest)
Switch to the target thread.
Definition Attaching.c:1273
BOOLEAN AttachingPerformDetach(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS DetachRequest)
Clearing hooks after resuming the process.
Definition Attaching.c:1220
BOOLEAN AttachingPerformAttachToProcess(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS AttachRequest, BOOLEAN IsAttachingToEntrypoint)
Attach to the target process.
Definition Attaching.c:776
BOOLEAN AttachingPauseProcess(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS PauseRequest)
Pauses the target process.
Definition Attaching.c:1059
BOOLEAN AttachingQueryCountOfActiveDebuggingThreadsAndProcesses(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS QueryCountOfDebugThreadsRequest)
Query count of active debugging threads.
Definition Attaching.c:1367
BOOLEAN AttachingRemoveHooks(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS AttachRequest)
Clearing hooks after resuming the process.
Definition Attaching.c:998
BOOLEAN AttachingKillProcess(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS KillRequest)
Kill the target process from kernel-mode.
Definition Attaching.c:1128
BOOLEAN AttachingContinueProcess(PDEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS ContinueRequest)
Continues the target process.
Definition Attaching.c:1084
BOOLEAN UdInitializeUserDebugger()
initialize user debugger
Definition Ud.c:21
#define DEBUGGER_ERROR_DEBUGGER_NOT_INITIALIZED
error, the user debugger cannot be initialized
Definition ErrorCodes.h:558
#define DEBUGGER_ERROR_INVALID_ACTION_TYPE
error, invalid type of action
Definition ErrorCodes.h:39
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_DETACH
Definition RequestStructures.h:665
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_QUERY_COUNT_OF_ACTIVE_DEBUGGING_THREADS
Definition RequestStructures.h:671
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_CONTINUE_PROCESS
Definition RequestStructures.h:668
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_KILL_PROCESS
Definition RequestStructures.h:667
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_SWITCH_BY_PROCESS_OR_THREAD
Definition RequestStructures.h:670
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_PAUSE_PROCESS
Definition RequestStructures.h:669
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_ATTACH
Definition RequestStructures.h:664
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_REMOVE_HOOKS
Definition RequestStructures.h:666
DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_TYPE Action
Definition RequestStructures.h:690
BOOLEAN IsStartingNewProcess
Definition RequestStructures.h:681
UINT64 Result
Definition RequestStructures.h:693