AuroraRuntime/Source/Process/ProcessMap.Win32.cpp

53 lines
1.1 KiB
C++
Raw Normal View History

2021-06-27 21:25:29 +00:00
/***
Copyright (C) 2021 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: ProcessMap.Win32.cpp
Date: 2021-6-12
Author: Reece
***/
#include <RuntimeInternal.hpp>
#include "ProcessMap.Win32.hpp"
namespace Aurora::Process
{
static AuString ModuleToSomething(HMODULE handle, bool path)
{
std::wstring file;
file.resize(16 * 1024);
// HMODULE arent handles, they're COFF pointers
if (!handle)
{
return {};
}
auto length = GetModuleFileNameW(handle, &file[0], file.size());
if (!length)
{
return {};
}
file.resize(length);
if (!path)
{
auto idx = file.find_last_of('\\');
if (idx != std::wstring::npos)
{
file = file.substr(idx + 1);
}
}
return Locale::ConvertFromWChar(file.c_str(), file.length());
}
AuString ModuleToName(HMODULE handle)
{
return ModuleToSomething(handle, false);
}
AuString ModuleToPath(HMODULE handle)
{
return ModuleToSomething(handle, true);
}
}