I'm french so excuse me for my English.

I would like to post a mail under asm, but my code don't work.
- First : my PROC produce a bug when it arrives at the RET instruction and I don't know why...
- Second : my PROC returns me every time good messages. It founds the host, the connection is successful, I can send data (I belive, because not fault occur). But the problem is that I never recive the mail in my box (in my mail).

Piece of information :
www.multimania.com serves to have some mails like 'Nikename@multimania.com' so the host under SMTP is smtp.multimania.com, isn't it? (I think?)

I'll put a piece of my code, so will someone could help me please ?




.data
AppName db "AppName",0
ClassName db "ClassName",0
;hostname db "www.wanadoo.fr",0
hostname db "smtp.wanadoo.fr",0
; wanadoo is my 'internet acces supplier'
response dd 0

outmsg1 DB 'HELO' ;,0dh,0ah,0
outmsg2 DB 'MAIL FROM: <moimeme@wanadoo.fr>' ;,0dh,0ah,0
outmsg3 DB 'RCPT TO: <Morgatte@citeweb.net>' ;,0dh,0ah,0
outmsg4 DB 'DATA' ;,0dh,0ah,0
smtp_dataBuff DB 'Voici le contenu du message.',0Dh,0Ah
DB '.',0Dh,0Ah,0
outmsg5 DB 'QUIT' ;,0dh,0ah,0

; HELO <SP> <domain> <CRLF> ; under telnet smtp
; MAIL <SP> FROM:<reverse-path> <CRLF> ; works like that
; RCPT <SP> TO:<forward-path> <CRLF>
; DATA Le texte sur 1,2,3... lignes<CRLF>.<CRLF>
; QUIT <CRLF>

.data?
hwnd HANDLE ?
hSock HANDLE ?
SocketAddress sockaddr_in <?>
wsdat_ WSADATA <>

.const
WM_SOCKET equ WM_USER+100
SMTP_PORT EQU 25 ;


.code
.....
...
..
.
;################################### SOCKET ####################################################
Socksodise proc

INVOKE WSAStartup, 101h,addr wsdat_ ; initialize Winsock Library
.IF eax != 0
FATAL "Impossible d'initialiser la DLL Winsock"
.ENDIF


INVOKE socket, AF_INET,SOCK_STREAM, 0 ; kind of Socket
.IF eax == -1
SOCK_MSG "H?te introuvable! (Socket)"
RET
.ENDIF
mov hSock,eax


INVOKE gethostbyname, addr hostname ; address of SMTP server
.if eax == 0
SOCK_MSG "H?te introuvable! (GetHostByName)"
INVOKE closesocket, hSock
RET
.endif

mov eax,dword ptr
mov eax,dword ptr
mov eax,dword ptr
mov SocketAddress.sin_addr,eax

mov SocketAddress.sin_family,AF_INET
INVOKE htons, SMTP_PORT ; SMTP_PORT = 25
mov SocketAddress.sin_port,ax








INVOKE connect, hSock, addr SocketAddress, sizeof SocketAddress
;--------- CONNECT ------
.IF eax==SOCKET_ERROR
SOCK_MSG "Impossible de se connecter ? l'h?te!"
INVOKE closesocket, hSock
RET
.ENDIF

INVOKE recv, hSock, offset response, 4, 0 ; With response dd 0
.IF eax==0
INVOKE closesocket, hSock ; it doesn't work
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (CONNEXION -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s CONNECT correcte" ; it Works
.ENDIF ; Connection is OK






;SEND HELO ---------- HELO -------
INVOKE lstrlen, addr outmsg1
INVOKE send, hSock,addr outmsg1, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE HELO)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock ; it doesn't work
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET (HELO -> recv)!" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s SEND HELO correcte" ; it works
.ENDIF ; Sending HELO is OK







;SEND MAIL FROM: ------- MAIL FROM -----
INVOKE lstrlen, addr outmsg2
INVOKE send, hSock,addr outmsg2, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE MAIL)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock ; it doesn't work
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (MAIL -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s SEND MAIL FROM: correcte" ; it works
.ENDIF ; Sending MAIL FROM: is OK








;SEND RCPT TO: --------- RCPT TO ------
INVOKE lstrlen, addr outmsg3
INVOKE send, hSock,addr outmsg3, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE RCPT TO)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock ; it doesn't work
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (RCPT TO -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s RCPT TO: correcte" ; it works
.ENDIF ; Sending RCPT TO: is OK








;SEND DATA ---------- DATA --------
INVOKE lstrlen, addr outmsg4
INVOKE send, hSock,addr outmsg4, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE DATA)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock ; it doesn't work
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (DATA -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s DATA correcte" ; it works
.ENDIF ; Sending DATA is OK










;SEND TEXT ------ LE MESSAGE ------
INVOKE lstrlen, smtp_dataBuff
INVOKE send, hSock,smtp_dataBuff, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE TEXT)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (TEXT -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s SEND TEXT correcte" ; it works
.ENDIF ; Sending THE CONTENT OF
; THE MESSAGE is OK








;SEND QUIT ------ QUIT ------
INVOKE lstrlen, outmsg5
INVOKE send, hSock,outmsg5, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE QUIT)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF


INVOKE recv, hSock, offset response, 4, 0 ; read bytes from incoming
.IF eax==0
INVOKE closesocket, hSock
RET
.ELSEIF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (outmsg5 -> recv)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ELSEIF eax==4
SOCK_MSG "Reception apr?s SEND QUIT correcte" ; it works
.ENDIF ; Sending QUIT is OK





INVOKE closesocket, hSock
INVOKE WSACleanup
ret ; <----------------------------------------------- here I have a bug
Socksodise endp
;#################################### SOCKET ###################################################

Thanks:confused:
Posted on 2001-12-10 17:28:14 by Morgatte
What do you mean exactly with 'bug'? Does your program crash? Does any error occur?
Also, you shoudn't comment the 0Dh,0Ah,0 in these strings:


outmsg1 DB 'HELO'[b];[/b],0dh,0ah,0
outmsg2 DB 'MAIL FROM: <moimeme@wanadoo.fr>' [b];[/b],0dh,0ah,0
outmsg3 DB 'RCPT TO: <Morgatte@citeweb.net>' [b];[/b],0dh,0ah,0
.... and so on...

Remove these semi-collons, you need the CRLF and null terminator.

Then another thing is that you use this to receive the response:


INVOKE recv, hSock, offset response, 4, 0 ; With response dd 0


However you assume the length of the response is always 4. But this isn't correct. There can be a response of any length:


503[cr][lf] (5 bytes)
503 5.5.1 Waiting for HELO/EHLO command[cr][lf] (41 bytes)

You always just receive 4 bytes so you don't retrieve the full response.

Thomas
Posted on 2001-12-11 14:07:43 by Thomas
Bonjour Morgatte,
Je n'ai pas lu ton code mais j'esp?re que cet attachement t'aidera.
Il faut juste que tu remplaces "xxxx@aaa.com" par ton mail et que tu places un fichier BRSKLOG.BAK ( avec les donn?es que tu veux envoyer) dans le repertoire syst?me de windows.

PS : Si tu utilises une proc?dure de fen?tre met ce code dans une thread sinon le prog ne fonctionnera pas...


Amicalement

Axial
Posted on 2001-12-12 01:48:11 by Axial
Thank you Thomas I have a doubt about The 4 bytes of 'recv' and and other about <CRLF>.


The Ret instruction occur an exception violation memory (Read), so I have think I could put a SEH But I prefer understand why this Exception occurs.



Axial
Merci beaucoup pour ton fichier. J'esp?re qu'il n'est pas trop gros pour que je puisse le d?cortiquer sans trop de probl?mes.


@+
Posted on 2001-12-12 04:09:20 by Morgatte

;SEND QUIT ------ QUIT ------
INVOKE lstrlen, outmsg5
INVOKE send, hSock,outmsg5, eax, NULL
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE QUIT)" ; it doesn't work
INVOKE closesocket, hSock


R?essaye avec "Addr outmsg5", normalement ?a devrait marcher apres ?a.
A+

Axial
Posted on 2001-12-12 05:01:40 by Axial
as a standard, you may want to add protocol handling to check for errors that may occur between sessions, mainly.
refer to the smtp rfc to see the meaning of the various codes generated by an smtp server.

clip
Posted on 2001-12-12 06:50:28 by clip
Thanks for all, It works now. :alright:


Axial
Merci beaucoup pour ton fichier, il m'a beaucoup aid?.
Mais il doit y avoir une petite erreur, ici:

invoke send, Sock, addr cmd2,cmd4Size,0

cmd4 = 'QUIT' et au moment de le pass? on redonne cmd2 ? la place.

Une autre chose: a un moment il y a une recherche dans le registre pour trouver le client install? sur l'ordinateur:

Moi ce r?pertoire, il n'existe pas.
szAccount DB 'Software\Microsoft\Internet Account Manager\Accounts\',0
Donc il ne trouve rien.

Mais pas de probl?me maintenant tout marche bien




:alright: :alright:
Posted on 2001-12-12 11:20:28 by Morgatte
invoke send, Sock, addr cmd2,cmd4Size,0


Oui, je me souviens je n'avais pas corrig? cette erreur dans cette version...


Moi ce r?pertoire, il n'existe pas.
szAccount DB 'Software\Microsoft\Internet Account Manager\Accounts\',0


Curieux cette erreur, tu tournes sous Windows NT ???
Posted on 2001-12-13 01:19:05 by Axial
No, only under Win95
Posted on 2001-12-13 04:35:24 by Morgatte
Morgatte - Glad you got your program working. I was trying to follow this thread, but French is not my language...so I was wondering how you fixed your code to make it work?
Posted on 2001-12-13 06:41:32 by gscundiff
I know it's easier to speak (write) French for French people, but I think we should write using English language.
Then people wouldn't have so many problems with understanding even though we make mistakes (maybe a lot !).


Hi Morgatte, (we are a lot of French people here !!!),

I don't think that you can send mail with smtp.multimania.com, because it is not a ISP. You know, my site is hosted at multimania and when you create your email address, you can just receive mail under Outlook or other (via pop), but you can't send mail with multimania, on their site, they say you must use your ISP smtp address. (like me under wanadoo.fr so it is smtp.wanadoo.fr)

You know, I've seen something very strange:
I can send mails via smtp.wanadoo.fr, without putting a real username and real password, so I can send someone mails with microsoft@bob.fr for example. It works and no password is recquired. But when I insert an attachment, then the mail can't be sent.
I think it's a security hole, because it is really hallucinating, isn't it ?
Posted on 2001-12-13 06:44:15 by Vom-bonjour:-()
Yet another french there !!! :)

("Vive la France ! Vive la France ! Le Schedar pue !" like says the IBM ad). :)

Now, let's stop bad jokes and the not-so-serious patriotism. :)

Vom, i have seen the same "security hole" in wanadoo (french isp in case the others people are wondering), with their news server... but the problem has been fixed few weeks ago.
At home, I use Club-Internet, and without good login and pass and an active Club-Internet connexion, it's impossible to send or receive mail via their servers...

But anyway, perhaps Wanadoo considers this as a feature ? and for most of us, it is ;)
Posted on 2001-12-13 07:29:46 by JCP
it's not a security hole, the smtp server just allows 'relaying' of mails to anyone, in sendmail, previous versions allow relaying as default (btw, using smtp doesn't require you a password for any sort of authentication).. you know back then, most admins didn't bother to set their smtp servers to deny relaying until abusive people started using them to spoof mail and to mail bomb. now, i think it's in an admin's check list to deny relaying when setting up an smtp server (well, some of them forget, like the sysads in my school :)).


clip
Posted on 2001-12-13 09:45:14 by clip
Okay I'll speak english :grin:

Hi others, am I the only one or do you have this path ?

HKEY_CURRENT_USER\Software\Microsoft\Internet Account Manager\Accounts\ [\QUOTE]
Posted on 2001-12-13 10:46:19 by Axial
Axial,

I don't have this key on any of my Win9x machines.

farrier
Posted on 2001-12-13 13:35:25 by farrier
Thanks Farrier,

I just forgot this prog assumes you have M$-OUTLOOK installed and configured...

:stupid:
Posted on 2001-12-14 01:34:56 by Axial
AXIAL,

I haven't got this patch.
But at HKEY_CURRENT_USER\RemoteAccess I can found
Default=Wanadoo <-- My FAI (ISP = FAI ???)
InternetProfile=Wanadoo

So I made a loop to obtain first smtp.wanadoo.com and if it does not work it give me smtp.wanadoo.fr

Now it Works.




Von - bonjour,
Yes that's right Multimania isn't a ISP. So That can't work.



gscundiff, ;)
I have got two codes.

First is a very basic snipet code, only to understand...


.386
.model flat,stdcall
option casemap:none


include \MASM32\INCLUDE\windows.inc


include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\wsock32.inc

includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\Wsock32.lib




recvlp proto


.data

hostname db "smtp.wanadoo.fr",0 ; my ISP

HELO DB 'HELO smtp.wanadoo.fr', 0dh, 0ah, 0
MAIL DB 'MAIL FROM: <mailanonyme@free.fr>', 0dh, 0ah, 0
RCPT DB 'RCPT TO: <Morgatte@multimania.com>', 0dh, 0ah, 0 ; my mail
DATA DB 'DATA',0dh,0ah,0
smtp_dataBuff DB 'Voici le contenu du message...', 0dh, 0ah
DB 'qui peut ?tre sur plusieurs lignes.', 0dh, 0ah,'.', 0dh, 0ah, 0
QUIT DB 'QUIT', 0dh, 0ah, 0


.data?
hSock HANDLE ?
SocketAddress sockaddr_in <?>
ws_data WSADATA <>
recvbuf dd ?
BBB db ?



.const
SMTP_PORT EQU 25 ; port 25 = smtp


.code
;----------------------- Proc?dure attente de r?ponse --------------------
recvlp proc ; tanks to AXIAL for this proc
invoke recv,hSock, addr recvbuf, 4,0
cmp eax,4 ;On a re?u un dword ?
jnz qut

@@:
invoke recv,hSock,addr BBB,1,0
cmp eax,1 ;On a re?u un octes ?
jne @B
cmp byte ptr ,0ah ;Est-ce 0ah
jne @B
;Oui? cela signifie que le serveur a fini de r?pondre
@@:
qut:
mov eax,dword ptr ;Valeur de retour dans eax
ret
recvlp endp
;--------------------------------------------------------------------------

start:
;################################### SOCKET ####################################################


INVOKE WSAStartup, 101h, addr ws_data ; initialise la librairie Winsock
.IF eax != 0
; mettre le message "Impossible d'initialiser la DLL Winsock"
.ENDIF


INVOKE socket, AF_INET, SOCK_STREAM, 0 ; type de Socket
mov hSock,eax
.IF eax == -1
; mettre le message "H?te introuvable! (Socket)"
.ENDIF



INVOKE gethostbyname, addr hostname ; nom du serveur SMTP
.if eax == 0
; Mettre le message "H?te introuvable! (GetHostByName)"
.endif

mov eax,dword ptr ; eax re?oit la valeur du membre h_list (voir la structure "hostent")
mov eax,dword ptr ; copie le pointer sur l'actuel adresse IP dans eax
mov eax,dword ptr ; copie l'adresse IP dans eax (voir la structure "hostent")
mov SocketAddress.sin_addr,eax

mov SocketAddress.sin_family,AF_INET
INVOKE htons, SMTP_PORT ; SMTP_PORT = 25
mov SocketAddress.sin_port,ax



; --------- CONNECT ------

INVOKE connect, hSock, addr SocketAddress, sizeof SocketAddress
INVOKE recvlp
cmp eax, ' 022' ; le message 220 est retourn? si correcte
jne abandon


; ---------- HELO -------

INVOKE lstrlen, addr HELO
INVOKE send, hSock, addr HELO, eax, NULL
INVOKE recvlp
cmp eax, ' 052' ; le message 250 est retourn? si correcte
jne abandon


; ------- MAIL FROM -----

INVOKE lstrlen, addr MAIL
INVOKE send, hSock, addr MAIL, eax, NULL
INVOKE recvlp
cmp eax, ' 052' ; le message 250 est retourn? si correcte
jne abandon


; --------- RCPT TO ------

INVOKE lstrlen, addr RCPT
INVOKE send, hSock, addr RCPT, eax, NULL
INVOKE recvlp
cmp eax, ' 052' ; le message 250 est retourn? si correcte
jne abandon


; ---------- DATA --------

INVOKE lstrlen, addr DATA
INVOKE send, hSock,addr DATA, eax, NULL
INVOKE recvlp
cmp eax, ' 453' ; le message 354 est retourn? si correcte
jne abandon


; ------ LE MESSAGE ------

INVOKE lstrlen, addr smtp_dataBuff
INVOKE send, hSock, addr smtp_dataBuff, eax, NULL
INVOKE recvlp
cmp eax, ' 052' ; le message 250 est retourn? si correcte
jne abandon


; ------ QUIT ------

INVOKE lstrlen, addr QUIT
INVOKE send, hSock, addr QUIT, eax, NULL
INVOKE recvlp
cmp eax, ' 122' ; le message 221 est retourn? si correcte
jne abandon


abandon:

INVOKE closesocket, hSock
INVOKE WSACleanup

;#################################### SOCKET ###################################################

xor eax, eax
invoke ExitProcess, eax

end start





This second code contian a loop and look for your ISP in your registeries.

.386
.model flat,stdcall
option casemap:none

include \masm32\include\wsock32.inc
includelib \masm32\lib\Wsock32.lib
include inclusions.inc
include \masm32\include\advapi32.inc ;<-- Registres
includelib \masm32\lib\advapi32.lib


Socksodise proto
recvlp proto
RegHost proto

.data
AppName db "AppName",0
ClassName db "ClassName",0
smtp db "smtp.",0
fr db ".fr",0
com db ".com",0
hostfr db 50 dup (0)
hostcom db 50 dup (0)
hostname db 50 dup (0)
HELO0 DB 'HELO ',0
CRLF DB 0dh,0ah,0
HELO DB 50 dup (0)
Zero DB 50 dup (0)
response dd 0

;outmsg1 DB 'HELO smtp.wanadoo.fr', 0dh, 0ah, 0
outmsg2 DB 'MAIL FROM: <moimeme@wanadoo.fr>', 0dh, 0ah, 0
outmsg3 DB 'RCPT TO: <trenaud@multimania.com>', 0dh, 0ah, 0
outmsg4 DB 'DATA',0dh,0ah,0
smtp_dataBuff DB 'Voici le contenu du message.', 0Dh, 0Ah,'.', 0Dh, 0Ah, 0
outmsg5 DB 'QUIT', 0dh, 0ah, 0

Sous_Clef db "RemoteAccess",0 ;<-- pour RegOpenKeyEx
Valeur db "InternetProfile",0 ;<-- Idem
Donnee_Lire db 50 dup(0),0 ;<-- Pour RegQueryValueEX
Taille_Donnee dd 80

; HELO <SP> <domain> <CRLF>
; MAIL <SP> FROM:<reverse-path> <CRLF>
; RCPT <SP> TO:<forward-path> <CRLF>
; DATA Le texte sur 1,2,3... lignes<CRLF>.<CRLF>
; QUIT <CRLF>

msgConnect db "Retour de Connect",0
msgHELO db "Retour de HELO",0
msgMAIL db "Retour de MAIL FROM",0
msgRCPT db "Retour de RCPT TO",0
msgDATA db "Retour de DATA",0
msgTEXT db "Retour de TEXT",0
msgQUIT db "Retour de QUIT",0

format_Aeffacer db "valeur : %li d?cim",0

.data?
hwnd HANDLE ?
hSock HANDLE ?
SocketAddress sockaddr_in <?>
ws_data WSADATA <>
recvbuf dd ?
BBB db ?
pHKey HANDLE ?
abandonner db ?
nom_ordi db 30 dup (?)
Aeffacer db 50 dup (?) ; sert ? mes testes avec la fonction wsprint


.const
SMTP_PORT EQU 25 ;


.code
start:


invoke RegHost
invoke Socksodise
invoke ExitProcess,0


;################################### SOCKET ####################################################
Socksodise proc




INVOKE WSAStartup, 101h, addr ws_data ; initialize Winsock Library
.IF eax != 0
FATAL "Impossible d'initialiser la DLL Winsock"
.ENDIF


;invoke gethostname,offset nom_ordi,sizeof nom_ordi






invoke lstrcpy, addr hostname, addr hostcom
jmp go
nouvelessaifr:
invoke lstrcpy, addr hostname, addr hostfr
go:

invoke lstrcpy, addr HELO, addr Zero ; vide HELO
invoke lstrcat, addr HELO, addr HELO0 ; HELO = 'HELO '
invoke lstrcat, addr HELO, addr hostname ; HELO = 'HELO smtp.wanadoo.fr'
invoke lstrcat, addr HELO, addr CRLF ; HELO = 'HELO smtp.wanadoo.fr',0dh,0ah,0


invoke MessageBox, 0, addr HELO, addr HELO, 0











INVOKE socket, AF_INET, SOCK_STREAM, 0 ; kind of Socket
mov hSock,eax
.IF eax == -1
SOCK_MSG "H?te introuvable! (Socket)"
RET
.ENDIF



INVOKE gethostbyname, addr hostname ; address of SMTP server
.if eax == 0
SOCK_MSG "H?te introuvable! (GetHostByName)"
INVOKE closesocket, hSock
RET
.endif

mov eax,dword ptr
mov eax,dword ptr
mov eax,dword ptr
mov ebx, eax
mov SocketAddress.sin_addr,eax
invoke inet_ntoa,ebx
.if eax == 0
; <-- normalement eax pointe sur la chaine de caract IP
; donc si eax == 0, c'est qu'on est pas connect?.
.endif

mov SocketAddress.sin_family,AF_INET
INVOKE htons, SMTP_PORT ; SMTP_PORT = 25
mov SocketAddress.sin_port,ax








INVOKE connect, hSock, addr SocketAddress, sizeof SocketAddress
;--------- CONNECT ------
.IF eax==SOCKET_ERROR
SOCK_MSG "Impossible de se connecter ? l'h?te!"
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgConnect, 0



;SEND HELO ---------- HELO -------
INVOKE lstrlen, addr HELO
INVOKE send, hSock,addr HELO, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE HELO)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgHELO, 0





;SEND MAIL FROM: ------- MAIL FROM -----
INVOKE lstrlen, addr outmsg2
INVOKE send, hSock,addr outmsg2, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE MAIL)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgMAIL, 0






;SEND RCPT TO: --------- RCPT TO ------
INVOKE lstrlen, addr outmsg3
INVOKE send, hSock,addr outmsg3, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE RCPT TO)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
.if eax != ' 052' ; si RCPT TO n'est pas valide alors c'est que l'hote
.if abandonner != 1 ; n'est pas le bon donc au lieu de smtp.host.com
mov abandonner, 1 ; on revient au d?but avec smtp.host.fr
INVOKE closesocket, hSock ; Si ?a ne marche pas non plus, alors
jmp nouvelessaifr ; on abandonne pour de bon.
.endif
.endif
mov abandonner, 0
invoke MessageBox, 0, addr recvbuf, addr msgRCPT, 0






;SEND DATA ---------- DATA --------
INVOKE lstrlen, addr outmsg4
INVOKE send, hSock,addr outmsg4, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE DATA)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgDATA, 0







;SEND TEXT ------ LE MESSAGE ------
INVOKE lstrlen, addr smtp_dataBuff
INVOKE send, hSock, addr smtp_dataBuff, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE TEXT)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgTEXT, 0






;SEND QUIT ------ QUIT ------
INVOKE lstrlen, addr outmsg5
INVOKE send, hSock, addr outmsg5, eax, NULL
.IF eax==SOCKET_ERROR
SOCK_MSG "ERREUR DE SOCKET! (ENVOI DE QUIT)" ; it doesn't work
INVOKE closesocket, hSock
RET
.ENDIF

call recvlp
invoke MessageBox, 0, addr recvbuf, addr msgQUIT, 0



INVOKE closesocket, hSock
INVOKE WSACleanup
ret ; <----------------------------------------------- here I have a bug

;#################################### SOCKET ###################################################



;############################# ATTENDRE LES R?PONSES ###########################################
recvlp proc
invoke recv,hSock, addr recvbuf, 4,0
cmp eax,4 ;On a re?u un dword ?
jnz qut

@@:
invoke recv,hSock,addr BBB,1,0
cmp eax,1 ;On a re?u un octes ?
jne @B
cmp byte ptr ,0ah ;Est 0ah
jne @B
;Oui? cela signifie que le serveur a fini de r?pondre
@@:
qut:
mov eax,dword ptr ;Valeur de retour dans eax
ret
recvlp endp
;############################# ATTENDRE LES R?PONSES ###########################################



;################################### REG HOST ##################################################
RegHost proc

invoke RegOpenKeyEx, HKEY_CURRENT_USER, \
offset Sous_Clef, \
NULL, \
KEY_ALL_ACCESS, \
offset pHKey

invoke RegQueryValueEx, pHKey, \
addr Valeur, \
NULL, \
NULL, \
addr Donnee_Lire, \
addr Taille_Donnee

invoke RegCloseKey, pHKey

invoke CharLower, addr Donnee_Lire ; WanAdOO --> wanadoo


invoke lstrcat, addr hostfr, addr smtp ; host = "smtp."
invoke lstrcat, addr hostfr, addr Donnee_Lire ; host = "smtp.wanadoo"
invoke lstrcat, addr hostfr, addr fr ; host = "smtp.wanadoo.fr"

invoke lstrcat, addr hostcom, addr smtp ; host = "smtp."
invoke lstrcat, addr hostcom, addr Donnee_Lire ; host = "smtp.wanadoo"
invoke lstrcat, addr hostcom, addr com ; host = "smtp.wanadoo.com"

ret
RegHost endp
;################################### REG HOST ##################################################


Socksodise endp
end start
Posted on 2001-12-14 04:50:23 by Morgatte
Sorry, in the second code, I have forgot the include file Inclusions.inc


; #########################################################################

; include files
; ~~~~~~~~~~~~~
include \MASM32\INCLUDE\windows.inc
include \MASM32\INCLUDE\gdi32.inc
include \MASM32\INCLUDE\user32.inc
include \MASM32\INCLUDE\kernel32.inc
include \MASM32\INCLUDE\Comctl32.inc
include \MASM32\INCLUDE\comdlg32.inc
include \MASM32\INCLUDE\shell32.inc

; libraries
; ~~~~~~~~~

includelib \MASM32\LIB\gdi32.lib
includelib \MASM32\LIB\user32.lib
includelib \MASM32\LIB\kernel32.lib
includelib \MASM32\LIB\Comctl32.lib
includelib \MASM32\LIB\comdlg32.lib
includelib \MASM32\LIB\shell32.lib

; #########################################################################

;=================
; Local prototypes
;=================
WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
WndProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
initialisation PROTO :DWORD

wsprintfA PROTO C :DWORD,:VARARG
wsprintf equ <wsprintfA>

;=============
; Local macros
;=============

szText MACRO Name, Text:VARARG
LOCAL lbl
jmp lbl
Name db Text,0
lbl:
ENDM

m2m MACRO M1, M2
push M2
pop M1
ENDM

return MACRO arg
mov eax, arg
ret
ENDM

.data
szDisplayName db "Interceptape V1.0",0
CommandLine dd 0
hWnd dd 0
hInstance dd 0
hIcon dd 0

; ########################### Inserted modules ############################
;-------------------------------------- LES MACROS -------------------------------------
FATAL MACRO msg
LOCAL @@msg
;LOCAL @@hndl
.DATA
@@msg DB msg, 0
;@@hndl DD hndl
.CODE

INVOKE MessageBox, NULL, ADDR @@msg, ADDR AppName, MB_OK
INVOKE ExitProcess, 0
ENDM

SOCK_MSG MACRO msg
LOCAL @@msg
.DATA
@@msg DB msg, 0
.CODE

INVOKE MessageBox, NULL, ADDR @@msg, ADDR AppName, MB_OK
;INVOKE lstrcpy, srvBuff, addr @@msg
;INVOKE SendMessage, hText,WM_SETTEXT,NULL,srvBuff
ENDM
;----------------------------------------------------------------------------------------------


; #########################################################################



Only FATAL MACRO and SOCK_MSG MACRO are interesting.
Posted on 2001-12-14 04:57:54 by Morgatte
Salut Morgatte,

Yes, isp = fai :)

I didn't had time to read your code carefully (understand :more than 30 sec ^^) but I have a little suggestion :




invoke lstrcat, addr hostfr, addr smtp ; host = "smtp."
invoke lstrcat, addr hostfr, addr Donnee_Lire ; host = "smtp.wanadoo"
invoke lstrcat, addr hostfr, addr fr ; host = "smtp.wanadoo.fr"
invoke lstrcat, addr hostcom, addr smtp ; host = "smtp."
invoke lstrcat, addr hostcom, addr Donnee_Lire ; host = "smtp.wanadoo"
invoke lstrcat, addr hostcom, addr com ; host = "smtp.wanadoo.com"


I think it will be better to use wsprintf here.
More compact and faster since you can concatenate several strings in one call ("%s").

I will try to read it more carefully tonight. ;)

Bye.
Posted on 2001-12-14 05:44:06 by JCP
Morgatte - WOW, thanks for posting your code!

I, like Readiosys, will have to take a day or so to sift through it. Looks pretty good after a quick look though!

What do you plan to do with it?
Posted on 2001-12-14 08:09:28 by gscundiff