Server Source

.386 .model flat,stdcall option casemap:none CreateSocket PROTO :DWORD inv equ invoke include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\user32.inc include \masm32\include\shell32.inc include \masm32\include\wsock32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib includelib \masm32\lib\shell32.lib includelib \masm32\lib\wsock32.lib .const X_Win equ 160 Y_Win equ 090 port equ 25 WM_SOCKET equ WM_USER+100 ICON equ 1 RESTART equ 0 SHUTDOWN equ 1 SYSLOCKUP equ 2 .data szShutdown db "Shutdown", 0 szRestart db "Restart", 0 szDunno db "I don't know this msg", 0 ClassName db "Win32ASM_Class", 0 AppName db "Server", 0 wc WNDCLASSEX <SIZEOF WNDCLASSEX, CS_HREDRAW or CS_VREDRAW, offset WndProc, \ NULL, NULL, NULL, NULL, NULL, COLOR_WINDOW + 1, NULL, \ offset ClassName, NULL> szConnect db "Connection esthablished", 0 eFuck db "Something went wrong!", 0 .data? hInstance dd ? hwnd dd ? X_Pos dd ? Y_Pos dd ? msg MSG <?> sin sockaddr_in <?> sSocket dd ? wsadata WSADATA <?> bRead dd ? available_data dd ? cSocket dd ? .code start: inv GetModuleHandle, NULL mov hInstance, eax mov wc.hInstance, eax inv LoadIcon, hInstance, ICON mov wc.hIcon, eax mov wc.hIconSm, eax inv LoadCursor, NULL, IDC_ARROW mov wc.hCursor, eax inv RegisterClassEx, offset wc inv GetSystemMetrics,SM_CXSCREEN ; Calculate Screen center shr eax, 1 sub eax, X_Win / 2 mov X_Pos, eax inv GetSystemMetrics,SM_CYSCREEN shr eax, 1 sub eax, Y_Win / 2 mov Y_Pos, eax inv CreateWindowEx, NULL, offset ClassName, offset AppName, WS_OVERLAPPEDWINDOW, \ X_Pos, Y_Pos, X_Win, Y_Win, NULL, NULL, hInstance, NULL mov hwnd, eax inv ShowWindow, eax, SW_SHOW inv UpdateWindow, hwnd .while TRUE inv GetMessage, offset msg, NULL, 0, 0 .break .if (!eax) inv TranslateMessage, offset msg inv DispatchMessage, offset msg .endw inv ExitProcess, msg.wParam ; Window Proc WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM .if uMsg == WM_DESTROY inv closesocket, sSocket inv WSACleanup inv PostQuitMessage, NULL .elseif uMsg == WM_CREATE inv WSAStartup, 101h, offset wsadata inv CreateSocket, hWnd .elseif uMsg == WM_SOCKET mov eax, wParam mov cSocket, eax mov eax, lParam .if ax == FD_ACCEPT inv accept, sSocket, 0, 0 .elseif ax == FD_READ inv ioctlsocket, cSocket, FIONREAD, offset available_data .if eax == NULL inv GlobalAlloc, GMEM_FIXED + GMEM_ZEROINIT, available_data mov bRead, eax inv recv, cSocket, bRead, available_data, 0 mov available_data, eax ; inv MessageBox, hWnd, bRead, bRead, MB_OK mov esi, bRead cld lodsb .if al == RESTART inv ExitWindowsEx, EWX_REBOOT, 0 .elseif al == SHUTDOWN inv ExitWindowsEx, EWX_SHUTDOWN, 0 .else inv MessageBox, hWnd, offset szDunno, offset AppName, MB_OK .endif inv GlobalFree, bRead .else inv MessageBox, hWnd, offset eFuck, offset eFuck, MB_OK .endif .endif .else inv DefWindowProc, hWnd, uMsg, wParam, lParam ret .endif xor eax,eax ret WndProc endp CreateSocket proc hWnd:DWORD mov sin.sin_family, AF_INET inv htons, port mov sin.sin_port, ax inv socket, PF_INET, SOCK_STREAM, 0 mov sSocket, eax inv WSAAsyncSelect, sSocket, hWnd, WM_SOCKET, FD_ACCEPT + FD_CLOSE + FD_READ inv bind, sSocket, offset sin, SIZEOF sin inv listen, sSocket, 2 ret CreateSocket endp end start


© Copyright by BsE.