| 311 | } |
| 312 | |
| 313 | std::vector<ModuleInfo> EnumerateModules(uint32_t pid) { |
| 314 | std::vector<ModuleInfo> modules; |
| 315 | Windows::UniqueFileHandle snapshot( |
| 316 | CreateToolhelp32Snapshot(TH32CS_SNAPMODULE | TH32CS_SNAPMODULE32, pid)); |
| 317 | if (!snapshot) { |
| 318 | OSTP_LOG_DEBUG("CreateToolhelp32Snapshot(pid={}) failed (error={})", pid, GetLastError()); |
| 319 | return modules; |
| 320 | } |
| 321 | |
| 322 | MODULEENTRY32W entry{}; |
| 323 | entry.dwSize = sizeof(entry); |
| 324 | if (Module32FirstW(snapshot.get(), &entry)) { |
| 325 | do { |
| 326 | std::filesystem::path nativePath(entry.szExePath); |
| 327 | std::string path = Encoding::WideToUtf8(entry.szExePath); |
| 328 | if (path.empty()) continue; |
| 329 | |
| 330 | modules.push_back(ModuleInfo{ |
| 331 | std::move(path), |
| 332 | std::move(nativePath), |
| 333 | entry.modBaseSize, |
| 334 | false, |
| 335 | }); |
| 336 | } while (Module32NextW(snapshot.get(), &entry)); |
| 337 | } |
| 338 | return modules; |
| 339 | } |
| 340 | |
| 341 | bool IsSystemModulePath(const std::string& path) { |
| 342 | static const std::string systemDir = [] { |
nothing calls this directly
no test coverage detected