| 281 | } |
| 282 | |
| 283 | std::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 | |
| 303 | std::optional<std::string> GetEnvironmentVariableValue(uint32_t pid, std::wstring_view name) { |
| 304 | Windows::UniqueHandle process = |