static int WSAAPI WSAStartup_hook(WORD wVersionRequested, LPWSADATA lpWSAData) { int ret = syshooks.WSAStartup()(wVersionRequested, lpWSAData); // only increment the refcount if the function succeeded if(ret == 0) syshooks.m_WSARefCount++; return ret; }
static BOOL WINAPI API112CreateProcessW_hook( __in_opt LPCWSTR lpApplicationName, __inout_opt LPWSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCWSTR lpCurrentDirectory, __in LPSTARTUPINFOW lpStartupInfo, __out LPPROCESS_INFORMATION lpProcessInformation) { return Hook_CreateProcessW(syshooks.API112CreateProcessW(), lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); }
static int WSAAPI WSACleanup_hook() { // don't let the application murder our sockets with a mismatched WSACleanup() call if(syshooks.m_WSARefCount == 1) { RDCLOG("WSACleanup called with (to the application) no WSAStartup! Ignoring."); SetLastError(WSANOTINITIALISED); return SOCKET_ERROR; } // decrement refcount and call the real thing syshooks.m_WSARefCount--; return syshooks.WSACleanup()(); }
static BOOL WINAPI CreateProcessW_hook(__in_opt LPCWSTR lpApplicationName, __inout_opt LPWSTR lpCommandLine, __in_opt LPSECURITY_ATTRIBUTES lpProcessAttributes, __in_opt LPSECURITY_ATTRIBUTES lpThreadAttributes, __in BOOL bInheritHandles, __in DWORD dwCreationFlags, __in_opt LPVOID lpEnvironment, __in_opt LPCWSTR lpCurrentDirectory, __in LPSTARTUPINFOW 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.CreateProcessW()( lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation); if(ret && RenderDoc::Inst().GetCaptureOptions().HookIntoChildren) { RDCDEBUG("Intercepting CreateProcessW"); bool inject = true; // sanity check to make sure we're not going to go into an infinity loop injecting into // ourselves. if(lpApplicationName) { wstring app = lpApplicationName; app = strlower(app); if(app.find(L"renderdoccmd.exe") != wstring::npos || app.find(L"renderdocui.vshost.exe") != wstring::npos || app.find(L"qrenderdoc.exe") != string::npos || app.find(L"renderdocui.exe") != wstring::npos) { inject = false; } } if(lpCommandLine) { wstring cmd = lpCommandLine; cmd = strlower(cmd); if(cmd.find(L"renderdoccmd.exe") != wstring::npos || cmd.find(L"renderdocui.vshost.exe") != wstring::npos || cmd.find(L"qrenderdoc.exe") != wstring::npos || cmd.find(L"renderdocui.exe") != wstring::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; }