WinVNC source code analysis

Source: Internet
Author: User

The following content is the execution process determined by the entire source code debugged by the VC. Net debugger. Do not analyze the code statically when analyzing the code, which is very slow. With the debugger, we can track the entire execution process by simply setting breakpoints. The overall process of WinVNC debugging is as follows: Winmain(1) initialize the socket library vsocketsystem (2) Parse command line parameters (3) Call the Main Window Process winvncappmain Winvncappmain(1) confirm that only one instance is currently running, vncinsthandler (2) create a server class, the role of this class: dynamically add and delete clients send updates to local windows to all connected clients, and send client mouse and keyboard events to connect local Sockets (3) create menus and pallets Vncmenu  Vncmenu(1) constructor: Create a tray icon window to add the window Tray Icon handle VncserverIn. m_policylist, initialize vncproperties-> init. In init, call vncproperties-> load to call vncproperties-> applyuserprefs to call server-> sockconnect to create various threads and set port States. Check whether the password needs to be verified in init. When we double-click the icon, vncproperties> applyuserprefs will be called, and vncproperties> applyuserprefs will call vncserver: sockconnect to restart the program. When a client is connected:When a client is connected, the run_undetached thread calls addclient after receiving the connection to add the client to a client's ing array. The key is clientsocket and the value is the class of the new client. Create a client thread and add the client to the list of unauthorized clients. Client thread work (Handle client-related work): The run function of the client Thread class vncclientthread is equivalent to the thread function (called in the thread ). Call the vncclientthread: initversion () function in the vncclientthread-> RUN function. The initversion function works as follows: (1) first, send your (server) version number (2) to the client) receive Client Version Number (3) Verify version number the run function of the client Thread class vncclientthread calls vncclientthread-> initauthenticateinitauthenticate to send an authentication request to the client (2) verify whether the client is valid for vncdesktopthread-> run_undetached thread ( Core functions) :( 1) This thread calls vncdesktop: startup (): For all initialization tasks: 1. set the pixel format and bitmap information. set various system hooks and add system hooks, including screen, keyboard, and mouse. 3. Set a timer to process the PULL mode ( Polling Mode), Run once every second. TriggerupdateThe routine is executed once per second. (2) set to process the clipboard message (3) create a cache region object. All region update messages are cached in this object, only when TriggerupdateThe messages are sent to all clients only when they are triggered. Authentication process: 1. Version authentication process: Remove this version authentication process. The authentication process for this version is roughly the WinVNC client on the server side. winmain à vncviewerapp32: newconnection (create clientconnection object) à clientconnection: Run function: (1) the pop-up window appears, receive the IP address and port number of the server entered by the user (2) obtain the connection information and perform clientconnection: getconnectdetails () (3) authentication clientconnection: negotiateprotocolversion () (4) perform permission verification clientconnection: Authenticate (); Modification time: Saturday, August 25, 2007 Modify content: Authdialog. cpp and authdialog. h are removed. The content of this authentication session box is that the client can enter the server password to remotely control the server. Modification time: 8/25/2007 9:43:10 AM Modification content:Remove log. cpp and log. H. This is a record of the results of each operation. For client codeAn important method to implement this function: Create a main display window for the clientconnection class. The window process is the static method static clientconnection: winprocclientconnection class to create a thread, and the clientconnection :: run_undetached, which is equivalent to the thread method in this class. Clientconnection: run_undetached analysis: run_undetached is a false thread method (). The implementation method may be: This method is a virtual function, in the base class, this method has been passed to the start function as a thread parameter, which is passed as a function pointer, in this way, you can use the function pointer to call the function in the Start function. The inheritance class only needs to implement run_undetached as a thread method. ( The reason for doing so is: Thread methods are not allowed to be used as members in the thread. Compilation is a problem of the call conventions.) Implementation process of this routine: the types of messages sent from the receiving server: frame update and readbell. Switch to the corresponding score. The subsequent processing of frameupdate is as follows: 1. read the number of rect updates on the server, rectcount, and then enter the for loop, rectcount2. read the header information of each rect, determine the coordinates, width, and height of the rect, and encode information 3. enter a specific swtich branch based on the encoding information and receive real data. 4. convert the received rect region to Windows coordinates.

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.