GetProcessName - Returns the string name of a process with id `pid` */
| 684 | GetProcessName - Returns the string name of a process with id `pid` |
| 685 | */ |
| 686 | wstring Process::GetProcessName(__in const DWORD pid) |
| 687 | { |
| 688 | if (pid <= 4) |
| 689 | { |
| 690 | Logger::logf(Err, "pid was either system process or null @ Process::GetProcessName"); |
| 691 | return {}; |
| 692 | } |
| 693 | |
| 694 | std::wstring processName; |
| 695 | |
| 696 | HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid); |
| 697 | |
| 698 | if (hProcess) |
| 699 | { |
| 700 | Logger::logf(Err, "OpenProcess failed with error %d @ Process::GetProcessName", GetLastError()); |
| 701 | return {}; |
| 702 | } |
| 703 | |
| 704 | HMODULE hMod = 0; |
| 705 | DWORD cbNeeded; |
| 706 | |
| 707 | if (EnumProcessModules(hProcess, &hMod, sizeof(hMod), &cbNeeded)) |
| 708 | { |
| 709 | WCHAR processNameBuffer[MAX_PATH]; |
| 710 | |
| 711 | if (GetModuleBaseName(hProcess, hMod, processNameBuffer, sizeof(processNameBuffer) / sizeof(WCHAR))) |
| 712 | { |
| 713 | processName = processNameBuffer; |
| 714 | } |
| 715 | else |
| 716 | { |
| 717 | Logger::logf(Err, "GetModuleBaseName failed with error %d @ Process::GetProcessName", GetLastError()); |
| 718 | } |
| 719 | } |
| 720 | else |
| 721 | { |
| 722 | Logger::logf(Err, "EnumProcessModules failed with error %d @ Process::GetProcessName", GetLastError()); |
| 723 | } |
| 724 | |
| 725 | CloseHandle(hProcess); |
| 726 | return processName; |
| 727 | } |
| 728 | |
| 729 | /* |
| 730 | GetLoadedModules - returns a vector<MODULE_DATA>* representing a set of loaded modules in the current process |
nothing calls this directly
no outgoing calls
no test coverage detected