void settings_import_music (const gchar *path) { GtkWidget *button; gchar *text; button = interface_get_widget ("button_settings_import_now"); gtk_widget_set_sensitive (button, FALSE); text = g_strdup_printf ("Starte Import von %s", path); settings_import_messages_add (text); g_debug ("%s", text); // Starte Scan recursive_dir (path); text = g_strdup_printf ("Import beendet!"); settings_import_messages_add (text); g_debug ("%s", text); gtk_widget_set_sensitive (button, TRUE); }
// Rekursiv durch ein Verzeichnis loopen void recursive_dir (const gchar *path) { GDir *dir; const gchar *dirname, *full_path; if ((dir = g_dir_open (path, 0, NULL))) { while ((dirname = g_dir_read_name (dir))) { /* This should be useless, but we'd better keep it for security */ g_assert (strcmp (dirname, ".") != 0); g_assert (strcmp (dirname, "..") != 0); if (strcmp (dirname, ".") == 0 || strcmp (dirname, "..") == 0) { continue; } // Ganzen Pfad zusammenstellen full_path = g_build_filename (path, dirname, NULL); // Export Verzeichnis ebenfalls ignorieren if (strcmp (g_strdup_printf("%s/", full_path), get_music_dir ()) == 0) { continue; } // Update UI while (gtk_events_pending()) { gtk_main_iteration(); } recursive_dir (full_path); g_free ((gchar *) full_path); } g_dir_close (dir); } if (g_file_test(path, G_FILE_TEST_IS_REGULAR)) { import_file (path); } return; }
int recursive_dir(u8 *filedir, int filedirsz) { int plen, namelen, ret = -1; #ifdef WIN32 static int winnt = -1; OSVERSIONINFO osver; WIN32_FIND_DATA wfd; HANDLE hFind = INVALID_HANDLE_VALUE; if(winnt < 0) { osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); GetVersionEx(&osver); if(osver.dwPlatformId >= VER_PLATFORM_WIN32_NT) { winnt = 1; } else { winnt = 0; } } plen = strlen(filedir); if((plen + 4) >= filedirsz) goto quit; strcpy(filedir + plen, "\\*.*"); plen++; if(winnt) { // required to avoid problems with Vista and Windows7! hFind = FindFirstFileEx(filedir, FindExInfoStandard, &wfd, FindExSearchNameMatch, NULL, 0); } else { hFind = FindFirstFile(filedir, &wfd); } if(hFind == INVALID_HANDLE_VALUE) goto quit; do { if(!strcmp(wfd.cFileName, ".") || !strcmp(wfd.cFileName, "..")) continue; namelen = strlen(wfd.cFileName); if((plen + namelen) >= filedirsz) goto quit; //strcpy(filedir + plen, wfd.cFileName); memcpy(filedir + plen, wfd.cFileName, namelen); filedir[plen + namelen] = 0; if(wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { if(recursive_dir(filedir, filedirsz) < 0) goto quit; } else { add_files(filedir, wfd.nFileSizeLow, NULL); } } while(FindNextFile(hFind, &wfd)); ret = 0; quit: if(hFind != INVALID_HANDLE_VALUE) FindClose(hFind); #else struct stat xstat; struct dirent **namelist; int n, i; n = scandir(filedir, &namelist, NULL, NULL); if(n < 0) { if(stat(filedir, &xstat) < 0) { fprintf(stderr, "**** %s", filedir); STD_ERR; } add_files(filedir, xstat.st_size, NULL); return(0); } plen = strlen(filedir); if((plen + 1) >= filedirsz) goto quit; strcpy(filedir + plen, "/"); plen++; for(i = 0; i < n; i++) { if(!strcmp(namelist[i]->d_name, ".") || !strcmp(namelist[i]->d_name, "..")) continue; namelen = strlen(namelist[i]->d_name); if((plen + namelen) >= filedirsz) goto quit; //strcpy(filedir + plen, namelist[i]->d_name); memcpy(filedir + plen, namelist[i]->d_name, namelen); filedir[plen + namelen] = 0; if(stat(filedir, &xstat) < 0) { fprintf(stderr, "**** %s", filedir); STD_ERR; } if(S_ISDIR(xstat.st_mode)) { if(recursive_dir(filedir, filedirsz) < 0) goto quit; } else { add_files(filedir, xstat.st_size, NULL); } free(namelist[i]); } ret = 0; quit: for(; i < n; i++) free(namelist[i]); free(namelist); #endif filedir[plen - 1] = 0; return(ret); }
int main(int argc, char *argv[]) { files_t *files = NULL; // scan int outdirlen = 0, curr_file = 0, input_total_files = 0; u8 filedir[PATHSZ + 1] = "", outdir[PATHSZ + 1] = "", *p = NULL; u32 bufflen, filelen; int i, forceenc = 0, encver = 1; u8 *filebuff, *buff, *in_file, *out_file; setbuf(stdout, NULL); setbuf(stderr, NULL); fputs("\n" "Race WTCC files encrypter/decrypter " VER "\n" "by Luigi Auriemma\n" "e-mail: [email protected]\n" "web: aluigi.org\n" "\n", stdout); #ifdef WIN32 // scan + gui mywnd = GetForegroundWindow(); if(GetWindowLong(mywnd, GWL_WNDPROC)) { for(i = 1; i < argc; i++) { if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) { break; } } i = 2 - (argc - i); if(i > 0) { fprintf(stderr, "- GUI mode activated, remember that the tool works also from command-line\n" " where are available various other options and the encryption mode\n" "\n"); buff = calloc(argc + i + 1, sizeof(char *)); if(!buff) STD_ERR; memcpy(buff, argv, sizeof(char *) * argc); argv = (void *)buff; argc -= (2 - i); if(i >= 2) argv[argc + 0] = get_file("select the input file to decrypt, type \"\" for the whole folder and subfolders", 1); if(i >= 1) argv[argc + 1] = get_file("select the output file or folder (type \"\") where decrypting the files", 1); // multi is not used, needed for "" argc += 2; } } #endif if(argc < 3) { printf("\n" "Usage: %s [options] <input_file/folder> <output_file/folder>\n" "\n" "Options:\n" "-o overwrite output file if already exists without prompting\n" "-v VER specify the file version for encryption, default %u\n" "-e d/e this option is here only for compatibility reasons, it allows you\n" " to force decryption 'd' or encryption 'e'\n" "-k GAME select the specific key for the specific GAME which uses a non\n" " default key, the following is the list of games (example -k volvo):\n" " raceroom\n" " volvo\n" "-F W filter the input files using the W wildcard, example -F \"*.gmt\"\n" "-V debug\n" "\n" "The encryption or decryption function is automatically chosen by the tool\n" "after having checked if the file is encrypted or not, use -e to override it.\n" "Note that -k volvo worked also with some old versions of RaceRoom.\n" "For the JCA files of RaceRoom use QuickBMS and the relative script:\n" " http://quickbms.aluigi.org\n" "\n", argv[0], encver); std_err(""); } argc -= 2; for(i = 1; i < argc; i++) { if(((argv[i][0] != '-') && (argv[i][0] != '/')) || (strlen(argv[i]) != 2)) { printf("\nError: recheck your options (%s is not valid)\n", argv[i]); std_err(""); } switch(argv[i][1]) { case 'o': overwrite = 1; break; case 'v': encver = atoi(argv[++i]); break; case 'e': forceenc = tolower(argv[++i][0]); break; case 'k': customkey = argv[++i]; break; case 'F': filter_in_files = argv[++i]; break; case 'V': debug = 1; break; default: { printf("\nError: wrong command-line argument (%s)\n\n", argv[i]); std_err(""); break; } } } if(customkey) { if(!stricmp(customkey, "volvo")) { customkey = (u8 *)volvo_key; customkeylen = sizeof(volvo_key); } else if(!stricmp(customkey, "roomrace") || !stricmp(customkey, "raceroom")) { customkey = (u8 *)raceroom_key; customkeylen = sizeof(raceroom_key); } else { printf("- unknown game specified with the -k option, I will consider it a hex key\n"); customkey = strdup(customkey); // not needed but good customkeylen = string2key(customkey); } } in_file = argv[argc]; out_file = argv[argc + 1]; // scan #ifdef WIN32 if(GetWindowLong(mywnd, GWL_WNDPROC) && fin[strlen(fin) + 1]) { // check if there are files after the folder i = snprintf(filedir, PATHSZ, "%s%c", fin, PATHSLASH); if((i < 0) || (i >= PATHSZ)) std_err(""); for(p = fin;;) { p += strlen(p) + 1; if(!*p) break; mystrcpy(filedir + i, p, PATHSZ - i); add_files(filedir, 0, NULL); } } else #endif if(check_is_dir(fin)) { printf("- start the scanning of the input folder: %s\n", fin); //strcpy(filedir, "."); // if you enable it you must add " + 2" to each add_files mystrcpy(filedir, fin, PATHSZ); recursive_dir(filedir, PATHSZ); } if(filedir[0]) { files = add_files(NULL, 0, &input_total_files); curr_file = 0; if(input_total_files <= 0) { printf("\nError: the input folder is empty\n"); myexit(-2); } } if(check_is_dir(fout)) { outdirlen = snprintf(outdir, PATHSZ, "%s%c", fout, PATHSLASH); if((outdirlen < 0) || (outdirlen >= PATHSZ)) std_err(""); fout = outdir; } int finlen = strlen(fin); redo_scan: if(files) { fin = files[curr_file].name; curr_file++; fprintf(stderr, "\n"); } if(outdirlen) { if(files) { for(p = fin + finlen; *p; p++) { if((*p != '\\') && (*p != '/')) break; } } else { p = strrchr(fin, '\\'); if(!p) p = strrchr(fin, '/'); if(p) { p++; } else { p = fin; } } mystrcpy(outdir + outdirlen, p, PATHSZ - outdirlen); } redo: filebuff = fd_read(in_file, &filelen); if((memcmp(filebuff, "\x0f\xb1\xff\xff", 4) && memcmp(filebuff, "\x1f\x8b\x08", 3) && (forceenc != 'd')) || (forceenc == 'e')) { printf("- perform encryption:\n"); buff = wtcc_encrypt(filebuff, filelen, &bufflen, encver); } else { printf("- perform decryption:\n"); buff = wtcc_decrypt(filebuff, filelen, &bufflen); } if(!buff && auto_try) { auto_try++; // 1 switch(auto_try) { case 2: customkey = (u8 *)raceroom_key; customkeylen = sizeof(raceroom_key); break; case 3: customkey = (u8 *)volvo_key; customkeylen = sizeof(volvo_key); break; default: auto_try = 0; break; } free(filebuff); printf("\n"); if(auto_try) goto redo; } fd_write(out_file, buff, bufflen); printf("- %u bytes written\n", bufflen); if(files && (curr_file < input_total_files)) { // scan if(!((buff >= filebuff) && (buff <= (filebuff + 16)))) free(buff); free(filebuff); goto redo_scan; } fprintf(stderr, "- done\n"); std_err(""); // scan return(0); }