CODE:#define STARTF_USESHOWWINDOW 1
#define STARTF_USESTDHANDLES 256
#define SW_HIDE 0
#define INFINITE -1
external(INT, "CreatePipe", "CreatePipe", "kernel32.dll");
external(VOID, "ZeroMemory", "RtlZeroMemory", "kernel32.dll");
external(VOID, "GetStartupInfo", "GetStartupInfoA", "kernel32.dll");
external(INT, "CreateProcess", "CreateProcessA", "kernel32.dll");
external(INT, "ReadFile", "ReadFile", "kernel32.dll");
external(INT, "WriteFile", "WriteFile", "kernel32.dll");
external(INT, "TerminateProcess", "TerminateProcess", "kernel32.dll");
external(INT, "WaitForSingleObject", "WaitForSingleObject", "kernel32.dll");
external(INT, "CloseHandle", "CloseHandle", "kernel32.dll");
string path="C:\Windows\System32\cmd.exe -i";
int hReadPipe1, hWritePipe1, hReadPipe2, hWritePipe2;
char pi[16];
char W_buff[1000000];
string Rez;
if (Start())
{
int lBytesWrite;
WriteFile(hWritePipe2, "dir^n", size("dir^n"), address(#lBytesWrite), 0);
sleep(500);
int readed;
ReadFile(hReadPipe1, address(#W_buff[0]), 1024 , address(#readed), 0);
W_buff[readed]=0;
messagebox (format(#W_buff[0]));
}
function Start()//Запустить программу и наладить с ней связь PIPE
{
int ret;
//SECURITY_ATTRIBUTES
char sa[12];
initialarray(#sa[0], 0);
writeaddress(sizearray(sa), address(#sa[0]));
writeaddress(0, address(#sa[4]));
writeaddress(1, address(#sa[8]));
ret=CreatePipe(address(#hReadPipe1),address(#hWritePipe1),address(#sa[0]),0);
if (ret==0)return 0;
ret=CreatePipe(address(#hReadPipe2),address(#hWritePipe2),address(#sa[0]),0);
if (ret==0)return 0;
//STARTUPINFO
char si[68];
initialarray(#si[0], 0);
ZeroMemory(address(#si[0]),sizearray(si));
GetStartupInfo(address(#si[0]));
writeaddress(sizearray(si), address(#si[0]));
writeaddress(STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES, address(#si[44]));
writeaddress(SW_HIDE, address(#si[48]));
writeaddress(hReadPipe2, address(#si[56]));
writeaddress(hWritePipe1, address(#si[60]));
writeaddress(hWritePipe1, address(#si[64]));
//PROCESS_INFORMATION
initialarray(#pi[0], 0);
ret=CreateProcess(0,path,0,0,1,0,0,0,address(#si[0]),address(#pi[0]));
if (ret==0)return 0;
return 1;
}
function Close()
{
TerminateProcess(addressi(address(#pi[0])), 0);
WaitForSingleObject(addressi(address(#pi[0])), INFINITE );
CloseHandle(addressi(address(#pi[0])));
CloseHandle(addressi(address(#pi[4])));
CloseHandle(hReadPipe1);
CloseHandle(hWritePipe1);
CloseHandle(hReadPipe2);
CloseHandle(hWritePipe2);
}