master
c 41 lines 1.24 KB
Raw
1 // SPDX-License-Identifier: GPL-3.0-or-later
2
3 // this must not include libnetdata.h because STRING is defined in winternl.h
4
5 #include "libnetdata/common.h"
6
7 #if defined(OS_WINDOWS)
8 #include <winternl.h>
9
10 // --------------------------------------------------------------------------------------------------------------------
11 // Get the full windows command line
12
13 WCHAR* GetProcessCommandLine(HANDLE hProcess) {
14 PROCESS_BASIC_INFORMATION pbi;
15 ULONG len;
16 NTSTATUS status = NtQueryInformationProcess(hProcess, 0, &pbi, sizeof(pbi), &len);
17 if (status != 0)
18 return NULL;
19
20 // The rest of the function remains the same as before
21 PEB peb;
22 if (!ReadProcessMemory(hProcess, pbi.PebBaseAddress, &peb, sizeof(peb), NULL))
23 return NULL;
24
25 RTL_USER_PROCESS_PARAMETERS procParams;
26 if (!ReadProcessMemory(hProcess, peb.ProcessParameters, &procParams, sizeof(procParams), NULL))
27 return NULL;
28
29 WCHAR* commandLine = (WCHAR*)malloc(procParams.CommandLine.MaximumLength);
30 if (!commandLine)
31 return NULL;
32
33 if (!ReadProcessMemory(hProcess, procParams.CommandLine.Buffer, commandLine, procParams.CommandLine.MaximumLength, NULL)) {
34 free(commandLine);
35 return NULL;
36 }
37
38 return commandLine;
39 }
40
41 #endif