;****************************************************************************** ; This lib is modified Iczelion http sample ;****************************************************************************** include \develop\masm32\include\wsock32.inc includelib \develop\masm32\lib\wsock32.lib .data PostTemplate db "POST %s HTTP/1.0",0dh,0ah db "Host: %s",0Dh,0Ah db "User-Agent: DriveInspector 0.9 (http://qtime.ru)",0Dh,0Ah db "Content-Length: 136",0Dh,0Ah db 0Dh,0Ah db "",0Dh,0Ah db "",0Dh,0Ah db " %04u-%02u-%02u %02u:%02u:%02u ",0Dh,0Ah db " %02u ",0Dh,0Ah db "",0Dh,0Ah,00 HTTP db "http://",0 sock dd 0 ; socket handle HTTPPort dd 80 ; the port that's used to connect to HTTP server HostName db 100 dup(?),0 RelativeURL db 400 dup(?),0 CommandString db 512 dup(?),0 ; The buffer to store the command to send to the web server URLString db 512 dup(?),0 PortString db 10 dup(?),0 ; the string indicating HTTP port in the url .data? wsadata WSADATA <> SocketAddress sockaddr_in <> .code ;****************************************************************************** ; String2Dword ;****************************************************************************** ; This procedure takes an address of a string and converts it to a dword ; value which it returns in eax ;****************************************************************************** String2Dword proc uses ecx edi edx esi String:DWORD xor ecx,ecx mov edi,String invoke lstrlen,String .while eax!=0 xor edx,edx mov dl,byte ptr [edi] sub dl,"0" ; subtrack each digit with "0" to convert it to hex value mov esi,eax dec esi push eax mov eax,edx push ebx mov ebx,10 .while esi > 0 mul ebx dec esi .endw pop ebx add ecx,eax pop eax inc edi dec eax .endw mov eax,ecx ret String2Dword endp ;****************************************************************************** ; ParseURL ;****************************************************************************** ; This function parses the url string for host name, relative URL and http port ;****************************************************************************** ParseURL PROC uses esi edi URL:DWORD LOCAL MyURL[512] :BYTE LOCAL URLLength :DWORD invoke lstrlen,URL mov URLLength,eax mov ecx,eax ; Trim the spaces at the start of the url string, if any mov edi,URL mov al,20h repe scasb dec edi invoke lstrcpy,addr MyURL,edi ; We don't want to modify the original url string since we have to modify the cases of the url invoke lstrcpy,URL,addr MyURL invoke lstrlen,URL mov URLLength,eax invoke RtlFillMemory, addr HostName, 501, 0 ; fill HostName and RelativeURL with zeroes invoke CharLower, addr MyURL ; change to lower case for ease of comparison lea edi,MyURL mov esi,offset HTTP ; check if the url starts with "http://" mov ecx,7 repe cmpsb jne No_HTTP mov eax,URLLength ; if it is, substract the length of url string by 7 to sub eax,7 ; account for the length of "http://" string mov URLLength,eax jmp Common_parse No_HTTP: lea edi,MyURL Common_parse: push edi invoke lstrcpy,addr MyURL,URL pop edi xor ecx,ecx mov esi,offset HostName mov HTTPPort,80 ; Default port = 80 .while ecx < URLLength .if byte ptr [edi]=="/" ; if "/" is found, it denotes the end of the host name string invoke lstrcpy,addr RelativeURL,edi ; and the start of the relative url string .break .elseif byte ptr [edi]==":" ; if ":" is found, it means an HTTP port is specified in the url inc ecx inc edi invoke RtlFillMemory,addr PortString, 10, 00 mov eax,offset PortString .while (byte ptr [edi]!="/") && (byte ptr [edi]!=00) mov dl,byte ptr [edi] mov byte ptr [eax],dl inc eax inc ecx inc edi .endw invoke String2Dword, addr PortString mov HTTPPort,eax .else mov al,byte ptr [edi] mov byte ptr [esi],al inc edi inc esi inc ecx .endif .endw .if ecx==URLLength ; if there's no relative URL , we must add "/" to it. mov byte ptr [RelativeURL],"/" .endif ret ParseURL endp ;****************************************************************************** ; ConnectSocket ;****************************************************************************** ; This function perform connection to the specified URL ;****************************************************************************** ConnectSocket proc invoke ParseURL, addr URLString ; Parse the URL into host name, relative url and the http port invoke socket,AF_INET,SOCK_STREAM,0 ; Create a stream socket .if eax!=INVALID_SOCKET mov sock,eax invoke inet_addr,addr HostName ; Assume that the host name is not an ip address. If the host name is really an ip address, ; the function will fail with eax==INADDR_NONE .if eax==INADDR_NONE invoke gethostbyname,addr HostName .if eax==NULL ;invoke ShowErrorMessage ret .endif mov eax, [eax+12] mov eax, [eax] mov eax, [eax] mov SocketAddress.sin_addr, eax .else mov SocketAddress.sin_addr, eax .endif mov SocketAddress.sin_family, AF_INET invoke htons,HTTPPort ; We must convert host byte order to network byte order mov SocketAddress.sin_port,ax invoke connect, sock, addr SocketAddress, sizeof SocketAddress ;.if eax==SOCKET_ERROR ; invoke WSAGetLastError ; .if eax!=WSAEWOULDBLOCK ; invoke ShowErrorMessage ; .endif ;.endif .else ;invoke ShowErrorMessage .endif ret ConnectSocket endp ;****************************************************************************** ; SendRequest ;****************************************************************************** ; This function sends HTTP request to the connected socket ;****************************************************************************** SendRequest PROC invoke lstrlen, addr CommandString invoke send, sock, addr CommandString, eax, 0 ret SendRequest ENDP ;****************************************************************************** ; CloseSock ;****************************************************************************** ; This function performs winsock library shutdown. It closes socket, ; output file, kills timer,and calls WSACleanup. It also clears the ; status bar and resets the progress bar control. ;****************************************************************************** CloseSock proc .if sock!=0 invoke closesocket, sock mov sock,0 .endif ret CloseSock endp ;****************************************************************************** ; This function posts xml data to the specified URL ;****************************************************************************** WriteToHttp proc LOCAL _st :SYSTEMTIME invoke lstrcpy, addr URLString, addr SignalHttp invoke ConnectSocket invoke GetLocalTime, addr _st .if (TunerInfo.sigq!=03) || (!SkyDllOk) mov sig_lev,0 .endif ; Create request push sig_lev sub eax,eax mov ax,_st.wSecond push eax mov ax,_st.wMinute push eax mov ax,_st.wHour push eax mov ax,_st.wDay push eax mov ax,_st.wMonth push eax mov ax,_st.wYear push eax push offset HostName push offset RelativeURL push offset PostTemplate push offset CommandString call wsprintfA add esp, 02Ch invoke SendRequest invoke CloseSock ret WriteToHttp endp