home *** CD-ROM | disk | FTP | other *** search
/ ftp.sberbank.sumy.ua / 2014.11.ftp.sberbank.sumy.ua.tar / ftp.sberbank.sumy.ua / incoming / 1 / DayTime.asm < prev    next >
Assembly Source File  |  2014-02-08  |  8KB  |  310 lines

  1.       .386
  2.       .model flat, stdcall  ; 32 bit memory model
  3.       option casemap :none  ; case sensitive
  4.  
  5.  
  6.       include \masm32\include\windows.inc
  7.       include \masm32\include\user32.inc
  8.       include \masm32\include\kernel32.inc
  9.       include \masm32\include\gdi32.inc
  10.       include \masm32\include\wsock32.inc
  11.       
  12.       includelib \masm32\lib\user32.lib
  13.       includelib \masm32\lib\kernel32.lib
  14.       includelib \masm32\lib\gdi32.lib
  15.       includelib \masm32\lib\wsock32.lib
  16.       
  17.  
  18.       return MACRO arg
  19.         mov eax, arg
  20.         ret
  21.       ENDM
  22.   
  23.  
  24.   WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
  25.   WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
  26.   TableCreateControls PROTO :DWORD, :DWORD, :DWORD
  27.   GetButtonProc PROTO :DWORD, :DWORD
  28.   MultiEdit PROTO :DWORD, :DWORD
  29.  
  30.  
  31. .data
  32.  
  33.  szClassName   db "Evgeney-Victorovich-Kupin-27-April-1982",0
  34.  szDisplayName db "Net bones Daytime protocol 13",0
  35.  
  36.  CommandLine   dd 0
  37.  hWnd          dd 0
  38.  hInstance     dd 0
  39.  
  40.  hIcon         dd 0
  41.  
  42. PosX          dd 0
  43. PosY          dd 0 
  44. dWidth        dd 450
  45. dHeight       dd 380
  46.  
  47. hSock   dd 0   
  48. strWsaData  WSADATA <0> 
  49.  
  50. stError db "Socket error",0
  51.  
  52. stWspritf db "%s%d.%d.%d.%d",0dh,0ah,0
  53. stBuffer db 256 dup(0)
  54. stBufferOne db 256 dup(0)
  55.  
  56.  
  57. tButtonStyle  equ WS_VISIBLE or WS_CHILD or BS_DEFPUSHBUTTON
  58. tMultiEditStyle  equ WS_VISIBLE or WS_CHILD or WS_VSCROLL or ES_MULTILINE or WS_HSCROLL or ES_AUTOHSCROLL
  59. tEditStyle equ WS_VISIBLE or WS_CHILDWINDOW or ES_AUTOHSCROLL or ES_NOHIDESEL
  60.  
  61.  
  62. stButtonClass   db "BUTTON",0
  63. stEditClass   db "EDIT",0
  64. stGetButton   db "Get",0
  65. stSetButton   db "Set",0
  66. stWWWaddress  db "time.nist.gov",0
  67.  
  68.  
  69. tControl  dd offset stButtonClass, stGetButton, 320, 0, 100, 30, tButtonStyle, GetButtonProc,\
  70.              offset stButtonClass, stSetButton, 320, 35, 100, 30, tButtonStyle, GetButtonProc,\
  71.              offset stEditClass, offset stWWWaddress, 0, 0, 300, 30, tEditStyle, MultiEdit,\ 
  72.              offset stEditClass, 0, 0, 35, 300, 300, tMultiEditStyle, MultiEdit 
  73.  
  74. tControlBase dd 10
  75. tControlID dd 10   
  76. tHandles   dd 100 dup(0)
  77.  
  78.  
  79. .code
  80.  
  81. start:
  82.       invoke GetModuleHandle, NULL
  83.       mov hInstance, eax
  84.  
  85.       invoke GetCommandLine
  86.       mov CommandLine, eax
  87.  
  88.       invoke WinMain, hInstance,NULL,CommandLine,SW_SHOWDEFAULT
  89.       invoke ExitProcess,eax
  90.  
  91. WinMain proc hInst     :DWORD, hPrevInst :DWORD, CmdLine   :DWORD, CmdShow   :DWORD
  92.  
  93.       LOCAL wc   :WNDCLASSEX
  94.       LOCAL msg  :MSG
  95.  
  96.       mov wc.cbSize,          sizeof WNDCLASSEX
  97.       mov wc.style,           CS_HREDRAW or CS_VREDRAW \
  98.                               or CS_BYTEALIGNWINDOW
  99.       mov  wc.lpfnWndProc,    offset WndProc
  100.       mov  wc.cbClsExtra,     NULL
  101.       mov  wc.cbWndExtra,     NULL
  102.       push hInst
  103.       pop  wc.hInstance
  104.       mov  wc.hbrBackground,  COLOR_BACKGROUND
  105.       mov  wc.lpszMenuName,   NULL
  106.       mov  wc.lpszClassName,  offset szClassName
  107.       push hIcon
  108.       pop  wc.hIcon
  109.       invoke LoadCursor,NULL,IDC_ARROW
  110.       mov  wc.hCursor,        eax
  111.       push hIcon 
  112.       pop  wc.hIconSm
  113.  
  114.       invoke RegisterClassEx, ADDR wc
  115.  
  116.       invoke GetSystemMetrics,SM_CXSCREEN
  117.       sub eax, dWidth
  118.       shr eax,1
  119.       mov PosX, eax
  120.  
  121.       invoke GetSystemMetrics,SM_CYSCREEN
  122.       sub eax, dHeight
  123.       shr eax,1
  124.       mov PosY, eax
  125.  
  126.       invoke CreateWindowEx,WS_EX_LEFT,
  127.                             ADDR szClassName,
  128.                             ADDR szDisplayName,
  129.                             WS_OVERLAPPEDWINDOW or WS_SYSMENU,
  130.                             PosX, PosY,dWidth,dHeight,
  131.                             NULL,NULL,
  132.                             hInst,NULL
  133.       mov   hWnd,eax
  134.  
  135.       invoke ShowWindow,hWnd,SW_SHOWNORMAL
  136.       invoke UpdateWindow,hWnd
  137.  
  138.     StartLoop:
  139.       invoke GetMessage,ADDR msg,NULL,0,0
  140.       cmp eax, 0
  141.       je ExitLoop
  142.       invoke TranslateMessage, ADDR msg
  143.       invoke DispatchMessage,  ADDR msg
  144.       jmp StartLoop
  145.     ExitLoop:
  146.  
  147.       return msg.wParam
  148.  
  149. WinMain endp
  150.  
  151.  
  152. WndProc proc hWin:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
  153.  
  154.  
  155.     .if uMsg == WM_CREATE
  156.  
  157.         mov eax, 0202h
  158.         invoke WSAStartup, eax, addr strWsaData
  159.  
  160.         invoke TableCreateControls, addr tControl, hWin, 4 
  161.         return 0
  162.  
  163.     .elseif uMsg == WM_COMMAND
  164.        
  165.         mov ecx, offset tControl
  166.         mov eax, wParam
  167.         and eax, 0ffffh
  168.         sub eax, tControlBase
  169.         shl eax, 5
  170.         add ecx, eax
  171.         shr eax, 3  
  172.  
  173.         cmp tHandles[eax],0
  174.         je  WndProc_WM_COMMAND_exit
  175.         
  176.         push tHandles[eax]
  177.         push hWin
  178.         call DWORD PTR[ecx+28]
  179.  
  180. WndProc_WM_COMMAND_exit:
  181.  
  182.         return 0
  183.  
  184.     .elseif uMsg == WM_DESTROY
  185.         invoke WSACleanup
  186.         invoke PostQuitMessage,NULL
  187.         return 0 
  188.     .endif
  189.  
  190.     invoke DefWindowProc,hWin,uMsg,wParam,lParam
  191.  
  192.     ret
  193.  
  194. WndProc endp
  195.  
  196. TableCreateControls proc pTable:DWORD, hWin:DWORD, dNumber:DWORD
  197.      
  198.     xor eax, eax
  199.  
  200. TableCreateControls_loop:
  201.     push eax
  202.     mov ecx, pTable     
  203.     shl eax, 2
  204.     shl eax, 3
  205.     add ecx, eax        
  206.  
  207.     invoke CreateWindowEx,WS_EX_CLIENTEDGE, [ecx], [ecx+4],\
  208.            [ecx+24],[ecx+8],[ecx+12],[ecx+16],[ecx+20],\
  209.            hWin, tControlID, hInstance, NULL
  210.     pop ecx  
  211.     shl ecx, 2
  212.     mov tHandles[ecx],eax
  213.     shr ecx, 2 
  214.     mov eax,ecx 
  215.     inc tControlID
  216.     inc eax
  217.     cmp eax, dNumber
  218.     jb TableCreateControls_loop
  219.       
  220.     ret
  221. TableCreateControls endp
  222.  
  223. GetButtonProc proc hWin:DWORD, hControl:DWORD
  224.  LOCAL lpHostent:DWORD
  225.  LOCAL aIP,bIP,cIP,dIP:DWORD
  226.  LOCAL sockAddr:sockaddr_in
  227.  
  228.     invoke GetWindowText, tHandles[4*2], addr stBuffer, 255
  229.  
  230.     invoke gethostbyname, addr stBuffer
  231.     cmp eax,0
  232.     je GetButtonProc_display_ip_list_exit
  233.     mov lpHostent, eax
  234.  
  235.     mov stBuffer[0],0 
  236.  
  237.     mov edx, 0
  238. GetButtonProc_display_ip_list:    
  239.     mov eax, lpHostent
  240.     mov ecx, [eax+12]
  241.     mov ecx, [ecx+edx]
  242.     cmp ecx, 0
  243.     je GetButtonProc_display_ip_list_exit
  244.     push [ecx]
  245.     pop aIP
  246.     and aIP, 0ffh
  247.     push [ecx]
  248.     pop bIP
  249.     shr bIP, 8
  250.     and bIP, 0ffh
  251.     push [ecx]
  252.     pop cIP
  253.     shr cIP, 16
  254.     and cIP, 0ffh
  255.     push [ecx]
  256.     pop dIP
  257.     shr dIP, 24
  258.     and dIP, 0ffh
  259.  
  260.     push edx
  261.     invoke wsprintf, addr stBuffer, addr stWspritf, addr stBuffer, aIP, bIP, cIP, dIP
  262.     pop edx
  263.     add edx, 4
  264.     jmp GetButtonProc_display_ip_list
  265. GetButtonProc_display_ip_list_exit:    
  266.  
  267.     invoke SetWindowText, tHandles[4*3], addr stBuffer
  268.  
  269.     invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
  270.     mov hSock, eax 
  271.  
  272.     mov sockAddr.sin_family, AF_INET
  273.     xor ax,ax
  274.     mov ah, 13
  275.     mov sockAddr.sin_port, ax
  276.  
  277.     mov eax, lpHostent
  278.     mov ecx, [eax+12]
  279.     mov ecx, [ecx]
  280.     push [ecx]
  281.     pop sockAddr.sin_addr
  282.  
  283.     invoke connect, hSock, addr sockAddr, sizeof sockaddr_in
  284.  
  285.    .if eax == SOCKET_ERROR
  286.      invoke MessageBox, hWin, addr stError, addr stError,0
  287.    .endif  
  288.  
  289.     invoke recv, hSock, addr stBufferOne, 256, 0 
  290.  
  291.     invoke closesocket, hSock
  292.  
  293.     mov stBufferOne[0], ">" 
  294.     invoke lstrcat, addr stBuffer, addr stBufferOne
  295.     
  296.     invoke SetWindowText, tHandles[4*3], addr stBuffer
  297.  
  298.     mov DWORD PTR stBufferOne[0],0   
  299.  
  300.     ret
  301. GetButtonProc endp
  302.  
  303. MultiEdit proc hWin:DWORD, hControl:DWORD
  304.  
  305.  
  306.     invoke GetWindowText, hControl, addr stBuffer, 255 
  307.     ret
  308. MultiEdit endp
  309. end start
  310.