Exemplo n.º 1
0
 static BOOL WINAPI CreateProcessA_hook(
     __in_opt LPCSTR lpApplicationName, __inout_opt LPSTR lpCommandLine,
     __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
     __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles,
     __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCSTR lpCurrentDirectory,
     __in LPSTARTUPINFOA lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation)
 {
     return Hook_CreateProcessA(syshooks.CreateProcessA(), lpApplicationName, lpCommandLine,
                                lpProcessAttributes, lpThreadAttributes, bInheritHandles,
                                dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo,
                                lpProcessInformation);
 }
Exemplo n.º 2
0
  static BOOL WINAPI CreateProcessA_hook(
      __in_opt LPCSTR lpApplicationName, __inout_opt LPSTR lpCommandLine,
      __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes,
      __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles,
      __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCSTR lpCurrentDirectory,
      __in LPSTARTUPINFOA lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation)
  {
    PROCESS_INFORMATION dummy;
    RDCEraseEl(dummy);

    // not sure if this is valid, but I need the PID so I'll fill in my own struct to ensure that.
    if(lpProcessInformation == NULL)
    {
      lpProcessInformation = &dummy;
    }
    else
    {
      *lpProcessInformation = dummy;
    }

    dwCreationFlags |= CREATE_SUSPENDED;

    BOOL ret = syshooks.CreateProcessA()(
        lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles,
        dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation);

    if(ret && RenderDoc::Inst().GetCaptureOptions().HookIntoChildren)
    {
      RDCDEBUG("Intercepting CreateProcessA");

      bool inject = true;

      // sanity check to make sure we're not going to go into an infinity loop injecting into
      // ourselves.
      if(lpApplicationName)
      {
        string app = lpApplicationName;
        app = strlower(app);

        if(app.find("renderdoccmd.exe") != string::npos ||
           app.find("renderdocui.vshost.exe") != string::npos ||
           app.find("qrenderdoc.exe") != string::npos || app.find("renderdocui.exe") != string::npos)
        {
          inject = false;
        }
      }
      if(lpCommandLine)
      {
        string cmd = lpCommandLine;
        cmd = strlower(cmd);

        if(cmd.find("renderdoccmd.exe") != string::npos ||
           cmd.find("renderdocui.vshost.exe") != string::npos ||
           cmd.find("qrenderdoc.exe") != string::npos || cmd.find("renderdocui.exe") != string::npos)
        {
          inject = false;
        }
      }

      if(inject)
      {
        // inherit logfile and capture options
        uint32_t ident = RENDERDOC_InjectIntoProcess(lpProcessInformation->dwProcessId, NULL,
                                                     RenderDoc::Inst().GetLogFile(),
                                                     &RenderDoc::Inst().GetCaptureOptions(), false);

        RenderDoc::Inst().AddChildProcess((uint32_t)lpProcessInformation->dwProcessId, ident);
      }
    }

    ResumeThread(lpProcessInformation->hThread);

    // ensure we clean up after ourselves
    if(dummy.dwProcessId != 0)
    {
      CloseHandle(dummy.hProcess);
      CloseHandle(dummy.hThread);
    }

    return ret;
  }