MCPcopy Create free account
hub / github.com/OpenSteam001/OpenSteamTool / GetImagePath

Function GetImagePath

src/OSTPlatform/Windows/Process.cpp:283–301  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

281}
282
283std::optional<std::string> GetImagePath(uint32_t pid) {
284 Windows::UniqueHandle process = OpenProcessHandle(pid, PROCESS_QUERY_LIMITED_INFORMATION);
285 if (!process) return std::nullopt;
286
287 for (DWORD capacity : {static_cast<DWORD>(MAX_PATH), DWORD{32768}}) {
288 std::wstring path(capacity, L'\0');
289 DWORD size = capacity;
290 if (QueryFullProcessImageNameW(process.get(), 0, path.data(), &size)) {
291 path.resize(size);
292 return Encoding::WideToUtf8(path);
293 }
294 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
295 OSTP_LOG_DEBUG("QueryFullProcessImageNameW(pid={}) failed (error={})", pid, GetLastError());
296 return std::nullopt;
297 }
298 }
299 OSTP_LOG_DEBUG("QueryFullProcessImageNameW(pid={}) failed: path exceeds 32768 wchars", pid);
300 return std::nullopt;
301}
302
303std::optional<std::string> GetEnvironmentVariableValue(uint32_t pid, std::wstring_view name) {
304 Windows::UniqueHandle process =

Callers 1

QueryProcessImagePathFunction · 0.85

Calls 4

OpenProcessHandleFunction · 0.85
WideToUtf8Function · 0.85
dataMethod · 0.80
getMethod · 0.45

Tested by 1

QueryProcessImagePathFunction · 0.68