home *** CD-ROM | disk | FTP | other *** search
/ Reverse Code Engineering RCE CD +sandman 2000 / ReverseCodeEngineeringRceCdsandman2000.iso / RCE / Mib / CRUECHAT.ZIP / CRUECHAT.ASM next >
Encoding:
Assembly Source File  |  1998-12-12  |  11.1 KB  |  533 lines

  1. .386
  2. locals
  3. jumps
  4. .model flat,STDCALL
  5.  
  6. include win32.inc
  7. include wsock32.inc
  8.  
  9. ;---------------------------------------------------------------------
  10.  
  11. L equ <LARGE>
  12.  
  13. WM_SOCKET   equ WM_USER+100
  14.  
  15. IDD_EXIT     EQU 1001
  16. IDD_YOU         EQU 1002
  17. IDD_REMOTE   EQU 1003
  18. IDD_SEND     EQU 1004
  19. IDD_CONNECT  EQU 1005
  20. IDD_CANCEL   EQU 1006
  21. IDD_STATUS     EQU 1007
  22. IDI_ICON1    EQU 100
  23. IDD_IPEDIT   EQU 1103
  24. IDD_ABOUTOK     EQU 1300
  25.  
  26. IDM_CONN     EQU 1200
  27. IDM_USERINFO EQU 1201
  28. IDM_ABOUT    EQU 1202
  29. IDM_EXIT     EQU 1203
  30.  
  31. TRUE        EQU 1
  32. FALSE       EQU 0
  33. NULL        EQU 0
  34.  
  35. ;-----------
  36.  
  37. .data
  38.  
  39. szTitleName      db '',0
  40. szClassName      db 'ASMCLASS32',0
  41. msg              MSGSTRUCT   <?>
  42. wc               WNDCLASS    <?>
  43.  
  44. wsadata          WSAdata <?> 
  45. sin              sockaddr_in <?>
  46.  
  47. szNULL            db      0
  48. ymenu             dd      0
  49.  
  50. hInst            dd 0
  51. hMenu            dd 0
  52. hDlg             dd 0
  53.  
  54. dlg_start        db 'DLG_START',0
  55. dlg_about         db 'DLG_ABOUT',0
  56. dlg_conn         db 'DLG_CONN',0
  57.  
  58. sockdes             dd 0
  59. newsockdes         dd 0
  60. TheIP             db 16 dup (0)
  61. PORT             dd 1024
  62.  
  63. ServDowntitle     db 'Connection lost!',0
  64. ServDowntext     db 'Connection to server lost, exiting!',0
  65. err2title         db 'No connection!',0
  66. err2text         db 'Could not establish connection!',0
  67.  
  68. conntitle         db 'Connection!',0
  69. conntext         db 'Connection established!',0
  70.  
  71. NotConnected     db '          Not Connected',0
  72. Connection         db '            Connected',0
  73.  
  74. CrueStr          db '½ Welcome to CrueChat! ╗',13,10,13,10,0
  75. SendBuffer        db 256 dup (0)
  76. ReadBuffer         db 256 dup (0)
  77.  
  78. .code
  79.  
  80. ;---------------------------------------------------------
  81. ; This is where control is received from the loader.
  82. ;---------------------------------------------------------
  83.  
  84.  
  85. start:
  86.         push    0
  87.         call    GetModuleHandle         
  88.         mov     [hInst], eax            
  89.  
  90.         push    offset wsadata                    ;Let's start
  91.         push    0101h
  92.         call    WSAStartup
  93.         test    eax,eax
  94.         jne        error
  95.  
  96.         push    0                                ;Create socket
  97.         push    SOCK_STREAM
  98.         push    PF_INET
  99.         call    socket
  100.         mov        sockdes,eax
  101.  
  102.         mov     sin.sin_family, AF_INET         ;Convert the port
  103.         push    PORT
  104.         call    htons
  105.         mov     sin.sin_port,ax         
  106.  
  107.         jmp        reg_class
  108. error:
  109.         ret
  110.  
  111. reg_class:
  112.  
  113.         mov     [wc.clsStyle], CS_HREDRAW + CS_VREDRAW + CS_GLOBALCLASS
  114.         mov     [wc.clsLpfnWndProc], offset WndProc
  115.         mov     [wc.clsCbClsExtra], 0
  116.         mov     [wc.clsCbWndExtra], 0
  117.  
  118.         mov     eax, [hInst]
  119.         mov     [wc.clsHInstance], eax
  120.  
  121.         push    IDI_ICON1
  122.         push     eax
  123.         call    LoadIcon
  124.  
  125.         mov     [wc.clsHIcon], eax
  126.  
  127.         push    L IDC_ARROW             
  128.         push    L 0
  129.         call    LoadCursor
  130.         mov     [wc.clsHCursor], eax
  131.  
  132.         push    0                   
  133.         push    offset Main_DlgProc
  134.         push    0
  135.         push    offset dlg_start
  136.         push    [hInst]
  137.         call    DialogBoxParamA
  138.         jmp     finish
  139.  
  140. msg_loop:
  141.         push    L 0
  142.         push    L 0
  143.         push    L 0
  144.         push    offset msg
  145.         call    GetMessage
  146.  
  147.         cmp     ax, 0
  148.         je      end_loop
  149.  
  150.         push    offset msg
  151.         call    TranslateMessage
  152.  
  153.         push    offset msg
  154.         call    DispatchMessage
  155.  
  156.         jmp     msg_loop
  157.  
  158. end_loop:
  159.  
  160.         push    [msg.msWPARAM]
  161.         call    ExitProcess             
  162.  
  163.  
  164. ;----------------------------------------------------------------------------
  165. ; WARNING: Win32 requires that EBX, EDI, and ESI be preserved!  
  166.  
  167. WndProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  168.         push    esi
  169.         push    edi
  170.         push    ebx
  171.         jmp     defwndproc
  172.  
  173. defwndproc:
  174.         push    [lparam]
  175.         push    [wparam]
  176.         push    [wmsg]
  177.         push    [hwnd]
  178.         call    DefWindowProc
  179.         jmp     finish
  180.  
  181. finish:
  182.         pop     ebx
  183.         pop     edi
  184.         pop     esi
  185.         ret
  186. WndProc endp
  187.  
  188. public WndProc
  189.  
  190.  
  191. ;----------------------
  192. ;Main Dialog
  193. ;----------------------
  194.  
  195. Main_DlgProc proc hwnd:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  196.  
  197.         push    ebx
  198.         push    esi
  199.         push    edi
  200.  
  201.         cmp        [wmsg],WM_SOCKET
  202.         je        socket_event
  203.         cmp     [wmsg],WM_COMMAND
  204.         je      main_command
  205.         cmp        [wmsg],WM_INITDIALOG
  206.         je        main_init
  207.         cmp     [wmsg], WM_CLOSE
  208.         je      main_dlgdestroy
  209.         mov     eax,FALSE
  210.  
  211. main_finish:
  212.         pop     edi
  213.         pop     esi
  214.         pop     ebx
  215.         ret
  216.  
  217. dlgconn:
  218.         push    L 0                     
  219.         push    offset Conn_DlgProc
  220.         push    [hwnd]
  221.         push    offset dlg_conn
  222.         push    [hInst]
  223.         call    DialogBoxParamA
  224.         jmp     main_finish
  225.  
  226. dlgabout:
  227.         push    L 0         
  228.         push    offset About_DlgProc      
  229.         push    [hwnd]
  230.         push    offset dlg_about
  231.         push    [hInst]
  232.         call    DialogBoxParamA
  233.         jmp        main_finish
  234.  
  235. socket_event:
  236.         mov        eax,lparam
  237.         cmp        ax,FD_CONNECT                    ;Do we have a FD_CONNECT msg?
  238.         jne        go_on                            ;If not, move on
  239.  
  240.         push    0
  241.         push    offset conntitle
  242.         push    offset conntext
  243.         push    [hwnd]
  244.         call    MessageBoxA
  245.  
  246.         push    offset Connection
  247.         push    IDD_STATUS
  248.         push    [hwnd]
  249.         call    SetDlgItemTextA
  250.         jmp        go_on
  251.  
  252. go_on:
  253.         mov        eax,lparam
  254.         cmp        ax,FD_READ                        ;Do we have a FD_READ msg?
  255.         jne        go_on2                            ;If not, move on
  256.  
  257.         push    0
  258.         push    256
  259.         push    offset ReadBuffer
  260.         push    [newsockdes]
  261.         call    recv                            ;Recieve the text
  262.         cmp     eax,-1                            ;If error, then move on
  263.         je        go_on2
  264.  
  265.         mov        ecx,eax                            ;Our MEGA COOL encryption algorightm :)
  266.         lea        edi,ReadBuffer
  267. XorLoop:                            
  268.         xor        byte ptr [edi],19
  269.         inc        edi
  270.         loop    XorLoop
  271.  
  272.         lea        edi,ReadBuffer
  273.         add        edi,eax
  274.         mov        byte ptr [edi],13                ;Add a line feed to the text
  275.         mov        byte ptr [edi+1],10
  276.  
  277.         push    offset ReadBuffer
  278.         push    0
  279.         push    EM_REPLACESEL
  280.         push    IDD_REMOTE
  281.         push    [hwnd]
  282.         call    SendDlgItemMessageA                ;Show the message in the "Chat Window"
  283.  
  284.         mov        al,0                            ;Clear the string
  285.         mov        ecx,256
  286.         lea        edi,ReadBuffer
  287.         rep        stosb
  288.  
  289.     go_on2:
  290.  
  291.         mov        eax,lparam
  292.         cmp        ax,FD_CLOSE                        ;Do we have a FD_CLOSE msg?
  293.         jne        go_on4                            ;If not, move on
  294.  
  295.         push    0                                ;Show "Server is down" message
  296.         push    offset ServDowntitle
  297.         push    offset ServDowntext
  298.         push    [hwnd]
  299.         call    MessageBoxA
  300.         jmp        main_dlgdestroy                    ;Exit the program
  301.  
  302.     go_on4:
  303.  
  304.         mov        eax,TRUE
  305.         jmp        main_finish
  306.  
  307. main_init:
  308.  
  309.         push    offset CrueStr
  310.         push    0
  311.         push    EM_REPLACESEL
  312.         push    IDD_REMOTE
  313.         push    [hwnd]
  314.         call    SendDlgItemMessageA                ;Send the welcome string to the "Chat Window"
  315.  
  316.         push    FD_CONNECT+FD_CLOSE+FD_READ        ;Choose what msg's to respond to
  317.         push    WM_SOCKET
  318.         push    [hwnd]
  319.         push    [sockdes]
  320.         call    WSAAsyncSelect
  321.  
  322.         push    0
  323.         push    256
  324.         push    EM_LIMITTEXT
  325.         push    IDD_YOU
  326.         push    [hwnd]
  327.         call    SendDlgItemMessageA                ;Limit the text in the "you" edit field
  328.  
  329.         push    offset NotConnected
  330.         push    IDD_STATUS
  331.         push    [hwnd]
  332.         call    SetDlgItemTextA
  333.  
  334.         mov        eax,TRUE
  335.         jmp        main_finish
  336.  
  337. main_command:
  338.  
  339.         cmp        [wparam],IDM_CONN
  340.         je        dlgconn
  341.         cmp        [wparam],IDM_ABOUT
  342.         je        dlgabout
  343.         cmp        [wparam],IDM_EXIT
  344.         je        main_dlgdestroy
  345.            cmp        [wparam],IDD_SEND
  346.         je        main_send
  347.         cmp     [wparam],IDD_EXIT
  348.         jne     main_nothing
  349.  
  350. main_dlgdestroy:
  351.  
  352.         push    [newsockdes]                    ;We must close all open sockets
  353.         call    closesocket
  354.  
  355.         push    [sockdes]                        ;We must close all open sockets
  356.         call    closesocket
  357.  
  358.         call    WSACleanup                        ;Let's clean up the mess we created :)
  359.  
  360.         push    L 0             
  361.         push    [hwnd]
  362.         call    EndDialog
  363.         mov     eax,TRUE        
  364.         jmp     main_finish
  365.  
  366. main_send:
  367.  
  368.         push    256
  369.         push    offset SendBuffer
  370.         push    IDD_YOU
  371.         push    [hwnd]
  372.         call    GetDlgItemTextA                    ;Get the string that we want to send
  373.         test    eax,eax                            ;Error?
  374.         je        ouch                            ;If so, exit
  375.  
  376.         push    eax                                ;Push away the length of the string (we'll need this later)
  377.  
  378.         lea        edi,SendBuffer                    ;Offset of the message in EDI
  379.         add        edi,eax                            ;Add the length of the string to EDI, thus making it point to the end of the string.
  380.         mov        byte ptr [edi],13                ;We must add a LineFeed to it
  381.         mov        byte ptr [edi+1],10
  382.         
  383.         sub        edi,eax                            ;Now edi points at the begin of the string again-
  384.  
  385.         push    edi
  386.         push    0
  387.         push    EM_REPLACESEL
  388.         push    IDD_REMOTE
  389.         push    [hwnd]
  390.         call    SendDlgItemMessageA                ;Write the text to the "Chat window"
  391.  
  392.         pop        eax                                ;Eax = Length of string
  393.  
  394.         push    0
  395.         push    eax
  396.         push    edi
  397.         push    [newsockdes]
  398.         call    send                            ;Send the msg to the server
  399.         cmp        eax,-1                            ;If eax=-1 then we have an error
  400.         jne        MessageSent
  401.  
  402.         push    -1
  403.         call    MessageBeep                        ;Apperently we didnt send the message, let's beep!
  404.  
  405. MessageSent:
  406.         mov        al,0
  407.         mov        ecx,256
  408.         lea        edi,SendBuffer
  409.         rep        stosb                            ;Clear the SendBuffer string
  410.  
  411.         push    offset SendBuffer                ;Remove what we just wrote from the "You" edit field
  412.         push    IDD_YOU
  413.         push    [hwnd]
  414.         call    SetDlgItemTextA
  415.  
  416. ouch:
  417.  
  418.         mov        eax,TRUE
  419.         jmp        main_finish
  420.  
  421. main_nothing:
  422.         mov     eax,FALSE
  423.         jmp     main_finish
  424.  
  425. Main_DlgProc    endp
  426. public Main_DlgProc
  427.  
  428. Conn_DlgProc proc hwnd2:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  429.  
  430.         push    ebx
  431.         push    esi
  432.         push    edi
  433.  
  434.         cmp     [wmsg],WM_COMMAND
  435.         je      conn_command
  436.         cmp     [wmsg], WM_CLOSE
  437.         je      conn_dlgdestroy
  438.         mov     eax,FALSE
  439.  
  440. conn_finish:
  441.  
  442.         pop     edi
  443.         pop     esi
  444.         pop     ebx
  445.  
  446.         ret
  447.  
  448. conn_command:
  449.       
  450.         cmp        [wparam],IDD_CONNECT
  451.         je      conn_connect
  452.         cmp        [wparam],IDD_CANCEL
  453.         je        conn_dlgdestroy
  454.         cmp     [wparam],IDD_EXIT
  455.         jne     conn_nothing
  456.  
  457. conn_dlgdestroy:
  458.  
  459.         push    L 0             
  460.         push    [hwnd2]
  461.         call    EndDialog
  462.         mov     eax,TRUE        
  463.         jmp     conn_finish
  464.  
  465. conn_connect:
  466.  
  467.         push    16                                ;Get the IP
  468.         push    offset TheIP
  469.         push    IDD_IPEDIT
  470.         push    [hwnd2]
  471.         call    GetDlgItemTextA                    
  472.  
  473.         push    offset TheIP                    ;Conver the IP
  474.         call    inet_addr
  475.         mov     sin.sin_addr,eax 
  476.  
  477.         push    16                                ;Try to connect
  478.         push    offset sin
  479.         push    [sockdes]
  480.         call    connect
  481.  
  482.         mov        eax,[sockdes]                    
  483.         mov        newsockdes,eax
  484.         jmp        conn_dlgdestroy
  485.  
  486. conn_nothing:
  487.         mov     eax,FALSE
  488.         jmp     conn_finish
  489.  
  490. Conn_DlgProc    endp
  491. public Conn_DlgProc
  492.  
  493. About_DlgProc proc hwnd3:DWORD, wmsg:DWORD, wparam:DWORD, lparam:DWORD
  494.  
  495.         push    ebx
  496.         push    esi
  497.         push    edi
  498.  
  499.         cmp     [wmsg],WM_COMMAND
  500.         je      about_command
  501.         cmp     [wmsg],WM_CLOSE
  502.         je      about_dlgdestroy
  503.         mov     eax,FALSE
  504.  
  505. about_finish:
  506.         pop     edi
  507.         pop     esi
  508.         pop     ebx
  509.         ret
  510.  
  511. about_command:
  512.       
  513.         cmp        [wparam],IDD_ABOUTOK
  514.         je      about_dlgdestroy
  515.         cmp     [wparam],IDD_EXIT
  516.         jne     about_nothing
  517.  
  518. about_dlgdestroy:
  519.  
  520.         push    L 0             
  521.         push    [hwnd3]
  522.         call    EndDialog
  523.         mov     eax,TRUE        
  524.         jmp     about_finish
  525.  
  526. about_nothing:
  527.         mov     eax,FALSE
  528.         jmp     about_finish
  529.  
  530. About_DlgProc    endp
  531. public About_DlgProc
  532. end start
  533.