title: C++ Hooking kernel32.dll OpenProcess with detours
body: <p>I am trying to hook <strong>OpenProcess</strong> from <strong>Kernel32.dll</strong> in order to prevent so called "<strong>injector</strong>" programs from injecting other dll`s into my process:</p>
  
  <pre><code>// -------------------------------------------------------------------
  HANDLE WINAPI myOpenProcess(DWORD dwDesiredAccess, BOOL  bInheritHandle, DWORD dwProcessId)
  {
      //
  
      if (dwDesiredAccess == PROCESS_ALL_ACCESS || dwDesiredAccess == PROCESS_VM_OPERATION ||
          dwDesiredAccess == PROCESS_VM_READ || dwDesiredAccess == PROCESS_VM_WRITE)
      {
          printf("Blcoked Process ID : %d , DesiredAccess : %d ", dwProcessId, dwDesiredAccess);
  
          return false;
      }
  
      //
  
      return dOpenProcess(dwDesiredAccess, bInheritHandle, dwProcessId);
  }
  </code></pre>
  
  <p>What do I need to add, in order to "<em>detect</em>" if anybody opens the process for "<strong>injecting</strong>" ?
  I do not want to "prevent", I wish to "detect" injection and decide what to do.</p>