Skip to content

Commit 7ec0c66

Browse files
committed
Swap (Windows): detect detailed info
1 parent 9d2df58 commit 7ec0c66

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/detection/swap/swap.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
typedef struct FFSwapResult
66
{
7+
FFstrbuf name;
78
uint64_t bytesUsed;
89
uint64_t bytesTotal;
910
} FFSwapResult;
1011

11-
const char* ffDetectSwap(FFSwapResult* swap);
12+
const char* ffDetectSwap(FFlist* result /* List of FFSwapResult */);

src/detection/swap/swap_windows.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,31 @@
11
#include "swap.h"
22
#include "util/mallocHelper.h"
3+
#include "util/windows/unicode.h"
34

45
#include <winternl.h>
56
#include <ntstatus.h>
67
#include <windows.h>
78

8-
const char* ffDetectSwap(FFSwapResult* swap)
9+
const char* ffDetectSwap(FFlist* result)
910
{
1011
uint8_t buffer[4096];
1112
ULONG size = sizeof(buffer);
1213
SYSTEM_PAGEFILE_INFORMATION* pstart = (SYSTEM_PAGEFILE_INFORMATION*) buffer;
1314
if(!NT_SUCCESS(NtQuerySystemInformation(SystemPagefileInformation, pstart, size, &size)))
1415
return "NtQuerySystemInformation(SystemPagefileInformation, size) failed";
1516

17+
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
1618
for (SYSTEM_PAGEFILE_INFORMATION* current = pstart; ; current = (SYSTEM_PAGEFILE_INFORMATION*)((uint8_t*) current + current->NextEntryOffset))
1719
{
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;
2026
if (current->NextEntryOffset == 0)
2127
break;
2228
}
23-
uint32_t pageSize = instance.state.platform.sysinfo.pageSize;
24-
swap->bytesUsed *= pageSize;
25-
swap->bytesTotal *= pageSize;
2629

2730
return NULL;
2831
}

0 commit comments

Comments
 (0)