News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Reading webpage via wininet.dll

Started by Ksbunker, May 01, 2008, 04:26:41 AM

Previous topic - Next topic

Ksbunker

I'm trying to get the following code working. When I read the data from the page, it reads "<!x>". The string should return either "0" or "1", ive been trying to fix this for ages but with no success, any hlp would be fantastic, cheers.

.386
.model flat,stdcall
option casemap:none

include windows.inc
include user32.inc
include kernel32.inc
include shell32.inc
include wininet.inc

includelib user32.lib
includelib kernel32.lib
includelib shell32.lib
includelib wininet.lib

CheckPerform_Ban PROTO :DWORD, :DWORD

.data

szName db "POO123", 0

.code

start:

mov eax, 0
Invoke CheckPerform_Ban, eax, addr szName
Invoke ExitProcess, 0

CheckPerform_Ban PROC ban:DWORD, username:DWORD

.data

szBanPhp db "http://ksbunker.beyondgaming.org/bancheck.php?ban=!&username=%s", 0
szBanUrl db 255 dup(0)
szAgent1 db "RS2.06PATCH", 0
szRet db 2 dup(0)
dwSize dd 0

.code

mov eax, ban
cmp al, 0
jne @next
mov [szBanPhp+50], byte ptr 30h      ;'0' = !
jmp @F
@next:
mov [szBanPhp+50], byte ptr 31h      ;'1' = !
@@:
Invoke wsprintf, addr szBanUrl, addr szBanPhp, username

Invoke InternetOpen, addr szAgent1, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, NULL
Invoke InternetOpenUrl, eax, addr szBanUrl, NULL, NULL, INTERNET_FLAG_NO_CACHE_WRITE, 0
mov ebx, eax
Invoke InternetReadFile, eax, addr szRet, sizeof szRet, addr dwSize    ;szRet = byte 30h "0" or 31 "1"
Invoke InternetCloseHandle, ebx

cmp [szRet], byte ptr 30h
jne @banned
mov eax, 0
ret

@banned:
mov eax, 1
ret

CheckPerform_Ban ENDP

end start

kermit

hm,

don't know what ur problem is, the code is working for me ( returns 1 in eax for the specified username, 0 for a different one )

maybe some proxy / firewall issues ?
try checking the return values / handles to localize the error ...

greetz,

kermit

Ksbunker

you're right... it's working now thank god.

not sure why it wasn't before, perhaps errors on the php side of things.

Nonetheless, thanks for your testing out of the code kermit, big thanks!

Ian_B

Here is the perfect example of why I hate frame-based proc calling:

mov eax, 0
Invoke CheckPerform_Ban, eax, addr szName

... [jumps to routine]

mov eax, ban


all of which could have been simplified by using OPTION PROLOGUE:none / OPTION EPILOGUE:none and simply jumping to the routine with the value in EAX, which is all you've basically done but with lots more wasted ops, memory writes and stack frame setting up inbetween. Obviously that's insignificant compared to the API overhead and waiting for the TCP data to arrive, but it's the principle of reducing everything to the smallest code that counts - isn't that why we are here?

The reason I'm replying is not to diss your programming style, though, but to ask where you preserved the value of EBX prior to this line?

mov ebx, eax

The concept is good, using EBX as it stays unchanged through the two API calls, but you still need to insulate YOUR use from surrounding code.