int handle_file(const char *file, struct config_opts_t *config_opts) { const char *dest_dir = config_opts->dest_dir; const char *file_name = basename(strdup(file)); char dest_file[1024] = ""; char lz4pack[1024] = ""; if (check_lzo_header(file)) { constructPath(dest_file, dest_dir, file_name, ".lzounpack"); printf("Extracting LZO file to: %s\n", dest_file); if (lzo_unpack(file, dest_file) == 0) { handle_file(dest_file, config_opts); return EXIT_SUCCESS; } } else if (is_nfsb(file)) { constructPath(dest_file, dest_dir, file_name, ".unnfsb"); printf("Extracting nfsb image to: %s.\n\n", dest_file); unnfsb(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if (is_lz4(file)) { constructPath(dest_file, dest_dir, file_name, ".unlz4"); printf("UnLZ4 file to: %s\n", dest_file); decode_file(file, dest_file); return EXIT_SUCCESS; } else if (is_squashfs(file)) { constructPath(dest_file, dest_dir, file_name, ".unsquashfs"); printf("Unsquashfs file to: %s\n", dest_file); rmrf(dest_file); unsquashfs(file, dest_file); return EXIT_SUCCESS; } else if (is_cramfs_image(file)) { constructPath(dest_file, dest_dir, file_name, ".uncramfs"); printf("Uncramfs file to: %s\n", dest_file); rmrf(dest_file); uncramfs(dest_file, file); return EXIT_SUCCESS; } else if (isFileEPK2(file)) { extractEPK2file(file, config_opts); return EXIT_SUCCESS; } else if (isFileEPK1(file)) { extract_epk1_file(file, config_opts); return EXIT_SUCCESS; } else if (is_kernel(file)) { constructPath(dest_file, dest_dir, file_name, ".unpaked"); printf("Extracting boot image to: %s.\n\n", dest_file); extract_kernel(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if(isSTRfile(file)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nConverting %s file to TS: %s\n", file, dest_file); convertSTR2TS(file, dest_file, 0); return EXIT_SUCCESS; } else if(!memcmp(&file[strlen(file)-3], "PIF", 3)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nProcessing PIF file: %s\n", file); processPIF(file, dest_file); return EXIT_SUCCESS; } else if(symfile_load(file) == 0) { constructPath(dest_file, dest_dir, file_name, ".idc"); printf("Converting SYM file to IDC script: %s\n", dest_file); symfile_write_idc(dest_file); return EXIT_SUCCESS; } return EXIT_FAILURE; }
int handle_file(const char *file, struct config_opts_t *config_opts) { const char *dest_dir = config_opts->dest_dir; const char *file_name = basename(strdup(file)); char dest_file[1024] = ""; char lz4pack[1024] = ""; if (check_lzo_header(file)) { constructPath(dest_file, dest_dir, file_name, ".lzounpack"); printf("Extracting LZO file to: %s\n", dest_file); if (lzo_unpack(file, dest_file) == 0) { handle_file(dest_file, config_opts); return EXIT_SUCCESS; } } else if (is_nfsb(file)) { constructPath(dest_file, dest_dir, file_name, ".unnfsb"); printf("Extracting nfsb image to: %s.\n\n", dest_file); unnfsb(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if (is_lz4(file)) { constructPath(dest_file, dest_dir, file_name, ".unlz4"); printf("UnLZ4 file to: %s\n", dest_file); decode_file(file, dest_file); return EXIT_SUCCESS; } else if (is_squashfs(file)) { constructPath(dest_file, dest_dir, file_name, ".unsquashfs"); printf("Unsquashfs file to: %s\n", dest_file); rmrf(dest_file); unsquashfs(file, dest_file); return EXIT_SUCCESS; } else if (is_gzip(file)) { constructPath(dest_file, dest_dir, "", ""); printf("Extracting gzip file %s\n", file_name); strcpy(dest_file, file_uncompress_origname((char *)file, dest_file)); return EXIT_SUCCESS; } else if(is_cramfs_image(file, "be")) { constructPath(dest_file, dest_dir, file_name, ".cramswap"); printf("Swapping cramfs endian for file %s\n",file); cramswap(file, dest_file); return EXIT_SUCCESS; } else if(is_cramfs_image(file, "le")) { constructPath(dest_file, dest_dir, file_name, ".uncramfs"); printf("Uncramfs %s to folder %s\n", file, dest_file); rmrf(dest_file); uncramfs(dest_file, file); return EXIT_SUCCESS; } else if (isFileEPK2(file)) { extractEPK2file(file, config_opts); return EXIT_SUCCESS; } else if (isFileEPK1(file)) { extract_epk1_file(file, config_opts); return EXIT_SUCCESS; } else if (is_kernel(file)) { constructPath(dest_file, dest_dir, file_name, ".unpaked"); printf("Extracting boot image to: %s.\n\n", dest_file); extract_kernel(file, dest_file); handle_file(dest_file, config_opts); return EXIT_SUCCESS; } else if(isPartPakfile(file)) { constructPath(dest_file, dest_dir, remove_ext(file_name), ".txt"); printf("Saving Partition info to: %s\n", dest_file); dump_partinfo(file, dest_file); return EXIT_SUCCESS; } else if(is_jffs2(file)) { constructPath(dest_file, dest_dir, file_name, ".unjffs2"); printf("jffs2extract %s to folder %s\n", file, dest_file); rmrf(dest_file); jffs2extract(file, dest_file, "1234"); return EXIT_SUCCESS; } else if(isSTRfile(file)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nConverting %s file to TS: %s\n", file, dest_file); convertSTR2TS(file, dest_file, 0); return EXIT_SUCCESS; } else if(!memcmp(&file[strlen(file)-3], "PIF", 3)) { constructPath(dest_file, dest_dir, file_name, ".ts"); setKey(); printf("\nProcessing PIF file: %s\n", file); processPIF(file, dest_file); return EXIT_SUCCESS; } else if(symfile_load(file) == 0) { constructPath(dest_file, dest_dir, file_name, ".idc"); printf("Converting SYM file to IDC script: %s\n", dest_file); symfile_write_idc(dest_file); return EXIT_SUCCESS; } return EXIT_FAILURE; }
int __wrap_main(int argc, char *argv[], char *envp[]) { int c; char *config_file = NULL; char *log_file = NULL; bool daemon = false; while ((c = getopt(argc, argv, "c:dhl:vV")) != -1) { switch (c) { case 'c': config_file = strdup(optarg); break; case 'd': daemon = true; break; case 'h': usage(); _exit(EXIT_SUCCESS); case 'l': log_file = strdup(optarg); break; case 'v': ++verbose; break; case 'V': printf("%s\n", openrelease_version()); _exit(EXIT_SUCCESS); case '?': usage(); _exit(EXIT_FAILURE); default: say_error("unmatched option: -%c", c); _exit(EXIT_FAILURE); } } create_log(log_file); config_init(config_file); if (getenv("OPENRELEASE_STAGE2") == NULL) { if (daemon) { if (daemonize(1, 0) == -1) { say_error("can't daemonize"); _exit(EXIT_FAILURE); } } if (stdio_wrap(config.input, config.output) == -1) { say_error("stdio_wrap failed"); _exit(EXIT_FAILURE); } putenv("OPENRELEASE_STAGE2=1"); execvp(argv[0], argv); } mmaps_init(); symfile_load(config.symfile); wrap_init(); debug_init(); key_action_init(); say_info("dive into RELEASE"); unsetenv("LD_PRELOAD"); argc = 1; if (optind != argc) { memmove(&argv[1], &argv[optind], (optind - argc) * sizeof(argv[0])); argc += optind - argc; } argv[argc] = NULL; __real_main(argc, argv, envp); _exit(EXIT_SUCCESS); return 0; }