Hello, i have attached the source code that i have been having some problems with, it is suppose to notify me on icq.....

oh wel here is the code:

.if eax==IDC_BTN1
invoke socket,AF_INET,SOCK_STREAM,0
mov sock,eax
mov sin.sin_family, AF_INET
invoke htons, Port
mov sin.sin_port,ax
invoke gethostbyname,addr HostName
mov eax,
mov eax,
mov eax,
mov sin.sin_addr,eax
invoke connect,sock,addr sin,sizeof sin
invoke send,sock,addr ctext,sizeof ctext,0
invoke closesocket,sock
.endif



where ctext:

ctext db 'POST http://wwp.icq.com/scripts/WWPMsg.dll HTTP/2.0',13,10
db 'Referer: http://wwp.mirabilis.com',13,10
db 'Connection: Keep-Alive',13,10
db 'Host: wwp.mirabilis.com:80',13,10
db 'Content-type: application/x-www-form-urlencoded',13,10
db 'Content-length:8000',13,10
db 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*',13,10,13,10
db 'from=Tsongkie &fromemail=tsongkie@cayamanan.com &fromicq:110206786 &body=Hello &to=118494738&Send=',0




I'm trying to translate this code that i found.... Its in Delphi/Pascal, maybe someone else can try....

procedure TForm1.Button1Click(Sender: TObject);
begin
cSend := 'POST http://wwp.icq.com/scripts/WWPMsg.dll HTTP/2.0' + chr(13) + chr(10);
cSend := cSend + 'Referer: http://wwp.mirabilis.com' + chr(13) + chr(10);
cSend := cSend + 'User-Agent: Mozilla/4.06 (Win95; I)' + chr(13) + chr(10);
cSend := cSend + 'Connection: Keep-Alive' + chr(13) + chr(10);
cSend := cSend + 'Host: wwp.mirabilis.com:80' + chr(13) + chr(10);
cSend := cSend + 'Content-type: application/x-www-form-urlencoded' + chr(13) + chr(10);
cSend := cSend + 'Content-length:8000' + chr(13) + chr(10);
cSend := cSend + 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*' +
chr(13) + chr(10) + chr(13) + chr(10);
cSend := cSend + 'from=' + edit1.Text + ' &fromemail=' + edit2.Text +
' &fromicq:110206786' + ' &body=' + memo1.Text + ' &to=' + edit3.Text + '&Send=';
clientsocket1.Active := True;
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
clientsocket1.Socket.SendText(csend);
clientsocket1.Active := False;
end;


Sorry for the long post...
Posted on 2002-04-21 10:20:03 by Tsongkie[ii]
First of all, the sizeof(ctext) will only give you the size of the first line of text. Use this instead:


string db "gewgwe"
db "wefefwfew"
size_string equ $-string


Secondly, you shouldn't send the 0 byte at the end of the request.

Finally, with the above modifications, the data is sent, but not in the right way. You have set content-length to a fixed number, it should be the actual size of the posted data (starting with 'from'). If you specify 8000 the server will wait until you've sent it 8000 bytes. So first calculate the size of the posted data, put that in the header, send the header, and then send the actual data.

One last thing: you shouldn't use spaces between the different variables
(...from=Tsongkie{no space here}&fromem..).

Thomas
Posted on 2002-04-21 10:40:12 by Thomas
Hey thanks for the reply... but when i used:

string db "gewgwe"
db "wefefwfew"
size_string equ $-string

I get an error: error A2025: operands must be in same segment

also, i'm pretty new at this stuff so how can i send the data withouth the 0?
Posted on 2002-04-21 19:57:59 by Tsongkie[ii]


...
ctext db 'POST (...)
...
db 'from=Tsongkie &fromemail=tsongkie@cayamanan.com &fromicq:110206786 &body=Hello &to=118494738&Send='[B],0
[/B]size_of_ctext equ $ - ctext
...


remove the text in bold.
if size_of_ctext gives an error put:


size_of_ctext equ $ - offset ctext


dunno if it works.

cu

Coder7345/ jEAN
Posted on 2002-04-27 12:04:33 by coder
Here is *correct* and working C code, don't use the source you found as it is wrong.


#define CRLF "\r\n"

char requestFormat[] =
{
"POST [url]http://wwp.icq.com/scripts/WWPMsg.dll[/url] HTTP/1.1" CRLF
"Referer: [url]http://wwp.mirabilis.com[/url]" CRLF
"Connection: Keep-Alive" CRLF
"Host: wwp.mirabilis.com" CRLF
"Content-type: application/x-www-form-urlencoded" CRLF
"Content-length: %lu" CRLF
"Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*" CRLF
CRLF
};

char postFormat[] =
{
"from=%s" //1st = from
"&fromemail=%s" //2nd = email
"&fromicq=%lu" //3rd = from icq
"&body=%s" //4th = body
"&to=%lu" //5th = to icq
"&Send="
};

#define PORTNR(x) ((x&0xFF)<<8|(x&0xFF00)>>8)

int main(int argc, char* argv[])
{
WSADATA wsaData;
WSAStartup(2,&wsaData);

char headerBuf[1024];
char postData[2048];

wsprintf(postData,postFormat,
"Thomas",
"nobody@invalid.mail",
12345678,
"This%20is%20a%20test%20message",
<<your icq here>>);

wsprintf(headerBuf,requestFormat,
lstrlen(postData));

SOCKET hSocket = socket(AF_INET, SOCK_STREAM, 0);

sockaddr_in sockAddr;

DWORD serverIP = ((long*)gethostbyname("wwp.icq.com")->h_addr_list[0])[0];

sockAddr.sin_addr.S_un.S_addr = serverIP;
sockAddr.sin_port = PORTNR(80);
sockAddr.sin_family = AF_INET;

connect(hSocket, (sockaddr*)&sockAddr, sizeof(sockAddr));

send(hSocket, headerBuf, lstrlen(headerBuf), 0);
send(hSocket, postData, lstrlen(postData), 0);


closesocket(hSocket);

WSACleanup();
return 0;
}


Thomas
Posted on 2002-04-27 12:35:54 by Thomas
mmm nice :) ... easy to convert 2 assembly. And this code help me to undestand how i do a "raw POST" on a site.

cu

Coder7345 / jEAN
Posted on 2002-04-27 14:27:16 by coder
Don't forget that all posted data has to be www/url encoded, i.e. special characters (special characters = [^A-Za-z0-9_] to be safe) have to be converted to their hex equivalents %XX.

Thomas
Posted on 2002-04-27 15:56:37 by Thomas
actually thomas i was having trouble finding a way to convert a string to hex .. i was making a program to post to an .asp page but it didnt work if the the string had those charactors any help with a sample code or a point iin the right direction?
Posted on 2002-04-28 11:53:25 by illwill
source: esi
dest: edi



dec edi
_nc:
movzx eax, byte ptr [esi]

test al, al ; al==0
jz _done

inc edi
inc esi

cmp al, 41h ; al=='A'
mov cl, al
jb _lA

cmp al, 5Bh ; al=='Z'
jbe _cpy

;al >= A
cmp al, 5Fh ; al=='_'
je _cpy

;al > _
cmp al, 61h ; al=='a'
jb _hex

; al >= a
cmp al, 7Ah ; al=='z'
jbe _cpy

_hex:
ror ax, 4
mov byte ptr [edi], '%'
shr ah, 4
add edi, 2
add al, 30h
cmp al, 3Ah
jb @F
add al, 41h-3Ah
@@:
add ah, 30h
cmp ah, 3Ah
jb @F
add ah, 41h-3Ah
@@:
mov word ptr [edi-1], ax
jmp _nc

_cpy:
mov [edi], al
jmp _nc

_space:
mov byte ptr [edi], '+'
jmp _nc

_lA:
cmp al, 20h
je _space

sub cl, 2Dh ; al=='-'
jz _cpy
dec cl ; al=='.'
jz _cpy

cmp al, 30h ; al=='0'
jb _hex

;al >= '0'
cmp al, 39h ; al=='9'
jbe _cpy

jmp _hex
_done:
mov byte ptr [edi],0


output buffer needs to be large enough to hold the converted data, which is 3*source_length in the *worst case*.
I think you can build the proc around it yourself :)

Thomas
Posted on 2002-04-28 12:45:22 by Thomas
yea i mad it into a process called hexit thanxfor the help .. here is the process for other to uses that needed help like me thanx again for the help

hexit PROTO :DWORD, :DWORD

.data
stringsrc db "!@#$%^%^*()~ omg! it's converted to hex!?",0

.data?
stringdest byte 255 dup (?)


.code
start:
invoke hexit,addr stringsrc,addr stringdest
invoke MessageBox,0,addr stringdest,addr stringsrc,MB_OK
invoke ExitProcess,0

hexit PROC szSRC:DWORD,szDEST:DWORD
push esi
push edi
mov esi,szSRC
mov edi,szDEST

dec edi
_nc:
movzx eax, byte ptr

test al, al ; al==0
jz _done

inc edi
inc esi

cmp al, 41h ; al=='A'
mov cl, al
jb _lA

cmp al, 5Bh ; al=='Z'
jbe _cpy

;al >= A
cmp al, 5Fh ; al=='_'
je _cpy

;al > _
cmp al, 61h ; al=='a'
jb _hex

; al >= a
cmp al, 7Ah ; al=='z'
jbe _cpy

_hex:
ror ax, 4
mov byte ptr , '%'
shr ah, 4
add edi, 2
add al, 30h
cmp al, 3Ah
jb @F
add al, 41h-3Ah
@@:
add ah, 30h
cmp ah, 3Ah
jb @F
add ah, 41h-3Ah
@@:
mov word ptr , ax
jmp _nc

_cpy:
mov , al
jmp _nc

_space:
mov byte ptr , '+'
jmp _nc

_lA:
cmp al, 20h
je _space

sub cl, 2Dh ; al=='-'
jz _cpy
dec cl ; al=='.'
jz _cpy

cmp al, 30h ; al=='0'
jb _hex

;al >= '0'
cmp al, 39h ; al=='9'
jbe _cpy

jmp _hex
_done:
mov byte ptr ,0
pop esi
pop edi
ret
hexit ENDP

end start
Posted on 2002-04-30 17:18:26 by illwill
A procedure, not a process ;).
A couple of notes... you don't have to do numeric comparisons, you
can do "cmp al, '_'" or "cmp al, 'Z'".

Still looks like there's room for improvement :].
Posted on 2002-04-30 17:28:30 by f0dder
hey, thanks for all the reply, i found out another way using wininet.lib :) Thank you very much, i can attach the source if you want :)
Posted on 2002-05-02 17:55:03 by Tsongkie[ii]