annotate dep/animia/src/platform/win32/fd.cc @ 137:69db40272acd

dep/animia: [WIP] huge refactor this WILL NOT compile, because lots of code has been changed and every API in the original codebase has been removed. note that this api setup is not exactly permanent...
author Paper <mrpapersonic@gmail.com>
date Fri, 10 Nov 2023 13:52:47 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
137
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 /**
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 * win32.cpp
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3 * - provides support for Windows clients
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 *
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 **/
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include "win32.h"
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7 #include <fileapi.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 #include <handleapi.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9 #include <iostream>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 #include <libloaderapi.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11 #include <ntdef.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 #include <psapi.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 #include <shlobj.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14 #include <stdexcept>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 #include <string>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 #include <stringapiset.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17 #include <tlhelp32.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 #include <unordered_map>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 #include <vector>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 #include <windows.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 #include <winternl.h>
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23 /* This file is noticably more complex than Unix and Linux, and that's because
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 there is no "simple" way to get the paths of a file. In fact, this thing requires
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 you to use *internal functions* that can't even be linked to, hence why we have to
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 use GetProcAddress and such. What a mess. */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 #define SystemExtendedHandleInformation ((SYSTEM_INFORMATION_CLASS)0x40)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 constexpr NTSTATUS STATUS_INFO_LENGTH_MISMATCH = 0xC0000004UL;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30 constexpr NTSTATUS STATUS_SUCCESS = 0x00000000UL;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32 static unsigned short file_type_index = 0;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
34 struct SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
35 PVOID Object;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
36 ULONG_PTR UniqueProcessId;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
37 HANDLE HandleValue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
38 ACCESS_MASK GrantedAccess;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
39 USHORT CreatorBackTraceIndex;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
40 USHORT ObjectTypeIndex;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
41 ULONG HandleAttributes;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
42 ULONG Reserved;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
43 };
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
44
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
45 struct SYSTEM_HANDLE_INFORMATION_EX {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
46 ULONG_PTR NumberOfHandles;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
47 ULONG_PTR Reserved;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
48 SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX Handles[1];
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
49 };
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
50
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
51 namespace Animia { namespace Windows {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
52
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
53 /* All of this BS is required on Windows. Why? */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
54
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
55 HANDLE DuplicateHandle(HANDLE process_handle, HANDLE handle) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
56 HANDLE dup_handle = nullptr;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
57 const bool result =
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
58 ::DuplicateHandle(process_handle, handle, ::GetCurrentProcess(), &dup_handle, 0, false, DUPLICATE_SAME_ACCESS);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
59 return result ? dup_handle : nullptr;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
60 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
61
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
62 PVOID GetNTDLLAddress(LPCSTR proc_name) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
63 return reinterpret_cast<PVOID>(::GetProcAddress(::GetModuleHandleA("ntdll.dll"), proc_name));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
64 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
65
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
66 NTSTATUS QuerySystemInformation(SYSTEM_INFORMATION_CLASS cls, PVOID sysinfo, ULONG len, PULONG retlen) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
67 static const auto func =
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
68 reinterpret_cast<decltype(::NtQuerySystemInformation)*>(GetNTDLLAddress("NtQuerySystemInformation"));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
69 return func(cls, sysinfo, len, retlen);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
70 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
71
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
72 NTSTATUS QueryObject(HANDLE handle, OBJECT_INFORMATION_CLASS cls, PVOID objinf, ULONG objinflen, PULONG retlen) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
73 static const auto func = reinterpret_cast<decltype(::NtQueryObject)*>(GetNTDLLAddress("NtQueryObject"));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
74 return func(handle, cls, objinf, objinflen, retlen);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
75 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
76
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
77 std::vector<SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX> GetSystemHandleInformation() {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
78 std::vector<SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX> res;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
79 ULONG cb = 1 << 19;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
80 NTSTATUS status = STATUS_SUCCESS;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
81 SYSTEM_HANDLE_INFORMATION_EX* info;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
82
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
83 do {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
84 status = STATUS_NO_MEMORY;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
85
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
86 if (!(info = (SYSTEM_HANDLE_INFORMATION_EX*)malloc(cb *= 2)))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
87 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
88
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
89 res.reserve(cb);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
90
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
91 if (0 <= (status = QuerySystemInformation(SystemExtendedHandleInformation, info, cb, &cb))) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
92 if (ULONG_PTR handles = info->NumberOfHandles) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
93 SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX* entry = info->Handles;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
94 do {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
95 if (entry)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
96 res.push_back(*entry);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
97 } while (entry++, --handles);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
98 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
99 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
100 free(info);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
101 } while (status == STATUS_INFO_LENGTH_MISMATCH);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
102
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
103 return res;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
104 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
105
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
106 OBJECT_TYPE_INFORMATION QueryObjectTypeInfo(HANDLE handle) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
107 OBJECT_TYPE_INFORMATION info;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
108 QueryObject(handle, ObjectTypeInformation, &info, sizeof(info), NULL);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
109 return info;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
110 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
111
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
112 /* we're using UTF-8. originally, I had used just the ANSI versions of functions, but that
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
113 sucks massive dick. this way we get unicode in the way every single other OS does it */
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
114 std::string UnicodeStringToUtf8(std::wstring string) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
115 unsigned long size = ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), NULL, 0, NULL, NULL);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
116 std::string ret = std::string(size, '\0');
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
117 ::WideCharToMultiByte(CP_UTF8, 0, string.c_str(), string.length(), &ret.front(), ret.length(), NULL, NULL);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
118 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
119 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
120
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
121 std::string UnicodeStringToUtf8(UNICODE_STRING string) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
122 unsigned long size = ::WideCharToMultiByte(CP_UTF8, 0, string.Buffer, string.Length, NULL, 0, NULL, NULL);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
123 std::string ret = std::string(size, '\0');
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
124 ::WideCharToMultiByte(CP_UTF8, 0, string.Buffer, string.Length, &ret.front(), ret.length(), NULL, NULL);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
125 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
126 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
127
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
128 std::wstring Utf8StringToUnicode(std::string string) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
129 unsigned long size = ::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), string.length(), NULL, 0);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
130 std::wstring ret = std::wstring(size, L'\0');
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
131 ::MultiByteToWideChar(CP_UTF8, 0, string.c_str(), string.length(), &ret.front(), ret.length());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
132 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
133 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
134
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
135 std::string GetHandleType(HANDLE handle) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
136 OBJECT_TYPE_INFORMATION info = QueryObjectTypeInfo(handle);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
137 return UnicodeStringToUtf8(info.TypeName);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
138 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
139
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
140 std::string GetFinalPathNameByHandle(HANDLE handle) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
141 std::wstring buffer;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
142
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
143 int result = ::GetFinalPathNameByHandleW(handle, NULL, 0, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
144 buffer.resize(result);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
145 ::GetFinalPathNameByHandleW(handle, &buffer.front(), buffer.size(), FILE_NAME_NORMALIZED | VOLUME_NAME_DOS);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
146 buffer.resize(buffer.find('\0'));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
147
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
148 return UnicodeStringToUtf8(buffer);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
149 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
150
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
151 bool IsFileHandle(HANDLE handle, unsigned short object_type_index) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
152 if (file_type_index)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
153 return object_type_index == file_type_index;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
154 else if (!handle)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
155 return true;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
156 else if (GetHandleType(handle) == "File") {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
157 file_type_index = object_type_index;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
158 return true;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
159 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
160 return false;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
161 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
162
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
163 bool IsFileMaskOk(ACCESS_MASK access_mask) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
164 if (!(access_mask & FILE_READ_DATA))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
165 return false;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
166
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
167 if ((access_mask & FILE_APPEND_DATA) || (access_mask & FILE_WRITE_EA) || (access_mask & FILE_WRITE_ATTRIBUTES))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
168 return false;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
169
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
170 return true;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
171 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
172
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
173 bool IsFilePathOk(const std::string& path) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
174 if (path.empty())
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
175 return false;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
176
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
177 const auto file_attributes = GetFileAttributesA(path.c_str());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
178 if ((file_attributes == INVALID_FILE_ATTRIBUTES) || (file_attributes & FILE_ATTRIBUTE_DIRECTORY))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
179 return false;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
180
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
181 return true;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
182 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
183
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
184 std::string GetSystemDirectory() {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
185 PWSTR path_wch;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
186 SHGetKnownFolderPath(FOLDERID_Windows, 0, NULL, &path_wch);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
187 std::wstring path_wstr(path_wch);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
188 CoTaskMemFree(path_wch);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
189 return UnicodeStringToUtf8(path_wstr);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
190 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
191
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
192 bool IsSystemFile(const std::string& path) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
193 std::wstring path_w = Utf8StringToUnicode(path);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
194 CharUpperBuffW(&path_w.front(), path_w.length());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
195 std::wstring windir_w = Utf8StringToUnicode(GetSystemDirectory());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
196 CharUpperBuffW(&windir_w.front(), windir_w.length());
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
197 return path_w.find(windir_w) == 4;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
198 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
199
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
200 std::vector<int> get_all_pids() {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
201 std::vector<int> ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
202 HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
203 PROCESSENTRY32 pe32;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
204 pe32.dwSize = sizeof(PROCESSENTRY32);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
205
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
206 if (hProcessSnap == INVALID_HANDLE_VALUE)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
207 return std::vector<int>();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
208
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
209 if (!Process32First(hProcessSnap, &pe32))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
210 return std::vector<int>();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
211
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
212 ret.push_back(pe32.th32ProcessID);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
213 while (Process32Next(hProcessSnap, &pe32)) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
214 ret.push_back(pe32.th32ProcessID);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
215 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
216 // clean the snapshot object
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
217 CloseHandle(hProcessSnap);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
218
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
219 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
220 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
221
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
222 std::string get_process_name(int pid) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
223 unsigned long size = 256, ret_size = 0;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
224 HANDLE handle = ::OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
225 if (!handle)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
226 return "";
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
227
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
228 std::wstring ret(size, L'\0');
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
229 while (size < 32768) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
230 ret.resize(size, L'\0');
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
231
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
232 if (!(ret_size = ::GetModuleBaseNameW(handle, 0, &ret.front(), ret.length())))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
233 ret = L"";
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
234 else if (size > ret_size)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
235 ret.resize(ret.find('\0'));
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
236
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
237 size *= 2;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
238 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
239
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
240 CloseHandle(handle);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
241
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
242 return UnicodeStringToUtf8(ret);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
243 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
244
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
245 std::vector<std::string> get_open_files(int pid) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
246 std::vector<std::string> ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
247 std::vector<SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX> info = GetSystemHandleInformation();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
248 for (auto& h : info) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
249 if (h.UniqueProcessId != pid)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
250 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
251
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
252 if (!IsFileHandle(nullptr, h.ObjectTypeIndex))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
253 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
254 if (!IsFileMaskOk(h.GrantedAccess))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
255 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
256
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
257 const HANDLE proc = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
258 HANDLE handle = DuplicateHandle(proc, h.HandleValue);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
259 if (!handle)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
260 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
261
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
262 if (GetFileType(handle) != FILE_TYPE_DISK)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
263 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
264
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
265 std::string path = GetFinalPathNameByHandle(handle);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
266 if (!IsFilePathOk(path))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
267 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
268
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
269 ret.push_back(path);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
270 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
271 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
272 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
273
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
274 std::vector<std::string> filter_system_files(const std::vector<std::string>& source) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
275 std::vector<std::string> ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
276 for (const std::string& s : source) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
277 if (!IsSystemFile(s))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
278 ret.push_back(s);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
279 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
280 return ret;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
281 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
282
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
283 std::unordered_map<int, std::vector<std::string>> get_all_open_files() {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
284 std::unordered_map<int, std::vector<std::string>> map;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
285 std::vector<SYSTEM_HANDLE_TABLE_ENTRY_INFO_EX> info = GetSystemHandleInformation();
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
286 for (auto& h : info) {
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
287 int pid = h.UniqueProcessId;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
288
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
289 if (!IsFileHandle(nullptr, h.ObjectTypeIndex))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
290 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
291 if (!IsFileMaskOk(h.GrantedAccess))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
292 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
293
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
294 const HANDLE proc = ::OpenProcess(PROCESS_DUP_HANDLE, false, pid);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
295 HANDLE handle = DuplicateHandle(proc, h.HandleValue);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
296 if (!handle)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
297 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
298
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
299 if (GetFileType(handle) != FILE_TYPE_DISK)
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
300 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
301
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
302 std::string path = GetFinalPathNameByHandle(handle);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
303 if (!IsFilePathOk(path))
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
304 continue;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
305
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
306 if (map.find(pid) == map.end())
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
307 map[pid] = {};
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
308 map[pid].push_back(path);
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
309 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
310 return map;
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
311 }
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
312
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
313 } // namespace Windows
69db40272acd dep/animia: [WIP] huge refactor
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
314 } // namespace Animia