having trouble with this code.... it seems like its posting right but it doesnt show up on the .asp page and for some reason it loops when its not supposed to im using winsock cuz i cant figure out how to use wininet

WebPost PROTO :DWORD

.data
lpszAddy db "www30.brinkster.com",0
lpszString db "GET http://%s/xillwillx/new.asp?%s,%s HTTP/1.1",13,10
db "Connection: keep-alive",13,10
db "Host: %s",13,10
db "Referer: http://www30.brinkster.com/xillwillx/",13,10,13,10,13,10,0
posttest db 'hi im posted',0
dwWEBStr dd 0
hWEBSock dd 0
lpszBuffer db 256 dup(?)
lpWSAData WSADATA<>
lpWEBSIN sockaddr_in<>
.code
start:
invoke WebPost,0
invoke ExitProcess,NULL


WebPost PROC dwError:DWORD
startnotify:
INVOKE WSAStartup, 101h, ADDR lpWSAData
; INVOKE socket, 2, 1, 0
INVOKE socket, AF_INET, SOCK_STREAM, 0
cmp eax, INVALID_SOCKET
je error

MOV hWEBSock, EAX
MOV lpWEBSIN.sin_family, 2
INVOKE htons, 80
MOV lpWEBSIN.sin_port, ax
INVOKE gethostbyname, ADDR lpszAddy
MOV EAX,
MOV EAX,
MOV EAX,
MOV lpWEBSIN.sin_addr, EAX
INVOKE connect, hWEBSock, ADDR lpWEBSIN, SIZEOF lpWEBSIN
cmp EAX, SOCKET_ERROR
je error


INVOKE wsprintf, ADDR dwWEBStr, ADDR lpszString, addr lpszAddy,addr posttest,addr posttest, addr lpszAddy
invoke MessageBox,0,addr dwWEBStr,addr dwWEBStr,MB_OK

INVOKE send, hWEBSock, ADDR dwWEBStr, EAX, 0
cmp EAX, SOCKET_ERROR
je error
INVOKE closesocket, hWEBSock
INVOKE WSACleanup
ret
error:
INVOKE closesocket, hWEBSock
INVOKE WSACleanup
INVOKE Sleep, 3000
JMP startnotify
WebPost ENDP
end start
Posted on 2002-06-22 17:15:38 by illwill
the first parameter of wsprintf is a *buffer* that receives the formatted string. In your code, you don't supply a buffer but a pointer to a dword.
The dword will be filled with the first 4 bytes of the wsprintf output and will then overflow and corrupt all other data variables behind it. Add a new buffer (buffer db 256 dup (?) or something) to use, or use the existing one.
A few other things:
- 'hi im posted'. The spaces in that sentence will corrupt the request, they should be %20 (the whole URI after GET should be www/url-encoded). Btw, with 'posted', most of the time, the POST method is meant, not GET.
- Not really a problem, but it's better to use the right prefixes for variable names. lpszAddy for example, 'lpsz' means (long) pointer to a null terminated string. But it isn't that, it's a null terminated string, not a pointer to it. So szAddy would be a more appropriate name (lpszAddy should be a dword actually). It doesn't matter to the assembler but it avoids confusion.

Thomas
Posted on 2002-06-22 17:30:51 by Thomas
WebPost PROTO :DWORD

.data
szAddy db "www30.brinkster.com",0
lpszString db "POST http://%s/xillwillx/new.asp?%s,%s HTTP/1.1",13,10
db "Connection: keep-alive",13,10
db "Host: %s",13,10
db "Referer: http://www30.brinkster.com/xillwillx/",13,10,13,10,13,10,0
posttest db 'Thomas%20Rules',0
dwWEBStr dd 0
hWEBSock dd 0
lpszBuffer db 256 dup(?)
lpWSAData WSADATA<>
lpWEBSIN sockaddr_in<>
.data?
buffer db 256 dup (?)
.code
start:
invoke WebPost,0
invoke ExitProcess,NULL


WebPost PROC dwError:DWORD
startnotify:
INVOKE WSAStartup, 101h, ADDR lpWSAData
; INVOKE socket, 2, 1, 0
INVOKE socket, AF_INET, SOCK_STREAM, 0
cmp eax, INVALID_SOCKET
je error

MOV hWEBSock, EAX
MOV lpWEBSIN.sin_family, 2
INVOKE htons, 80
MOV lpWEBSIN.sin_port, ax
INVOKE gethostbyname, ADDR szAddy
MOV EAX,
MOV EAX,
MOV EAX,
MOV lpWEBSIN.sin_addr, EAX
INVOKE connect, hWEBSock, ADDR lpWEBSIN, SIZEOF lpWEBSIN
cmp EAX, SOCKET_ERROR
je error


INVOKE wsprintf, ADDR buffer, ADDR lpszString, addr szAddy,addr posttest,addr posttest, addr szAddy
;invoke MessageBox,0,addr buffer,addr buffer,MB_OK

INVOKE send, hWEBSock, ADDR buffer, EAX, 0
cmp EAX, SOCKET_ERROR
je error
INVOKE closesocket, hWEBSock
INVOKE WSACleanup
ret
error:
INVOKE closesocket, hWEBSock
INVOKE WSACleanup
INVOKE Sleep, 3000
JMP startnotify
WebPost ENDP

well this worked thank you .. btw i was talking with dawai on irc and he suggested using wininet.. he said it makes for cleaner coding... plus i gotta be able to use GET to read the posted text off the page... any other suggestions would be appreciated
:alright:
Posted on 2002-06-22 17:55:07 by illwill