Get STARTUPINFO for this process

Can I get information about starting another running process? I want to know the arguments of the cmd line if it should be run with minimum / maximum, run in the directory, run as admin, etc.

+6
source share
1 answer

you need to read RTL_USER_PROCESS_PARAMETERS from the remote process. it can be done like this:

NTSTATUS GetProcessParameters(PCLIENT_ID pcid, PUNICODE_STRING CommandLine) { HANDLE hProcess; NTSTATUS status; static OBJECT_ATTRIBUTES zoa = { sizeof(zoa)}; if (0 <= (status = ZwOpenProcess(&hProcess, PROCESS_VM_READ|PROCESS_QUERY_INFORMATION, &zoa, pcid))) { PROCESS_BASIC_INFORMATION pbi; _RTL_USER_PROCESS_PARAMETERS ProcessParameters, *pv; if (0 <= (status = ZwQueryInformationProcess(hProcess, ProcessBasicInformation, &pbi, sizeof(pbi), 0))) { if ( (0 <= (status = ZwReadVirtualMemory(hProcess, (_PEB*)&pbi.PebBaseAddress->ProcessParameters, &pv, sizeof(pv), 0))) && (0 <= (status = ZwReadVirtualMemory(hProcess, pv, &ProcessParameters, sizeof(ProcessParameters), 0))) ) { if (ProcessParameters.CommandLine.Length) { if (CommandLine->Buffer = (PWSTR)LocalAlloc(0, ProcessParameters.CommandLine.Length + sizeof(WCHAR))) { if (0 > (status = ZwReadVirtualMemory(hProcess, ProcessParameters.CommandLine.Buffer, CommandLine->Buffer, ProcessParameters.CommandLine.Length, 0))) { LocalFree(CommandLine->Buffer); } else { CommandLine->MaximumLength = (CommandLine->Length = ProcessParameters.CommandLine.Length) + sizeof(WCHAR); *(PWSTR)RtlOffsetToPointer(CommandLine->Buffer, ProcessParameters.CommandLine.Length) = 0; } } else { status = STATUS_INSUFFICIENT_RESOURCES; } } } } ZwClose(hProcess); } return status; } UNICODE_STRING CommandLine; if (0 <= GetProcessParameters(&cid, &CommandLine)) { DbgPrint("CommandLine=%wZ\n", &CommandLine); LocalFree(CommandLine.Buffer); } 
+2
source

All Articles