.386
.model flat,stdcall
option casemap:none
WinMain proto :DWORD,:DWORD,:DWORD,:DWORD
include E:\masm32\include\windows.inc
include E:\masm32\include\kernel32.inc
include E:\masm32\include\user32.inc
include E:\masm32\include\advapi32.inc
include E:\masm32\include\gdi32.inc
include E:\masm32\include\ws2_32.inc
includelib E:\masm32\lib\kernel32.lib
includelib E:\masm32\lib\user32.lib
includelib E:\masm32\lib\advapi32.lib
includelib E:\masm32\lib\gdi32.lib
includelib E:\masm32\lib\ws2_32.lib
include E:\masm32\macros\Strings.mac
IN_ADDR struct
s_addr dd ?
IN_ADDR ends
SOCKADDR_IN struct
sin_family dw ?
sin_port dw ?
sin_addr IN_ADDR <?>
sin_zero db 8h dup(?)
SOCKADDR_IN ends
HOSTENT struct
h_name dd ?
h_aliases dd ?
h_addrtype dw ?
h_length dw ?
h_addr dd ?
HOSTENT ends
.DATA
ClassName db "SimpleWinClass",0
AppName db "Our First Window",0
OurText db "Win32 assembly is great and easy!",0
.DATA?
hInstance HINSTANCE ?
CommandLine LPSTR ?
.CODE
start:
invoke GetModuleHandle, NULL
mov hInstance,eax
invoke GetCommandLine
mov CommandLine,eax
invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax
WinMain proc hInst:HINSTANCE, hPrevInst:HINSTANCE, CmdLine:LPSTR,
CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND
mov wc.cbSize,SIZEOF WNDCLASSEX
mov wc.style, CS_HREDRAW or CS_VREDRAW
mov wc.lpfnWndProc, OFFSET WndProc
mov wc.cbClsExtra,NULL
mov wc.cbWndExtra,NULL
push hInst
pop wc.hInstance
mov wc.hbrBackground,COLOR_WINDOW+1
mov wc.lpszMenuName,NULL
mov wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov wc.hIcon,eax
mov wc.hIconSm,eax
invoke LoadCursor,NULL,IDC_ARROW
mov wc.hCursor,eax
invoke RegisterClassEx, addr wc
invoke CreateWindowEx,NULL,ADDR ClassName,ADDR AppName,\
WS_OVERLAPPEDWINDOW,CW_USEDEFAULT,\
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,NULL,NULL,\
hInst,NULL
mov hwnd,eax
invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd
;invoke CreateThread,0h,0h,offset Some,0h,0h,offset ThreadId
.WHILE TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .IF (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.ENDW
mov eax,msg.wParam
ret
WinMain endp
.data?
controls dd 100h dup(?)
wsadata WSADATA <>
.code
encodeBase64 proc
xor esi,esi ; encodeBase64 by Bumblebee. All rights reserved ;)
call over_enc_table
db "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
db "abcdefghijklmnopqrstuvwxyz"
db "0123456789+/"
over_enc_table:
pop edi
push ebp
xor ebp,ebp
baseLoop:
movzx ebx,byte ptr [eax]
shr bl,2
and bl,00111111b
mov bh,byte ptr [edi+ebx]
mov byte ptr [edx+esi],bh
inc esi
mov bx,word ptr [eax]
xchg bl,bh
shr bx,4
mov bh,0
and bl,00111111b
mov bh,byte ptr [edi+ebx]
mov byte ptr [edx+esi],bh
inc esi
inc eax
mov bx,word ptr [eax]
xchg bl,bh
shr bx,6
xor bh,bh
and bl,00111111b
mov bh,byte ptr [edi+ebx]
mov byte ptr [edx+esi],bh
inc esi
inc eax
xor ebx,ebx
movzx ebx,byte ptr [eax]
and bl,00111111b
mov bh,byte ptr [edi+ebx]
mov byte ptr [edx+esi],bh
inc esi
inc eax
inc ebp
cmp ebp,24
jna DontAddEndOfLine
xor ebp,ebp ; Добавляем новую линию
mov word ptr [edx+esi],0A0Dh
inc esi
inc esi
test al,00h ; Оптимизиpовано
org $-1
DontAddEndOfLine:
inc ebp
sub ecx,3
or ecx,ecx
jne baseLoop
mov ecx,esi
add edx,esi
pop ebp
ret
encodeBase64 endp
myconnect PROTO :DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD,:DWORD
.data
helo_mes db "HELO",0h
mail_from db "MAIL FROM:<",0h
rcpt_mes db "RCPT TO:<",0h
datames db "DATA",0Dh,0Ah,0h
subj_mes db "SUBJECT: ",0h
;text_def db 'Content-type: text/plain; boundary="simple boundary"',0Dh,0Ah,0Dh,0Ah,0h
my_message db "Hello World!!!",0Dh,0Ah,0Dh,0Ah,".",0Dh,0Ah,0h
quit_mes db "QUIT",0Dh,0Ah,0h
.code
recvy PROTO :DWORD,:DWORD
recvy proc memheap:DWORD,s:DWORD
mov eax,memheap
add eax,1000h
push eax
invoke lstrlen,eax
pop edx
add eax,edx
invoke recv,s,eax,100h,0h
ret
recvy endp
clear PROTO :DWORD
clear proc memheap:DWORD
mov edi,memheap
mov ecx,200h
xor eax,eax
rep stosb
ret
clear endp
myconnect proc hWnd,hMemo,hEdit,hEdit2,hEdit3,hEdit4,hMemo2
LOCAL s:SOCKET
LOCAL memheap:DWORD
LOCAL procheap:DWORD
LOCAL sin:SOCKADDR_IN
LOCAL memory:DWORD
LOCAL bytes:DWORD
LOCAL handle:DWORD
LOCAL file_buffer:DWORD
LOCAL coding_data_size:DWORD
;jmp endy
invoke GetProcessHeap
mov procheap,eax
invoke HeapAlloc,eax,HEAP_ZERO_MEMORY,4000h
mov memheap,eax
invoke WSAStartup,101h,offset wsadata
invoke socket,AF_INET,SOCK_STREAM,0h
mov s,eax
mov eax,memheap
add eax,5h
invoke SendMessage,hEdit,WM_GETTEXT,50h,eax
mov eax,memheap
add eax,5h
invoke gethostbyname,eax
assume eax:ptr HOSTENT
mov eax,[eax].h_addr
assume eax:nothing
mov eax,[eax]
mov eax,[eax]
MOV sin.sin_addr.s_addr,eax
MOV sin.sin_port,1900h
MOV sin.sin_family,AF_INET
invoke connect,s,addr sin,sizeof(sockaddr_in)
;xor eax,eax
.if eax==0h
mov eax,memheap
add eax,1000h
invoke recv,s,eax,100h,0h
invoke lstrcpy,memheap,offset helo_mes
add eax,sizeof helo_mes-1h
mov byte ptr [eax],20h
inc eax
push eax
invoke SendMessage,hEdit,WM_GETTEXT,50h,eax
pop edx
mov dword ptr [eax][edx],0A0Dh
invoke lstrlen,memheap
invoke send,s,memheap,eax,0h
mov eax,memheap
add eax,1000h
invoke recv,s,eax,100h,0h
invoke clear,memheap
invoke lstrcpy,memheap,offset mail_from
add eax,sizeof mail_from-1h
push eax
invoke SendMessage,hEdit2,WM_GETTEXT,50h,eax
pop edx
mov dword ptr [eax][edx],'>' or 0A0D00h
add eax,3h
invoke lstrlen,memheap
invoke send,s,memheap,eax,0h
invoke recvy,memheap,s
invoke clear,memheap
invoke lstrcpy,memheap,offset rcpt_mes
add eax,sizeof rcpt_mes-1h
push eax
invoke SendMessage,hEdit3,WM_GETTEXT,50h,eax
pop edx
mov dword ptr [eax][edx],'>' or 0A0D00h
add eax,3h
invoke lstrlen,memheap
invoke send,s,memheap,eax,0h
mov eax,memheap
add eax,1000h
push eax
invoke lstrlen,eax
pop edx
add eax,edx
invoke recv,s,eax,100h,0h
invoke clear,memheap
invoke lstrcpy,memheap,offset datames
mov eax,sizeof datames-1h
invoke send,s,memheap,eax,0h
invoke recvy,memheap,s
invoke clear,memheap
invoke VirtualAlloc,0h,100000h,MEM_COMMIT,PAGE_READWRITE
mov memory,eax
invoke lstrcpy,memory,offset subj_mes
add eax,sizeof subj_mes-1h
push eax
invoke SendMessage,hEdit4,WM_GETTEXT,50h,eax
pop edx
mov word ptr [eax][edx],0A0Dh
add eax,2h
add eax,edx
;invoke SendMessage,hMemo2,WM_GETTEXT,400h,eax
.data
CrLf equ 0Dh,0Ah
Send_data db 'MIME-Version: 1.0',CrLf
db 'Content-Type: application/octet-stream; name="file.txt"',CrLf
db 'Content-Disposition: attachment; filename="file.txt"',CrLf
db 'Content-Transfer-Encoding: base64',CrLf
;db 30,80h,40h,20h,30h,22h,50h,40h,CrLf,0
.code
invoke lstrcpy,eax,offset Send_data
invoke CreateFile,$CTA0("file.txt"),GENERIC_READ ,0h,0h,OPEN_EXISTING,0h,0h
mov handle,eax
invoke GetFileSize,eax,0h
mov coding_data_size,eax
invoke HeapAlloc,procheap,HEAP_ZERO_MEMORY,eax
mov file_buffer,eax
invoke ReadFile,handle,file_buffer,coding_data_size,addr bytes,0h
invoke CloseHandle,handle
invoke lstrlen,memory
mov edx,eax
add edx,memory
mov eax,file_buffer
mov ecx,coding_data_size
call encodeBase64
invoke HeapFree,procheap,0h,file_buffer
comment @
invoke lstrlen,memory
mov edx,memory
mov word ptr [eax][edx],0A0Dh
add eax,2h
mov word ptr [eax][edx],0A0Dh
add eax,2h
add eax,memory
invoke lstrcpy,eax,offset MyFile
invoke lstrlen,memory
mov edx,eax
add edx,memory
mov eax,offset coding_data
mov ecx,sizeof coding_data
call encodeBase64
invoke lstrlen,memory
add eax,memory
invoke lstrcpy,eax,offset end_of_File
@
invoke lstrlen,memory
mov edx,memory
mov dword ptr [eax][edx],0A0Dh
inc eax
inc eax
mov dword ptr [eax][edx],2E0A0Dh
add eax,3h
mov dword ptr [eax][edx],0A0Dh
inc eax
inc eax
invoke lstrlen,memory
invoke send,s,memory,eax,0h
invoke VirtualFree,memory,100000h,MEM_DECOMMIT
invoke recvy,memheap,s
invoke clear,memheap
invoke lstrcpy,memheap,offset quit_mes
mov eax,sizeof quit_mes-1h
invoke send,s,memheap,eax,0h
mov eax,memheap
add eax,1000h
push eax
push eax
invoke lstrlen,eax
pop edx
add eax,edx
invoke recv,s,eax,100h,0h
add edx,eax
pop eax
invoke SendMessage,hMemo,WM_SETTEXT,edx,eax
.endif
invoke closesocket,s
invoke WSACleanup
invoke HeapFree,procheap,0h,memheap
endy:
ret
myconnect endp
end start
SMTP и WinAPI
До недавнего времени ничего не соображал по работе с инетом, но разобраться нужно.
потом соединяешься с smtp-сервером, по 25 порту, через обычный сокет. считываешь/записываешь из сокета данные.
например. подключаешься к smtp.mail.ru
он тебе говорит:
220 mail.ru ESMTP Sun, 23 Dec 2007 12:48:28 +0300
а ты ему:
EHLO server
а он тебе:
250-mx33.mail.ru Hello server [217.118.81.36]
250-SIZE 31457280
250-8BITMIME
250-AUTH PLAIN LOGIN
250 PIPELINING
а ты ему:
AUTH LOGIN
а он тебе:
334 буковки_в_base64
а ты ему:
свой_логин_кодированный_в_base64
а он тебе:
334 буковки_в_base64
а ты ему:
свой_пароль_кодированный_в_base64
а он тебе:
235 Authentication succeeded
а ты ему:
MAIL FROM:<твоя_почта@mail.ru>
а он тебе:
250 OK
а ты ему:
RCPT TO:<чужая_почта@mail.ru>
а он тебе:
250 Accepted
а ты ему:
DATA
Subject: TEST
а он тебе:
354 Enter message, ending with "." on a line by itself
а ты ему:
Всё пройдет, пройдет и это. :-)
.
а он тебе:
250 OK id=буковки_и_циферки
тогда ты ему:
QUIT
а он тебе скажет "пока"
221 mx33.mail.ru closing connection
примерно так :-D
Код:
WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
CONTSTR STRUCT
button dd ?
edit dd ?
edit2 dd ?
edit3 dd ?
edit4 dd ?
memo dd ?
memo2 dd ?
CONTSTR ENDS
mov esi,offset controls
assume esi:ptr CONTSTR
.if uMsg==WM_CREATE
invoke CreateWindowEx,0h,$CTA0("BUTTON"),$CTA0("Send"),WS_VISIBLE or WS_CHILD or BS_DEFPUSHBUTTON,160,20,80,20,hWnd,0,hInstance,0
mov [esi].button,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("www.yandex.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,270,50,200,20,hWnd,0,hInstance,0
;invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("User-91396ed1f7"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,270,50,200,20,hWnd,0,hInstance,0
mov [esi].edit,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("xxx@rambler.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,50,200,20,hWnd,0,hInstance,0
mov [esi].edit2,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("xxx@rambler.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,80,200,20,hWnd,0,hInstance,0
mov [esi].edit3,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("Hello"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,110,200,20,hWnd,0,hInstance,0
mov [esi].edit4,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0(""),WS_VISIBLE or WS_CHILD or WS_BORDER or WS_VSCROLL or ES_MULTILINE,10,50,250,250,hWnd,0,hInstance,0
mov [esi].memo,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("Hello "),WS_VISIBLE or WS_CHILD or WS_BORDER or WS_VSCROLL or ES_MULTILINE,270,80,200,220,hWnd,0,hInstance,0
mov [esi].memo2,eax
;invoke SendMessage,hWnd,WM_PAINT,0h,0h
.endif
.if uMsg==WM_COMMAND
mov eax,dword ptr [esi].button
.if lParam==eax
invoke myconnect,hWnd,[esi].memo,[esi].edit,[esi].edit2,[esi].edit3,[esi].edit4,[esi].memo2
.endif
.endif
.if uMsg==WM_PAINT
.endif
assume esi:nothing
.if uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
; xor eax, eax
.endif
ret
WndProc endp
CONTSTR STRUCT
button dd ?
edit dd ?
edit2 dd ?
edit3 dd ?
edit4 dd ?
memo dd ?
memo2 dd ?
CONTSTR ENDS
mov esi,offset controls
assume esi:ptr CONTSTR
.if uMsg==WM_CREATE
invoke CreateWindowEx,0h,$CTA0("BUTTON"),$CTA0("Send"),WS_VISIBLE or WS_CHILD or BS_DEFPUSHBUTTON,160,20,80,20,hWnd,0,hInstance,0
mov [esi].button,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("www.yandex.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,270,50,200,20,hWnd,0,hInstance,0
;invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("User-91396ed1f7"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,270,50,200,20,hWnd,0,hInstance,0
mov [esi].edit,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("xxx@rambler.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,50,200,20,hWnd,0,hInstance,0
mov [esi].edit2,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("xxx@rambler.ru"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,80,200,20,hWnd,0,hInstance,0
mov [esi].edit3,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("Hello"),WS_VISIBLE or WS_CHILD or WS_BORDER or ES_AUTOHSCROLL,490,110,200,20,hWnd,0,hInstance,0
mov [esi].edit4,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0(""),WS_VISIBLE or WS_CHILD or WS_BORDER or WS_VSCROLL or ES_MULTILINE,10,50,250,250,hWnd,0,hInstance,0
mov [esi].memo,eax
invoke CreateWindowEx,0h,$CTA0("EDIT"),$CTA0("Hello "),WS_VISIBLE or WS_CHILD or WS_BORDER or WS_VSCROLL or ES_MULTILINE,270,80,200,220,hWnd,0,hInstance,0
mov [esi].memo2,eax
;invoke SendMessage,hWnd,WM_PAINT,0h,0h
.endif
.if uMsg==WM_COMMAND
mov eax,dword ptr [esi].button
.if lParam==eax
invoke myconnect,hWnd,[esi].memo,[esi].edit,[esi].edit2,[esi].edit3,[esi].edit4,[esi].memo2
.endif
.endif
.if uMsg==WM_PAINT
.endif
assume esi:nothing
.if uMsg==WM_DESTROY
invoke PostQuitMessage,NULL
.else
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
; xor eax, eax
.endif
ret
WndProc endp
Только мааааленькая проблемка - моя работа и подготовка к сессии... Автоматы усиленно получаю. Еще раз спасибо, зайду ближе к выходным, разберусь и отпишусь.
Цитата: ШпиЁн
а он тебе:
334 буковки_в_base64
а ты ему:
свой_логин_кодированный_в_base64
а он тебе:
334 буковки_в_base64
буковки_в_base64 = это в первом случае закодированное слово Login, а во втором - Password