Mercurial > libanimone
changeset 5:6d6d2b51517b
chore: merge
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Fri, 12 Apr 2024 05:23:45 -0400 |
parents | cce3a81b03bf (current diff) aa55bcfb5b79 (diff) |
children | f26b08274dcf |
files | |
diffstat | 4 files changed, 16 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/include/animone/fd/win32.h Fri Apr 12 05:21:45 2024 -0400 +++ b/include/animone/fd/win32.h Fri Apr 12 05:23:45 2024 -0400 @@ -4,13 +4,12 @@ #include <set> #include <string> -#include <windows.h> - #include "animone/fd.h" #include "animone/types.h" namespace animone::internal::win32 { +bool GetProcessName(pid_t pid, std::string& name); bool EnumerateOpenProcesses(process_proc_t process_proc); bool EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc);
--- a/include/animone/util/win32.h Fri Apr 12 05:21:45 2024 -0400 +++ b/include/animone/util/win32.h Fri Apr 12 05:23:45 2024 -0400 @@ -1,8 +1,9 @@ #ifndef ANIMONE_ANIMONE_UTIL_WIN32_H_ #define ANIMONE_ANIMONE_UTIL_WIN32_H_ +#include <windef.h> #include <subauth.h> -#include <windows.h> +#include <handleapi.h> #include <memory> #include <string> @@ -22,6 +23,7 @@ std::string ToUtf8String(const UNICODE_STRING& string); std::wstring ToWstring(const std::string& string); +std::wstring GetProcessPath(DWORD process_id); std::wstring GetFileNameFromPath(const std::wstring& path); std::wstring GetFileNameWithoutExtension(const std::wstring& filename);
--- a/src/fd/win32.cc Fri Apr 12 05:21:45 2024 -0400 +++ b/src/fd/win32.cc Fri Apr 12 05:23:45 2024 -0400 @@ -34,7 +34,6 @@ * TODO: implement SystemHandleInformation for systems older than XP */ static constexpr SYSTEM_INFORMATION_CLASS SystemExtendedHandleInformation = static_cast<SYSTEM_INFORMATION_CLASS>(0x40); -static constexpr SYSTEM_INFORMATION_CLASS SystemHandleInformation = static_cast<SYSTEM_INFORMATION_CLASS>(0x10); static constexpr NTSTATUS STATUS_INFO_LENGTH_MISMATCH = 0xC0000004UL; /* this is filled in at runtime because it's not guaranteed to be (and isn't) @@ -70,7 +69,9 @@ } NTSTATUS QuerySystemInformation(SYSTEM_INFORMATION_CLASS cls, PVOID sysinfo, ULONG len, - PULONG retlen){return nt_query_system_information(cls, sysinfo, len, retlen)} + PULONG retlen){ + return nt_query_system_information(cls, sysinfo, len, retlen); + } NTSTATUS QueryObject(HANDLE handle, OBJECT_INFORMATION_CLASS cls, PVOID objinf, ULONG objinflen, PULONG retlen) { return nt_query_object(handle, cls, objinf, objinflen, retlen); @@ -80,8 +81,7 @@ HMODULE ntdll; decltype(::NtQuerySystemInformation)* nt_query_system_information; decltype(::NtQueryObject)* nt_query_object; - -} +}; Ntdll ntdll; @@ -96,10 +96,10 @@ /* we should really put a cap on this */ ULONG cb = 1 << 19; NTSTATUS status = STATUS_NO_MEMORY; - std::unique_ptr<SYSTEM_HANDLE_INFORMATION_EX> info(malloc(cb)); + std::unique_ptr<SYSTEM_HANDLE_INFORMATION_EX> info; do { - info.reset(malloc(cb *= 2)); + info.reset(reinterpret_cast<SYSTEM_HANDLE_INFORMATION_EX*>(malloc(cb *= 2))); if (!info) continue; @@ -179,11 +179,12 @@ } bool GetProcessName(pid_t pid, std::string& name) { - std::wstring wname = GetProcessPath(); + std::wstring wname = GetProcessPath(pid); if (wname.empty()) return false; - return ToUtf8String(GetFileNameWithoutExtension(GetFileNameFromPath(wname))); + name = ToUtf8String(GetFileNameWithoutExtension(GetFileNameFromPath(wname))); + return true; } bool EnumerateOpenProcesses(process_proc_t process_proc) {
--- a/src/win/win32.cc Fri Apr 12 05:21:45 2024 -0400 +++ b/src/win/win32.cc Fri Apr 12 05:23:45 2024 -0400 @@ -9,6 +9,7 @@ #include "animone.h" #include "animone/util/win32.h" #include "animone/win.h" +#include "animone/fd.h" #include <set> #include <string> @@ -120,9 +121,9 @@ Process process; process.pid = GetWindowProcessId(hwnd); - process.name = fd::GetProcessName(process.pid) + GetProcessName(process.pid, process.name); - auto& window_proc = *reinterpret_cast<window_proc_t*>(param); + auto& window_proc = *reinterpret_cast<window_proc_t*>(param); if (!window_proc(process, window)) return FALSE;