È possibile ottenere le informazioni di avvio di un altro processo in esecuzione? Voglio scoprire gli argomenti della riga cmd, se deve essere eseguito minimizzato/massimizzato, avviare nella directory, eseguire come amministratore, ecc.Ottenere STARTUPINFO per il processo specificato
risposta
è necessario leggere RTL_USER_PROCESS_PARAMETERS dal processo remoto. questo può essere fatto in questo modo
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);
}
Questo non aiuta a ottenere 'STARTUPINFO', che è la vera domanda. –
cerca i campi STARTUPINFO e i campi RTL_USER_PROCESS_PARAMETERS: è quasi uguale. veramente STARTUPINFO è compilato da RTL_USER_PROCESS_PARAMETERS – RbMm
Probabilmente vale la pena ricordare che la documentazione dice: "La funzione ZwQueryInformationProcess e le strutture che restituisce sono interne al sistema operativo e sono soggette a modifiche da una versione di Windows a un'altra. Per mantenere la compatibilità della tua applicazione , è preferibile utilizzare le funzioni pubbliche citate nella descrizione del parametro ProcessInformationClass. " – theB
1. Inserire il codice nel processo di destinazione. 2. Chiama 'GetStartupInfo()' e 'GetCommandLine()' dal contesto del processo di destinazione. 3. Passare i dati alla procedura originale. –
@ JonathanPotter grazie per il tuo commento. Lo scopo è di fornire all'utente la possibilità di avviare processi (con i loro attributi di avvio corretti) facendo clic su un pulsante. Iniettare il codice per ottenere gli attributi di avvio corretti sarebbe sospetto/contrassegnato dai programmi antivirus, vero? –
@JakeM: la riga di comando di un processo può essere recuperata senza utilizzare l'iniezione, sia [leggendo la struttura 'PEB' del processo] (http://stackoverflow.com/a/11042947/65863), sia usando [WMI] (https :? //blogs.msdn.microsoft.com/oldnewthing/20091125-00/ p = 15923). –