Exemple #1
0
void processExtractedFile(char *filename, char *folderExtractTo, const char *PAKname) {
	char extractedFile[255] = "";
	int extracted = 0;
	if (is_lz4(filename)) {
		constructPath(extractedFile, folderExtractTo, PAKname, ".unlz4");
		printf("UnLZ4 %s to %s\n", filename, extractedFile);
		extracted = !decode_file(filename, extractedFile);
	} else {
		if (check_lzo_header(filename)) {
			constructPath(extractedFile, folderExtractTo, PAKname, ".unpacked");
			printf("LZOunpack %s to %s\n", filename, extractedFile);
			extracted = !lzo_unpack((const char*) filename, (const char*) extractedFile);
		} else {
	    		if (is_cramfs_image(filename)) {
				constructPath(extractedFile, folderExtractTo, PAKname, NULL);
				printf("Uncramfs %s to folder %s\n", filename, extractedFile);
				rmrf(extractedFile);
				uncramfs(extractedFile, filename);
				return;
			} else {
			    	if (is_kernel(filename)) {
					constructPath(extractedFile, folderExtractTo, PAKname, ".unpaked");
					printf("Extracting kernel %s to %s\n", filename, extractedFile);
					extract_kernel(filename, extractedFile);
					extracted = 1;
	    			} else {
					if (is_nfsb(filename)) {
						constructPath(extractedFile, folderExtractTo, PAKname, ".unnfsb");
						printf("Unnfsb %s to %s\n", filename, extractedFile);
						unnfsb(filename, extractedFile);
						extracted = 1;
					} 
				}
			}
		}
	}
	if (strcmp(PAKname, "patc") != 0 && strcmp(PAKname, "extr") != 0) {
		if (is_squashfs(filename)) {
			constructPath(extractedFile, folderExtractTo, PAKname, NULL);
			printf("Unsquashfs %s to folder %s\n", filename, extractedFile);
			rmrf(extractedFile);
			unsquashfs(filename, extractedFile);
			return;
		}
	} else {
		printf("!!!Skipping unsquashfs (%s) as it doesn't know how to handle it...\n", PAKname);
		return;
	}
	if (extracted) processExtractedFile(extractedFile, folderExtractTo, PAKname);
}
Exemple #2
0
void sba_create_kernel(struct opencl_info *info, char *kernel_file, char *kernel_name, int kernel_index)
{
	size_t src_size = 0;
	cl_int error;

	// Extract the kernel as a string
	char *kernel_string = extract_kernel(kernel_file);
	src_size = strlen(kernel_string);

	// Create opencl program
	cl_program program = clCreateProgramWithSource(info->context, 1, &kernel_string, &src_size, &error);

	assert(error == CL_SUCCESS);

	// Build the opencl program
	error = clBuildProgram(program, 1, &(info->device), NULL, NULL, NULL);

	// Get build log
	char *build_log;
	size_t log_size;

	clGetProgramBuildInfo(program, info->device, CL_PROGRAM_BUILD_LOG, 0, NULL, &log_size);
	build_log = (char *)malloc((log_size+1)*sizeof(char));

	clGetProgramBuildInfo(program, info->device, CL_PROGRAM_BUILD_LOG, log_size, build_log, NULL);
	build_log[log_size] = '\0';

	printf("[sba_opencl] Build log: %s\n", build_log);

	free(build_log);
	free(kernel_string);

	cl_kernel sba_kernel = clCreateKernel(program, kernel_name, &error);
	if(error != CL_SUCCESS)
		printf("[sba_opencl] Error is: %d\n", error);
	
	assert(error == CL_SUCCESS);

	info->kernel[kernel_index] = sba_kernel;
}
Exemple #3
0
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;
}
Exemple #4
0
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;
}