コード例 #1
0
ファイル: aokts.cpp プロジェクト: DoctorWillCU/aokts
// TODO: fix alternate cohesion crap
void OnCompressOrDecompress(HWND sheet, bool compress)
{
	int size, ret;
	char path[_MAX_PATH];

	if (!GetOpenFileNameA(sheet, path, sizeof(path)))
		return;

	size = fsize(path);
	std::vector<unsigned char> buffer(size);

	AutoFile fIn(path, "rb");
	fread(&buffer[0], sizeof(char), size, fIn.get()); // contiguous
	fIn.close();

	path[0] = '\0';   // don't pre-fill path
	if (!GetSaveFileNameA(sheet, path, sizeof(path)))
		return;

	AutoFile fOut(path, "wb");

	if (compress)
		ret = deflate_file(&buffer[0], size, fOut.get());
	else
		ret = inflate_file(&buffer[0], size, fOut.get());

	fOut.close();

	if (ret >= 0)
		MessageBox(sheet, "Operation completed successfully.",
		"Raw Compression/Decompression", MB_OK);
	else
		MessageBox(sheet, "Operation failed.",
		"Raw Compression/Decompression", MB_ICONWARNING);
}
コード例 #2
0
/*
 * Read the manifest from the specified jar file and fill in the manifest_info
 * structure with the information found within.
 *
 * Error returns are as follows:
 *    0 Success
 *   -1 Unable to open jarfile
 *   -2 Error accessing the manifest from within the jarfile (most likely
 *      a manifest is not present, or this isn't a valid zip/jar file).
 */
int
JLI_ParseManifest(char *jarfile, manifest_info *info)
{
    int     fd;
    zentry  entry;
    char    *lp;
    char    *name;
    char    *value;
    int     rc;
    char    *splashscreen_name = NULL;

    if ((fd = open(jarfile, O_RDONLY
#ifdef O_LARGEFILE
        | O_LARGEFILE /* large file mode */
#endif
#ifdef O_BINARY
        | O_BINARY /* use binary mode on windows */
#endif
        )) == -1) {
        return (-1);
    }
    info->manifest_version = NULL;
    info->main_class = NULL;
    info->jre_version = NULL;
    info->jre_restrict_search = 0;
    info->splashscreen_image_file_name = NULL;
    if (rc = find_file(fd, &entry, manifest_name) != 0) {
        close(fd);
        return (-2);
    }
    manifest = inflate_file(fd, &entry, NULL);
    if (manifest == NULL) {
        close(fd);
        return (-2);
    }
    lp = manifest;
    while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) {
        if (JLI_StrCaseCmp(name, "Manifest-Version") == 0)
            info->manifest_version = value;
        else if (JLI_StrCaseCmp(name, "Main-Class") == 0)
            info->main_class = value;
        else if (JLI_StrCaseCmp(name, "JRE-Version") == 0)
            info->jre_version = value;
        else if (JLI_StrCaseCmp(name, "JRE-Restrict-Search") == 0) {
            if (JLI_StrCaseCmp(value, "true") == 0)
                info->jre_restrict_search = 1;
        } else if (JLI_StrCaseCmp(name, "Splashscreen-Image") == 0) {
            info->splashscreen_image_file_name = value;
        }
    }
    close(fd);
    if (rc == 0)
        return (0);
    else
        return (-2);
}
コード例 #3
0
ファイル: Scenario.cpp プロジェクト: ajoslin/LuaTrig
bool Scenario::open()
{
	printf("[O] Opening scenario %s\n", path.c_str());

	FILE *scx = fopen(path.c_str(), "rb");
	if (scx==NULL)
		return false;

	long scx_filesize = fsize(path.c_str());

	long bytes_read = 0;

	char *headerversion= new char[4];
	READ(&headerversion, sizeof(char), 4, scx); //READ macro adds to bytes_read

	READ(&headerlength, sizeof(unsigned long), 1, scx);

	//read geader
	char *header = new char[headerlength];
	READ(header, 1, headerlength, scx);

	FILE *headerfile = fopen("header.hex", "wb");
	fseek(scx, 0, SEEK_SET);
	for (int i=0; i<headerlength+8; i++)
		fputc(fgetc(scx), headerfile);
	fclose(headerfile);


	printf("\t[O] headerlength: %d\n", headerlength);

	printf("\t[O] bytes_read: %d\n", bytes_read);

	//COMPRESSED DATA
	//get length of compressed data
	long clen = scx_filesize - bytes_read;

	printf("\t[O] scx_filesize: %d\n", scx_filesize);
	printf("\t[O] clen: %d\n", clen);

	Bytef *cdata = new Bytef[clen];
	READ(cdata, sizeof(char), clen, scx);

	FILE *out = fopen("scndata.hex", "wb");

	inflate_file(cdata, clen, out);

	fclose(scx);
	fclose(out);

	printf("\t[O] End open\n");

	return true;
}
コード例 #4
0
ファイル: unzip.c プロジェクト: Ezio-PS/mame2003-libretro
/* Read UNcompressed data
   out:
	data UNcompressed data
   return:
	==0 success
	<0 error
*/
int readuncompresszip(ZIP* zip, struct zipent* ent, char* data) {
	if (ent->compression_method == 0x0000) {
		/* file is not compressed, simply stored */

		/* check if size are equal */
		if (ent->compressed_size != ent->uncompressed_size) {
			errormsg("Wrong uncompressed size in store compression", ERROR_CORRUPT,zip->zip);
			return -3;
		}

		return readcompresszip(zip,ent,data);
	} else if (ent->compression_method == 0x0008) {
		/* file is compressed using "Deflate" method */
		if (ent->version_needed_to_extract > 0x14) {
			errormsg("Version too new", ERROR_UNSUPPORTED,zip->zip);
			return -2;
		}

		if (ent->os_needed_to_extract != 0x00) {
			errormsg("OS not supported", ERROR_UNSUPPORTED,zip->zip);
			return -2;
		}

		if (ent->disk_number_start != zip->number_of_this_disk) {
			errormsg("Cannot span disks", ERROR_UNSUPPORTED,zip->zip);
			return -2;
		}

		/* read compressed data */
		if (seekcompresszip(zip,ent)!=0) {
			return -1;
		}

		/* configure inflate */
		if (inflate_file( zip->fp, ent->compressed_size, (unsigned char*)data, ent->uncompressed_size))
		{
			errormsg("Inflating compressed data", ERROR_CORRUPT, zip->zip);
			return -3;
		}

		return 0;
	} else {
		errormsg("Compression method unsupported", ERROR_UNSUPPORTED, zip->zip);
		return -2;
	}
}
コード例 #5
0
/*
 * Opens the jar file and unpacks the specified file from its contents.
 * Returns NULL on failure.
 */
void *
JLI_JarUnpackFile(const char *jarfile, const char *filename, int *size) {
    int     fd;
    zentry  entry;
    void    *data = NULL;

    fd = open(jarfile, O_RDONLY
#ifdef O_BINARY
	| O_BINARY /* use binary mode on windows */
#endif
	);
    if (fd != -1 && find_file(fd, &entry, filename) == 0) {
        data = inflate_file(fd, &entry, size);
    }
    close(fd);
    return (data);
}
コード例 #6
0
/*
 * Iterate over the manifest of the specified jar file and invoke the provided
 * closure function for each attribute encountered.
 *
 * Error returns are as follows:
 *    0 Success
 *   -1 Unable to open jarfile
 *   -2 Error accessing the manifest from within the jarfile (most likely
 *      this means a manifest is not present, or it isn't a valid zip/jar file).
 */
int
JLI_ManifestIterate(const char *jarfile, attribute_closure ac, void *user_data)
{
    int     fd;
    zentry  entry;
    char    *mp;        /* manifest pointer */
    char    *lp;        /* pointer into manifest, updated during iteration */
    char    *name;
    char    *value;
    int     rc;

    if ((fd = open(jarfile, O_RDONLY
#ifdef O_LARGEFILE
        | O_LARGEFILE /* large file mode */
#endif
#ifdef O_BINARY
        | O_BINARY /* use binary mode on windows */
#endif
        )) == -1) {
        return (-1);
    }

    if (rc = find_file(fd, &entry, manifest_name) != 0) {
        close(fd);
        return (-2);
    }

    mp = inflate_file(fd, &entry, NULL);
    if (mp == NULL) {
        close(fd);
        return (-2);
    }

    lp = mp;
    while ((rc = parse_nv_pair(&lp, &name, &value)) > 0) {
        (*ac)(name, value, user_data);
    }
    free(mp);
    close(fd);
    return (rc == 0) ? 0 : -2;
}
コード例 #7
0
/*
 * Opens the jar file and unpacks the specified file from its contents.
 * Returns NULL on failure.
 */
void *
JLI_JarUnpackFile(const char *jarfile, const char *filename, int *size) {
    int     fd;
    zentry  entry;
    void    *data = NULL;

    if ((fd = open(jarfile, O_RDONLY
#ifdef O_LARGEFILE
        | O_LARGEFILE /* large file mode */
#endif
#ifdef O_BINARY
        | O_BINARY /* use binary mode on windows */
#endif
        )) == -1) {
        return NULL;
    }
    if (find_file(fd, &entry, filename) == 0) {
        data = inflate_file(fd, &entry, size);
    }
    close(fd);
    return (data);
}
コード例 #8
0
ファイル: aokts.cpp プロジェクト: DoctorWillCU/aokts
/*
	ProcessCmdline: processes the command-line and returns whether to exit
*/
bool ProcessCmdline(char *cmdline)
{
	bool ret = true;
	char pathIn[_MAX_PATH], pathOut[_MAX_PATH];
	FILE *fileIn, *fileOut;
	int size, code;
	unsigned char *buffer;
	int c;

	switch (c = tolower(cmdline[1]))
	{
	case 'c':
	case 'u':
		cmdline += 2;
		cmdline = getCmdlinePath(cmdline, pathIn);
		if (!cmdline)
			break;
		cmdline = getCmdlinePath(cmdline, pathOut);
		if (!cmdline)
			break;

		if (c == 'c')
			printf("Compressing %s to %s... ", pathIn, pathOut);
		else
			printf("Decompressing %s to %s... ", pathIn, pathOut);

		size = fsize(pathIn);
		buffer = new unsigned char[size];
		if (!buffer)
		{
			printf_log("not enough memory.\n");
			break;
		}

		fileIn = fopen(pathIn, "rb");
		if (!fileIn)
		{
			printf_log("couldn\'t open input file\n");
			delete [] buffer;
			break;
		}
		fread(buffer, sizeof(char), size, fileIn);
		fclose(fileIn);

		fileOut = fopen(pathOut, "wb");
		if (!fileOut)
		{
			printf_log("couldn\'t open output file\n");
			delete [] buffer;
			break;
		}

		if (c == 'c')
			code = deflate_file(buffer, size, fileOut);
		else
			code = inflate_file(buffer, size, fileOut);

		fclose(fileOut);

		if (code >= 0)
			printf_log("done!\n");
		else
			printf_log("failed.\n");

		break;

	default:
		ret = false;
	}

	return ret;
}