Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/MaaUtils/Runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
MAA_NS_BEGIN

MAA_UTILS_API const std::filesystem::path& library_dir();
MAA_UTILS_API std::filesystem::path get_library_path(void* addr);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

该想想名字了,这俩函数光看名字不知道有啥区别


MAA_NS_END
1 change: 1 addition & 0 deletions include/MaaUtils/SafeWindows.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@

#include <windows.h>

#include <psapi.h>
#include <shellapi.h>
10 changes: 10 additions & 0 deletions source/Runtime/Runtime_Posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ const std::filesystem::path& library_dir()
return s_library_dir_cache;
}

std::filesystem::path get_library_path(void* addr)
{
Dl_info dl_info {};
if (dladdr(addr, &dl_info) == 0) {
return {};
}

return { dl_info.dli_fname };
}

void init_library_dir()
{
Dl_info dl_info {};
Expand Down
12 changes: 12 additions & 0 deletions source/Runtime/Runtime_Win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ const std::filesystem::path& library_dir()
return s_library_dir_cache;
}

std::filesystem::path get_library_path(void* addr)
{
WCHAR path_buf[MAX_PATH + 5];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为啥是 + 5

另外要初始化一下

DWORD path_len = GetMappedFileNameW(GetCurrentProcess(), addr, path_buf, MAX_PATH);

if (path_len == 0) {
return {};
}

return { path_buf };

This comment was marked as outdated.

This comment was marked as outdated.

}

void init_library_dir(HINSTANCE hinstDLL)
{
WCHAR buffer[MAX_PATH] = { 0 };
Expand Down