Skip to content

Commit cc3595c

Browse files
committed
Processing (Windows): prefers NT APIs
1 parent 8c72792 commit cc3595c

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

src/common/impl/processing_windows.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -216,12 +216,14 @@ const char* ffProcessReadOutput(FFProcessHandle* handle, FFstrbuf* buffer)
216216

217217
bool ffProcessGetInfoWindows(uint32_t pid, uint32_t* ppid, FFstrbuf* pname, FFstrbuf* exe, const char** exeName, FFstrbuf* exePath, bool* gui)
218218
{
219-
FF_AUTO_CLOSE_FD HANDLE hProcess = pid == 0
220-
? NtCurrentProcess()
221-
: OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
222-
223-
if (hProcess == NULL)
224-
return false;
219+
FF_AUTO_CLOSE_FD HANDLE hProcess = NtCurrentProcess();
220+
if(pid != 0)
221+
{
222+
if (!NT_SUCCESS(NtOpenProcess(&hProcess, PROCESS_QUERY_LIMITED_INFORMATION, &(OBJECT_ATTRIBUTES) {
223+
.Length = sizeof(OBJECT_ATTRIBUTES),
224+
}, &(CLIENT_ID) { .UniqueProcess = (HANDLE)(uintptr_t) pid })))
225+
return false;
226+
}
225227

226228
if(ppid)
227229
{

src/common/windows/nt.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,3 +1098,10 @@ NTSYSAPI NTSTATUS NTAPI NtQueryKey(
10981098
_In_ ULONG Length,
10991099
_Out_ PULONG ResultLength
11001100
);
1101+
1102+
NTSYSAPI NTSTATUS NTAPI NtOpenProcess(
1103+
_Out_ PHANDLE ProcessHandle,
1104+
_In_ ACCESS_MASK DesiredAccess,
1105+
_In_ PCOBJECT_ATTRIBUTES ObjectAttributes,
1106+
_In_opt_ PCLIENT_ID ClientId
1107+
);

src/detection/wm/wm_windows.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,10 @@ static bool verifySignature(const wchar_t* filePath)
5252

5353
static bool isProcessTrusted(DWORD processId, FFProcessType processType, UNICODE_STRING* buffer, size_t bufSize)
5454
{
55-
FF_AUTO_CLOSE_FD HANDLE hProcess = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, processId);
56-
if (!hProcess)
55+
FF_AUTO_CLOSE_FD HANDLE hProcess = NULL;
56+
if (!NT_SUCCESS(NtOpenProcess(&hProcess, PROCESS_QUERY_LIMITED_INFORMATION, &(OBJECT_ATTRIBUTES) {
57+
.Length = sizeof(OBJECT_ATTRIBUTES),
58+
}, &(CLIENT_ID) { .UniqueProcess = (HANDLE)(uintptr_t) processId })))
5759
return false;
5860

5961
ULONG size;

0 commit comments

Comments
 (0)