int decrypt_dir(const char *dirName, unsigned char *key) { char buffer[PATH_SIZE]; DIR *dir; struct dirent *entry; dir = opendir(dirName); if (!dir) { perror("diropen"); exit(1); }; while ( (entry = readdir(dir)) != NULL) { if(entry->d_type != DT_DIR && strcmp(entry->d_name,".DS_Store")) { cnct(dirName,entry->d_name,buffer); decrypt_file(dirName,buffer,key); } if(entry->d_type == DT_DIR && strcmp(entry->d_name,"..") && strcmp(entry->d_name,".")) { cnct(dirName,entry->d_name,buffer); decrypt_dir(buffer, key); } } closedir(dir); return 0; }
static void decrypt_dir(char *sourcedir, char* destdir) { DIR *dir; struct dirent *dp; struct stat info; char src_path[1024], dst_path[1024]; dir = opendir(sourcedir); if (!dir) return; mkdir(destdir, 0777); while ((dp = readdir(dir)) != NULL) { if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, "..")) { // do nothing (straight logic) } else { sprintf(src_path, "%s/%s", sourcedir, dp->d_name); sprintf(dst_path, "%s/%s", destdir , dp->d_name); if (!stat(src_path, &info)) { if (S_ISDIR(info.st_mode)) { decrypt_dir(src_path, dst_path); } else if (S_ISREG(info.st_mode)) { if (is_self(src_path)) decrypt_and_dump_self(src_path, dst_path); } } } } closedir(dir); }
void dump_game(char *title_id, char *usb_path) { char base_path[64]; char src_path[64]; char dst_file[64]; char dst_app[64]; char dst_pat[64]; char dump_sem[64]; char comp_sem[64]; sprintf(src_path, "%s/.split", usb_path); int split = file_exists(src_path); sprintf(base_path, "%s/%s", usb_path, title_id); sprintf(dump_sem, "%s.dumping", base_path); sprintf(comp_sem, "%s.complete", base_path); unlink(comp_sem); touch_file(dump_sem); if (split) { sprintf(dst_app, "%s-app", base_path); sprintf(dst_pat, "%s-patch", base_path); } else { sprintf(dst_app, "%s", base_path); sprintf(dst_pat, "%s", base_path); } mkdir(dst_app, 0777); mkdir(dst_pat, 0777); sprintf(src_path, "/user/app/%s/app.pkg", title_id); notify("Extracting app package..."); unpkg(src_path, dst_app); sprintf(src_path, "/system_data/priv/appmeta/%s/nptitle.dat", title_id); sprintf(dst_file, "%s/sce_sys/nptitle.dat", dst_app); copy_file(src_path, dst_file); sprintf(src_path, "/system_data/priv/appmeta/%s/npbind.dat", title_id); sprintf(dst_file, "%s/sce_sys/npbind.dat", dst_app); copy_file(src_path, dst_file); sprintf(src_path, "/user/patch/%s/patch.pkg", title_id); if (file_exists(src_path)) { if (split) notify("Extracting patch package..."); else notify("Merging patch package..."); unpkg(src_path, dst_pat); sprintf(src_path, "/system_data/priv/appmeta/%s/nptitle.dat", title_id); sprintf(dst_file, "%s/sce_sys/nptitle.dat", dst_pat); copy_file(src_path, dst_file); sprintf(src_path, "/system_data/priv/appmeta/%s/npbind.dat", title_id); sprintf(dst_file, "%s/sce_sys/npbind.dat", dst_pat); copy_file(src_path, dst_file); } sprintf(src_path, "/mnt/sandbox/pfsmnt/%s-app0-nest/pfs_image.dat", title_id); notify("Extracting app image..."); unpfs(src_path, dst_app); sprintf(src_path, "/mnt/sandbox/pfsmnt/%s-patch0-nest/pfs_image.dat", title_id); if (file_exists(src_path)) { if (split) notify("Extracting patch image..."); else notify("Applying patch..."); unpfs(src_path, dst_pat); } sprintf(src_path, "/mnt/sandbox/pfsmnt/%s-app0", title_id); notify("Decrypting selfs..."); decrypt_dir(src_path, dst_app); sprintf(src_path, "/mnt/sandbox/pfsmnt/%s-patch0", title_id); if (file_exists(src_path)) { notify("Decrypting patch..."); decrypt_dir(src_path, dst_pat); } unlink(dump_sem); touch_file(comp_sem); }