Attach to target process. 
  353{
  355    ULONG                                    ReturnedLength;
 
  357    PROCESS_INFORMATION                      ProcInfo      = {0};
  358 
  359    
  360    
  361    
  363 
  364    
  365    
  366    
  368 
  369    
  370    
  371    
  372    if (TargetFileAddress == NULL)
  373    {
  375    }
  376    else
  377    {
  379    }
  380 
  381    
  382    
  383    
  385 
  386    
  387    
  388    
  390 
  392    {
  393        
  394        
  395        
  397        {
  398            ShowMessages(
"err, unable to start (file not found)\n");
 
  400        }
  401 
  402        
  403        
  404        
  406 
  407        
  408        
  409        
  410        AttachRequest.
ProcessId = ProcInfo.dwProcessId;
 
  411        AttachRequest.
ThreadId  = ProcInfo.dwThreadId;
 
  412    }
  413    else
  414    {
  415        
  416        
  417        
  419    }
  420 
  421    
  422    
  423    
  424    Status = DeviceIoControl(
  427                                                         
  428        &AttachRequest,                                  
  430        &AttachRequest,                                  
  432                                                         
  433        &ReturnedLength,                                 
  434        NULL                                             
  435    );
  436 
  437    if (!Status)
  438    {
  439        ShowMessages(
"ioctl failed with code 0x%x\n", GetLastError());
 
  441    }
  442 
  443    
  444    
  445    
  447    {
  449        {
  450            
  451            
  452            
  453            ShowMessages(
"successfully attached to the target process!\n" 
  454                         "please keep interacting with the process until all the "
  455                         "threads are intercepted and halted; whenever you execute "
  456                         "the first command, the thread interception will be stopped\n");
  458        }
  459 
  460        
  461        
  462 
  463        
  464        
  465        
  467        {
  468            ResumeThread(ProcInfo.hThread);
  469        }
  470        else
  471        {
  472            
  473            
  474            
  476        }
  477 
  478        
  479        
  480        
  481 
  483        {
  484            
  485            
  486            
  488 
  489            
  490            
  491            
  492            Status = DeviceIoControl(
  495                                                                 
  496                &AttachRequest,                                  
  498                &AttachRequest,                                  
  500                                                                 
  501                &ReturnedLength,                                 
  502                NULL                                             
  503            );
  504 
  505            if (!Status)
  506            {
  507                ShowMessages(
"ioctl failed with code 0x%x\n", GetLastError());
 
  509            }
  510 
  511            
  512            
  513            
  514            
  516            {
  517                
  518                
  519                
  520                break;
  521            }
  523            {
  524                
  525                
  526                
  527                
  528 
  529                Sleep(1000);
  530                continue;
  531            }
  532            else
  533            {
  534                
  535                
  536                
  539            }
  540        }
  541 
  542        
  543        
  544        
  546 
  547        
  548        
  549        
  551    }
  552    else
  553    {
  556    }
  557 
  559}
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define NULL64_ZERO
Definition BasicTypes.h:52
#define TRUE
Definition BasicTypes.h:55
#define FALSE
Definition BasicTypes.h:54
unsigned int UINT32
Definition BasicTypes.h:48
unsigned long ULONG
Definition BasicTypes.h:37
#define DEBUGGER_ERROR_UNABLE_TO_REMOVE_HOOKS_ENTRYPOINT_NOT_REACHED
error, failed to remove hooks as entrypoint is not reached yet
Definition ErrorCodes.h:302
#define DEBUGGER_OPERATION_WAS_SUCCESSFUL
General value to indicate that the operation or request was successful.
Definition ErrorCodes.h:23
#define IOCTL_DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS
ioctl, attach or detach user-mode processes
Definition Ioctls.h:162
#define SIZEOF_DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS
Definition RequestStructures.h:607
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_ATTACH
Definition RequestStructures.h:616
@ DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_REMOVE_HOOKS
Definition RequestStructures.h:618
BOOLEAN IsFileExistW(const wchar_t *FileName)
check if a file exist or not (wide-char)
Definition common.cpp:632
BOOLEAN ShowErrorMessage(UINT32 Error)
shows the error message
Definition debugger.cpp:38
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
request for attaching user-mode process
Definition RequestStructures.h:631
BOOLEAN CheckCallbackAtFirstInstruction
Definition RequestStructures.h:635
DEBUGGER_ATTACH_DETACH_USER_MODE_PROCESS_ACTION_TYPE Action
Definition RequestStructures.h:638
BOOLEAN IsStartingNewProcess
Definition RequestStructures.h:632
UINT32 ProcessId
Definition RequestStructures.h:633
UINT64 Result
Definition RequestStructures.h:641
UINT32 ThreadId
Definition RequestStructures.h:634
VOID UdInitializeUserDebugger()
Initialize the user debugger in user mode.
Definition ud.cpp:29
UINT32 g_ProcessIdOfLatestStartingProcess
The process id of the latest starting process.
Definition globals.h:368
BOOLEAN UdCreateSuspendedProcess(const WCHAR *FileName, const WCHAR *CommandLine, PPROCESS_INFORMATION ProcessInformation)
Attach to a target process.
Definition ud.cpp:306