Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Kill Process using DebugActiveProcess.

Kill Process using DebugActiveProcess.

Scheduled Pinned Locked Moved C / C++ / MFC
questiondebugging
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    gothic_coder
    wrote on last edited by
    #1

    Hello all. I want to kill the process using DebugActiveProcess.. I read somewhere that to kill the debugee process or target process i need to terminate the Debug object.. Can anyone clarify that? How do i do that? Thanks.

    G 1 Reply Last reply
    0
    • G gothic_coder

      Hello all. I want to kill the process using DebugActiveProcess.. I read somewhere that to kill the debugee process or target process i need to terminate the Debug object.. Can anyone clarify that? How do i do that? Thanks.

      G Offline
      G Offline
      gothic_coder
      wrote on last edited by
      #2

      I'm doing something like this.

      #define DEBUG_KILL_PROCESS_ON_EXIT 0x1
      #define OBJ_KERNEL_HANDLE 0x00000200L
      #define OBJ_CASE_INSENSITIVE 0x00000040L
      #define OBJECT_ALL_ACCESS (STANDARD_RIGHTS_REQUIRED | 0x1)

      if(strcmp(Proc_Argument, "-debug") == 0)
      {
      OBJECT_ATTRIBUTES objAttr;

      objAttr.Length = sizeof(OBJECT\_ATTRIBUTES);
      objAttr.RootDirectory = NULL;
      objAttr.Attributes = OBJ\_CASE\_INSENSITIVE | OBJ\_KERNEL\_HANDLE;
      objAttr.ObjectName = NULL;
      objAttr.SecurityDescriptor = NULL;
      objAttr.SecurityQualityOfService = NULL;
      
      HMODULE hDebugObject = NULL;
      HANDLE MyDebugHandle = NULL;
      		
      HANDLE hProc = MyOpenProcess(PROCESS\_SUSPEND\_RESUME,FALSE, dwID);
      		
      typedef NTSTATUS (WINAPI \*\_NtCreateDebugObject)(OUT PHANDLE DebugHandle,
                   				IN ACCESS\_MASK DesiredAccess,
      					IN POBJECT\_ATTRIBUTES ObjectAttributes,
      					IN ULONG Flags);
      
      			 
      \_NtCreateDebugObject Debug\_Object;
      
      
      		
      typedef NTSTATUS (WINAPI \*\_NtDebugActiveProcess)(IN HANDLE ProcessHandle,
      					IN HANDLE DebugHandle);
      
      \_NtDebugActiveProcess Debug\_Process = NULL;
      
      
      hDebugObject = GetModuleHandle("ntdll.dll");
      
      if(hDebugObject == INVALID\_HANDLE\_VALUE || hDebugObject == NULL)
      {
      	hDebugObject = LoadLibrary("ntdll.dll");
      	if(hDebugObject == INVALID\_HANDLE\_VALUE || hDebugObject == NULL)
      	{
      		MessageBox(NULL, "Cannot Load NtDll.dll", "Error", MB\_OK);
      				
      	}
      }
      
      Debug\_Object = (\_NtCreateDebugObject)GetProcAddress(hDebugObject, "NtCreateDebugObject");
      Debug\_Process = (\_NtDebugActiveProcess)GetProcAddress(hDebugObject, "NtDebugActiveProcess");
      
      
      NTSTATUS nStatus = Debug\_Object(&MyDebugHandle,
      							OBJECT\_ALL\_ACCESS,
      							&objAttr,
      							DEBUG\_KILL\_PROCESS\_ON\_EXIT);
      
          DWORD err = GetLastError();
      
      if(nStatus != STATUS\_SUCCESS)
      {
      	MessageBox(NULL, "Fail to create object", "Error", MB\_OK)
      	return FALSE;
      }
      
      NTSTATUS nStatusProc = Debug\_Process(hWnd, MyDebugHandle);
      
          //This does not attch the process... Don't know what's the problem..
      	
      err = GetLastError();
      		
      if(nStatusProc != STATUS\_SUCCESS)
      {
                  
      	MessageBox(NULL, "Cannot Attach Processl", "Error", MB\_OK)
      	return FALSE;
      }
      		
      CloseHandle(MyDebugHandle);
      

      }

      Also the error after Debug_Process comes out to be 299 i.e "Only part of a ReadProcessMemory or WriteProcessMemory request was completed."...

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups