/* compress/decompress a file */ static void handle_file(char *file, struct stat *sbp) { off_t usize, gsize; char outfile[PATH_MAX]; infile = file; if (dflag) { usize = file_uncompress(file, outfile, sizeof(outfile)); #ifndef SMALL if (vflag && tflag) print_test(file, usize != -1); #endif if (usize == -1) return; gsize = sbp->st_size; } else { gsize = file_compress(file, outfile, sizeof(outfile)); if (gsize == -1) return; usize = sbp->st_size; } #ifndef SMALL if (vflag && !tflag) print_verbage(file, (cflag) ? NULL : outfile, usize, gsize); #endif }
DWORD WINAPI sendFileThread(LPVOID lpParam) { char *filename = (char *)lpParam; try { char installPath[1024]; CModuleUtil::getInstallPath(installPath); char fname[1024]; sprintf(fname, "%s\\%s", installPath, filename); char fnameGz[1024]; sprintf(fnameGz, "%s\\%s.gz", installPath, filename); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%d.gz", filename, time(NULL), rand()); file_compress(fname, "wb"); CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); ftpConnection->PutFile(fnameGz, remoteFileName); ftpConnection->Close(); delete ftpConnection; _unlink(fname); _unlink(fnameGz); fileSendingProgress = 1; } catch (CInternetException*) { fileSendingProgress = -1; } return 0; }
int joinFiles_Ext1 (const char *sourceDir, const char *sourceName,const char *extName) { stJAndSHeader *joinHdr = NULL; FILE *fileHdl = NULL; char destName[_MAX_DIR],tempName[_MAX_DIR]; char outmode[] = "wb6 "; short nErr; // Get memory for the join header structure joinHdr=pstrFileNameArr; if(joinHdr->numFilesJoined==0) { return 1; } errno = EZERO; // Generate the destination name if (strlen(sourceDir)) sprintf (destName, "%s\\%s%s", sourceDir, sourceName, extName); else sprintf (destName, ".\\%s%s", sourceName, extName); // Open the join file... if ((fileHdl = fopen (destName, "wb")) != NULL) { // ... and join in all the files. writeHeader ( joinHdr, fileHdl); concatFiles ( sourceDir, joinHdr, fileHdl); fclose (fileHdl); // Rename file as a temporary file if (strlen(sourceDir)) sprintf (tempName, "%s\\%s%s", sourceDir, sourceName, ".CAT"); else sprintf (tempName, ".\\%s%s", sourceName, ".CAT"); rename (destName, tempName); // Compress the file @2 if ((nErr = file_compress (sourceDir, sourceName, ".CAT", extName,outmode)) != 0) { String msg = String("Failed to compress ") + sourceName; throw std::exception ( msg.c_str() ); return nErr; } } return errno; }
DWORD WINAPI sendMapsThread(LPVOID lpParam) { char *path = (char *)lpParam; try { char fullMask[1024]; sprintf(fullMask, "%s\\*.map", path); WIN32_FIND_DATA data; HANDLE hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); time_t t = time(NULL); int r = rand(); int lastfile = 1; while (lastfile) { char fname[128]; char fnameGz[128]; sprintf(fname, "%s\\%s", path, data.cFileName); sprintf(fnameGz, "%s\\%s.gz", path, data.cFileName); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%d.gz", data.cFileName, t, r); file_compress(fname, "wb"); ftpConnection->PutFile(fnameGz, remoteFileName); _unlink(fnameGz); lastfile = FindNextFile(hFind, &data); } ftpConnection->Close(); delete ftpConnection; } fileSendingProgress = 1; } catch (CInternetException*) { fileSendingProgress = -1; } // allocated before starting a thread free(path); return 0; }
DWORD WINAPI sendPacketLogThread(LPVOID lpParam) { char path[1024]; CModuleUtil::getInstallPath(path); char fullMask[1024]; sprintf(fullMask, "%s\\tascripts\\* statistics.txt", path); WIN32_FIND_DATA data; HANDLE hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { char fname[128]; int lastfile = 1; while (lastfile) { sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); FILE* f = fopen(fname, "a+"); if (f) { fseek(f, 0, SEEK_END); int flen = ftell(f); fclose(f); if (flen > 1000) goto sendFiles; } lastfile = FindNextFile(hFind, &data); } } { hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { char fname[128]; int lastfile = 1; while (lastfile) { sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); _unlink(fname); lastfile = FindNextFile(hFind, &data); } } fileSendingProgress = 1; return 0; } sendFiles: int msgboxID = -1; if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) msgboxID = MessageBox(NULL, "TA is about to send your botting statistics to TA.net. You can edit this option in \"General options and statistics\".\n\nWould you like to receive this message every time before TA sends this data?\nUse cancel to stop the operation.", "Submit Botting Data", MB_YESNOCANCEL); if (msgboxID == IDCANCEL) return 0; try { hFind = FindFirstFile(fullMask, &data); if (hFind != INVALID_HANDLE_VALUE) { CInternetSession session; CFtpConnection *ftpConnection = session.GetFtpConnection("upload.tibiaauto.net", "anonymous", "*****@*****.**", 21, true); time_t t = time(NULL); unsigned long serialNumber; GetVolumeInformation(NULL, NULL, 0, &serialNumber, NULL, NULL, NULL, 0); unsigned int r = serialNumber % 0x1000000; int lastfile = 1; while (lastfile) { char fname[128]; char fnameGz[128]; sprintf(fname, "%s\\tascripts\\%s", path, data.cFileName); sprintf(fnameGz, "%s\\tascripts\\%s.gz", path, data.cFileName); char remoteFileName[128]; sprintf(remoteFileName, "incoming/%s-%d-%u.gz", data.cFileName, t, r); file_compress(fname, "wb"); ftpConnection->PutFile(fnameGz, remoteFileName); _unlink(fnameGz); lastfile = FindNextFile(hFind, &data); _unlink(fname); } ftpConnection->Close(); delete ftpConnection; } fileSendingProgress = 1; if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) AfxMessageBox("Thank you for submitting \"botting statistics.txt\" and \"module statistics.txt\".\n\nNo personally identifiable information was sent.\nThis botting information will be analysed and used to help prevent CIPSoft from automatically detecting TA in the future. You can change this setting in \"General Options and Statistics\".\n\nTA users thank you for helping us towards this end.\n~TA Team"); } catch (CInternetException*) { if (!CModuleUtil::getTASetting("RemoveBotStatsMessage")) AfxMessageBox("Failed to send file. Check your connection to the internet."); fileSendingProgress = -1; } if (msgboxID == IDNO) CModuleUtil::setTASetting("RemoveBotStatsMessage", 1); return 0; }
int main( int argc, char *argv[]) { int copyout = 0; int uncompr = 0; gzFile file; char *bname, outmode[20]; strcpy(outmode, "wb6 "); prog = argv[0]; bname = strrchr(argv[0], '/'); if (bname) bname++; else bname = argv[0]; argc--, argv++; if (!strcmp(bname, "gunzip")) uncompr = 1; else if (!strcmp(bname, "zcat")) copyout = uncompr = 1; while (argc > 0) { if (strcmp(*argv, "-c") == 0) copyout = 1; else if (strcmp(*argv, "-d") == 0) uncompr = 1; else if (strcmp(*argv, "-f") == 0) outmode[3] = 'f'; else if (strcmp(*argv, "-h") == 0) outmode[3] = 'h'; else if (strcmp(*argv, "-r") == 0) outmode[3] = 'R'; else if ((*argv)[0] == '-' && (*argv)[1] >= '1' && (*argv)[1] <= '9' && (*argv)[2] == 0) outmode[2] = (*argv)[1]; else break; argc--, argv++; } if (outmode[3] == ' ') outmode[3] = 0; if (argc == 0) { SET_BINARY_MODE(stdin); SET_BINARY_MODE(stdout); if (uncompr) { file = gzdopen(fileno(stdin), "rb"); if (file == NULL) error("can't gzdopen stdin"); gz_uncompress(file, stdout); } else { file = gzdopen(fileno(stdout), outmode); if (file == NULL) error("can't gzdopen stdout"); gz_compress(stdin, file); } } else { if (copyout) { SET_BINARY_MODE(stdout); } do { if (uncompr) { if (copyout) { file = gzopen(*argv, "rb"); if (file == NULL) fprintf(stderr, "%s: can't gzopen %s\n", prog, *argv); else gz_uncompress(file, stdout); } else { file_uncompress(*argv); } } else { if (copyout) { FILE * in = fopen(*argv, "rb"); if (in == NULL) { perror(*argv); } else { file = gzdopen(fileno(stdout), outmode); if (file == NULL) error("can't gzdopen stdout"); gz_compress(in, file); } } else { file_compress(*argv, outmode); } } } while (argv++, --argc); } return 0; }
int joinDir(const char *sourceDir, const char *extName) { stJAndSHeader *joinHdr = NULL; FILE *fileHdl = NULL; char destName[_MAX_DIR], tempName[_MAX_DIR]; char outmode[] = "wb6 "; short nErr; // Clear any outstanding errors errno = EZERO; // Get memory for the join header structure if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL) { // Populate the header with all the match files if (genHeader (sourceDir, "", extName, joinHdr, 1)) //@3 directory { // Clear any outstanding errors errno = EZERO; // Generate the destination name sprintf (destName, "%s%s", sourceDir, extName); // Open the join file... if ((fileHdl = fopen (destName, "wb")) != NULL) { // ... and join in all the files. writeHeader ( joinHdr, fileHdl); concatFiles ( sourceDir, joinHdr, fileHdl); fclose (fileHdl); // Rename file as a temporary file sprintf (tempName, "%s%s", sourceDir, ".CAT"); rename (destName, tempName); String strDir(sourceDir); size_t pos = strDir.find_last_of ( '\\' ); if ( String::npos == pos ) pos = strDir.find_last_of ( '/' ); String strFolderName = strDir.substr ( pos + 1 ); String strParentDir = strDir.substr(0, pos); // Compress the file @2 if ( ( nErr = file_compress ( strParentDir.c_str(), strFolderName.c_str(), ".CAT", extName, outmode ) ) != 0 ) { free(joinHdr); String msg = String("Failed to compress ") + tempName; throw std::exception ( msg.c_str() ); return nErr; } } } free(joinHdr); joinHdr = NULL; } else throw std::exception("Insufficient memory"); // For debugging only #ifdef DEBUG_MODE printHeader (stdout,joinHdr); #endif return errno; }
/* ======================================================================== PURPOSE : */ int joinFiles (const char *sourceDir, const char *sourceName, const char *extName) { stJAndSHeader *joinHdr = NULL; FILE *fileHdl = NULL; char destName[_MAX_DIR], tempName[_MAX_DIR]; char outmode[] = "wb6 "; short nErr; // Clear any outstanding errors errno = EZERO; // Get memory for the join header structure if ((joinHdr = (stJAndSHeader*)malloc(sizeof(stJAndSHeader))) != NULL) { // Populate the header with all the match files if (genHeader (sourceDir, sourceName, extName, joinHdr, 0)) //@3 files { // Clear any outstanding errors errno = EZERO; // Generate the destination name if (strlen(sourceDir)) sprintf (destName, "%s\\%s%s", sourceDir, sourceName, extName); else sprintf (destName, ".\\%s%s", sourceName, extName); // Open the join file... if ((fileHdl = fopen (destName, "wb")) != NULL) { // ... and join in all the files. writeHeader ( joinHdr, fileHdl); concatFiles ( sourceDir, joinHdr, fileHdl); fclose (fileHdl); // Rename file as a temporary file if (strlen(sourceDir)) sprintf (tempName, "%s\\%s%s", sourceDir, sourceName, ".CAT"); else sprintf (tempName, ".\\%s%s", sourceName, ".CAT"); rename (destName, tempName); // Compress the file @2 if ((nErr = file_compress (sourceDir, sourceName, ".CAT", extName, outmode)) != 0) { free(joinHdr); String msg = String("Failed to compress ") + sourceName; throw std::exception ( msg.c_str() ); return nErr; } } } free(joinHdr); joinHdr = NULL; } else throw std::exception( "Insufficient memory" ); // For debugging only #ifdef DEBUG_MODE printHeader (stdout,joinHdr); #endif return errno; }