Skip to content

Commit df87cdf

Browse files
committed
Windows: defines NtCurrentProcess and uses it
1 parent dee4b36 commit df87cdf

5 files changed

Lines changed: 11 additions & 4 deletions

File tree

src/common/impl/processing_windows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "common/processing.h"
33
#include "common/io.h"
44
#include "common/windows/unicode.h"
5+
#include "common/windows/nt.h"
56

67
#include <stdalign.h>
78
#include <windows.h>
@@ -213,7 +214,7 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer)
213214
bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui)
214215
{
215216
FF_AUTO_CLOSE_FD HANDLE hProcess = pid == 0
216-
? GetCurrentProcess()
217+
? NtCurrentProcess()
217218
: OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
218219

219220
if (hProcess == NULL)

src/common/windows/nt.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,7 @@ typedef struct _PROCESS_DEVICEMAP_INFORMATION_EX
266266
};
267267
ULONG Flags; // PROCESS_LUID_DOSDEVICES_ONLY
268268
} PROCESS_DEVICEMAP_INFORMATION_EX, *PPROCESS_DEVICEMAP_INFORMATION_EX;
269+
270+
#ifndef NtCurrentProcess
271+
#define NtCurrentProcess() ((HANDLE)(LONG_PTR)-1)
272+
#endif

src/detection/bootmgr/bootmgr_windows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
#include "bootmgr.h"
22
#include "efi_helper.h"
33
#include "common/io.h"
4+
#include "common/windows/nt.h"
45

56
#include <windows.h>
67

78
const char* enablePrivilege(const wchar_t* privilege)
89
{
910
FF_AUTO_CLOSE_FD HANDLE token = NULL;
10-
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
11+
if (!OpenProcessToken(NtCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
1112
return "OpenProcessToken() failed";
1213

1314
TOKEN_PRIVILEGES tp = {

src/detection/disk/disk_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const char* ffDetectDisksImpl(FFDiskOptions* options, FFlist* disks)
1212
{
1313
PROCESS_DEVICEMAP_INFORMATION_EX info = {};
1414
ULONG size = 0;
15-
if(!NT_SUCCESS(NtQueryInformationProcess(GetCurrentProcess(), ProcessDeviceMap, &info, sizeof(info), &size)))
15+
if(!NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessDeviceMap, &info, sizeof(info), &size)))
1616
return "NtQueryInformationProcess(ProcessDeviceMap) failed";
1717

1818
// For cross-platform portability; used by `presets/examples/13.jsonc`

src/detection/terminalshell/terminalshell_windows.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "common/windows/registry.h"
77
#include "common/windows/unicode.h"
88
#include "common/windows/version.h"
9+
#include "common/windows/nt.h"
910
#include "common/stringUtils.h"
1011

1112
#include <stdalign.h>
@@ -223,7 +224,7 @@ static bool detectDefaultTerminal(FFTerminalResult* result)
223224
conhost:;
224225
ULONG_PTR conhostPid = 0;
225226
ULONG size;
226-
if(NT_SUCCESS(NtQueryInformationProcess(GetCurrentProcess(), ProcessConsoleHostProcess, &conhostPid, sizeof(conhostPid), &size)) && conhostPid != 0)
227+
if(NT_SUCCESS(NtQueryInformationProcess(NtCurrentProcess(), ProcessConsoleHostProcess, &conhostPid, sizeof(conhostPid), &size)) && conhostPid != 0)
227228
{
228229
// For Windows Terminal, it reports the PID of OpenConsole
229230
if(ffProcessGetInfoWindows((uint32_t) conhostPid, NULL, &result->processName, &result->exe, &result->exeName, &result->exePath, NULL))

0 commit comments

Comments
 (0)