mirror of
https://github.com/WinDurango/Detours.git
synced 2026-01-31 00:55:20 +01:00
Other improvements: - Makes the pcbData parameter in DetourFindPayload and DetourFindPayloadEx optional, so that if an application only needs to search for the presence of a payload, they can ignore the size by passing nullptr. - Makes the pvData parameter in DetourCopyPayloadToProcess const, so that a pointer to a const C++ object can be passed instead of the object needing to be const_casted or being non-const. - Adds DetourCopyPayloadToProcessEx, which has the same interface than DetourCopyPayloadToProcess, but it returns the address of the payload in the remote module, if the program later wants to write to it. - Add payload example and extra unit tests covering new APIs. Fixes #79 Co-authored-by: Charles Milette <me@charlesmilette.net>
44 lines
1.1 KiB
C++
44 lines
1.1 KiB
C++
//////////////////////////////////////////////////////////////////////////////
|
|
//
|
|
// 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;
|
|
} |