| |

VerySource

 Forgot password?
 Register
Search
View: 4594|Reply: 11

[Discussion] How to realize the output of cmd in win32 assembly

[Copy link]

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2020-12-17 13:00:01
| Show all posts |Read mode
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
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-12-17 20:15:01
| Show all posts
If vc is available, win32asm is also available, use /subsystem:console to connect, and then use
The console api is fine.
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-12-18 11:00:01
| Show all posts
Should I use /subsystem:console in link VC code or asm?
Reply

Use magic Report

0

Threads

15

Posts

13.00

Credits

Newbie

Rank: 1

Credits
13.00

 China

Post time: 2020-12-18 12:15:01
| Show all posts
Used in masm32 link.
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-12-18 14:30:01
| Show all posts
:(

I added   it doesn't seem to work
Reply

Use magic Report

0

Threads

23

Posts

17.00

Credits

Newbie

Rank: 1

Credits
17.00

 China

Post time: 2020-12-18 16:00:01
| Show all posts
The host did not point the hStdInput, hStdOutput, and hStdError members in the StartupInfo structure when the cmd.exe process was created to the handle returned by the previous accept() function. This is done in the c above
Reply

Use magic Report

0

Threads

3

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-12-19 14:30:01
| Show all posts
nodxsteelon the first floor   You used the console, but did not use the console API, there is still no result.
invoke stdout,addr szBuffer
invoke stdin,addr szBuffer
Use standard console API input and output statements
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-12-19 17:30:01
| Show all posts
Doesn’t seem to need to use the console API?

The input is only on the client side, if it is logged in via telnet, there is already. The server does not need to go to stdout, at most one send is sent to the client
Reply

Use magic Report

1

Threads

6

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

 Author| Post time: 2020-12-20 16:00:01
| Show all posts
szCommand db'cmd.exe',0
.
.
      invoke accept, hScoket, NULL, NULL; if there is a client connection, confirm immediately
       .if eax != INVALID_SOCKET
       mov hScoketOther,eax
      invoke GetStartupInfo,addr stStartUp
      mov ebx,hScoketOther
mov stStartUp.hStdInput,ebx
mov stStartUp.hStdOutput,ebx
mov stStartUp.hStdError,ebx
mov stStartUp.dwFlags,STARTF_USESHOWWINDOW or STARTF_USESTDHANDLES
mov stStartUp.wShowWindow,SW_HIDE
mov stStartUp.wShowWindow,SW_SHOWNORMAL
invoke CreateProcess,NULL,addr szCommand,NULL,NULL,\
NULL,NORMAL_PRIORITY_CLASS,NULL,NULL,offset stStartUp,offset stProcInfo
.endif
       Sweaty, once connected, immediately disconnected...
Reply

Use magic Report

0

Threads

17

Posts

16.00

Credits

Newbie

Rank: 1

Credits
16.00

 China

Post time: 2020-12-20 20:30:01
| Show all posts
Just use pipe. msdn has the complete source code.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list