|
1 | 1 | #include "swap.h" |
2 | 2 | #include "util/mallocHelper.h" |
| 3 | +#include "util/windows/unicode.h" |
3 | 4 |
|
4 | 5 | #include <winternl.h> |
5 | 6 | #include <ntstatus.h> |
6 | 7 | #include <windows.h> |
7 | 8 |
|
8 | | -const char* ffDetectSwap(FFSwapResult* swap) |
| 9 | +const char* ffDetectSwap(FFlist* result) |
9 | 10 | { |
10 | 11 | uint8_t buffer[4096]; |
11 | 12 | ULONG size = sizeof(buffer); |
12 | 13 | SYSTEM_PAGEFILE_INFORMATION* pstart = (SYSTEM_PAGEFILE_INFORMATION*) buffer; |
13 | 14 | if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size))) |
14 | 15 | return "NtQuerySystemInformation(SystemPagefileInformation, size) failed"; |
15 | 16 |
|
| 17 | + uint32_t pageSize = instance.state.platform.sysinfo.pageSize; |
16 | 18 | for (SYSTEM_PAGEFILE_INFORMATION* current = pstart; ; current = (SYSTEM_PAGEFILE_INFORMATION*)((uint8_t*) current + current->NextEntryOffset)) |
17 | 19 | { |
18 | | - swap->bytesUsed += current->TotalUsed; |
19 | | - swap->bytesTotal += current->CurrentSize; |
| 20 | + FFSwapResult* swap = ffListAdd(result); |
| 21 | + ffStrbufInitNWS(&swap->name, current->FileName.Length / sizeof(wchar_t), current->FileName.Buffer); |
| 22 | + if (ffStrbufStartsWithS(&swap->name, "\\??\\")) |
| 23 | + ffStrbufSubstrAfter(&swap->name, strlen("\\??\\") - 1); |
| 24 | + swap->bytesUsed = current->TotalUsed * pageSize; |
| 25 | + swap->bytesTotal = current->CurrentSize * pageSize; |
20 | 26 | if (current->NextEntryOffset == 0) |
21 | 27 | break; |
22 | 28 | } |
23 | | - uint32_t pageSize = instance.state.platform.sysinfo.pageSize; |
24 | | - swap->bytesUsed *= pageSize; |
25 | | - swap->bytesTotal *= pageSize; |
26 | 29 |
|
27 | 30 | return NULL; |
28 | 31 | } |
0 commit comments