-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathprocess_helpers.cpp
More file actions
44 lines (39 loc) · 1.12 KB
/
process_helpers.cpp
File metadata and controls
44 lines (39 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//////////////////////////////////////////////////////////////////////////////
//
// Process Test Helpers (process_helpers.cpp of unittests.exe)
//
// Microsoft Research Detours Package
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
#include "windows.h"
#include "process_helpers.h"
HRESULT GetProcessFileName(HANDLE process, std::wstring& filename)
{
filename.resize(MAX_PATH);
DWORD size = static_cast<DWORD>(filename.size()) + 1;
if (QueryFullProcessImageNameW(process, 0, &filename[0], &size))
{
filename.resize(size);
return S_OK;
}
else
{
return HRESULT_FROM_WIN32(GetLastError());
}
}
HRESULT CreateSuspendedCopy(TerminateOnScopeExit& wrapper)
{
std::wstring location;
const auto hr = GetProcessFileName(GetCurrentProcess(), location);
if (FAILED(hr))
{
return hr;
}
STARTUPINFOW si = { sizeof(si) };
if (!CreateProcessW(location.c_str(), nullptr, nullptr, nullptr, false, CREATE_SUSPENDED, nullptr, nullptr, &si, &wrapper.information))
{
return HRESULT_FROM_WIN32(GetLastError());
}
return S_OK;
}