Skip to content

Commit

Permalink
fix: make GetProcPath throw if result is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
qudix committed Sep 21, 2024
1 parent 55214e3 commit 0895432
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/REX/W32/KERNEL32.h
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ namespace REX::W32
std::uint32_t GetPrivateProfileStringA(const char* a_app, const char* a_key, const char* a_default, char* a_buf, std::uint32_t a_bufLen, const char* a_name) noexcept;
std::uint32_t GetPrivateProfileStringW(const wchar_t* a_app, const wchar_t* a_key, const wchar_t* a_default, wchar_t* a_buf, std::uint32_t a_bufLen, const wchar_t* a_name) noexcept;
void* GetProcAddress(HMODULE a_module, const char* a_name) noexcept;
std::string_view GetProcPath(HMODULE a_handle) noexcept;
std::string_view GetProcPath(HMODULE a_handle);
void GetSystemInfo(SYSTEM_INFO* a_info) noexcept;
bool IMAGE_SNAP_BY_ORDINAL64(std::uint64_t a_ordinal) noexcept;
IMAGE_SECTION_HEADER* IMAGE_FIRST_SECTION(const IMAGE_NT_HEADERS64* a_header) noexcept;
Expand Down
8 changes: 3 additions & 5 deletions src/REX/W32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,14 @@ namespace REX::W32
return ::W32_IMPL_GetProcAddress(a_module, a_name);
}

std::string_view GetProcPath(HMODULE a_handle) noexcept
std::string_view GetProcPath(HMODULE a_handle)
{
// I don't like this function...
static std::string fileName(MAX_PATH + 1, ' ');
auto res = GetModuleFileNameA(a_handle, fileName.data(), MAX_PATH + 1);

if (res == 0) {
fileName = "[ProcessHost]";
res = 13;
}
if (res == 0)
throw std::system_error(static_cast<int>(GetLastError()), std::system_category());

return { fileName.c_str(), res };
}
Expand Down

0 comments on commit 0895432

Please sign in to comment.