Ejemplo n.º 1
0
int main(int argc, const char *argv[])
{
    if (argc < 2) {
        fprintf(stderr, "usage: %s <file>\n", argv[0]);
        return -1;
    }
    const char* innerFile = "";
    if (argc == 3) innerFile = argv[2];

    zzip_error_t errcode;
    ZZIP_DIR* dir = zzip_dir_open(argv[1], &errcode);
    if (dir == NULL) {
        fprintf(stderr, "zzip_operdir failed: %s\n", zzip_strerror(errcode));
        return -1;
    }

    // scan files
    ZZIP_DIRENT* dirent = zzip_readdir(dir);
    while (dirent) {
        printf("%s, compression %d, size %d/%d\n",
            dirent->d_name, dirent->d_compr, dirent->d_csize, dirent->st_size);

        checkFile(dir, dirent, innerFile);
        dirent = zzip_readdir(dir);
    }

    int err = zzip_closedir(dir);
    if (err != 0) {
        fprintf(stderr, "zzip_closedir failed: %s\n", zzip_strerror_of(dir));
        return -1;
    }

    return 0;
}
Ejemplo n.º 2
0
void * ZIPROMReaderInit(const char * filename)
{
	ZZIP_DIR * dir = zzip_opendir(filename);
	ZZIP_DIRENT * dirent = zzip_readdir(dir);
	if (dir != NULL)
	{
		char tmp1[1024];
		char tmp2[1024];
		memset(tmp1,0,sizeof(tmp1));
		memset(tmp2,0,sizeof(tmp2));
		strncpy(tmp1, filename, strlen(filename) - 4);
		sprintf(tmp2, "%s/%s", tmp1, dirent->d_name);
		return zzip_fopen(tmp2, "rb");
	}
	return NULL;
}
Ejemplo n.º 3
0
Archivo: luazip.c Proyecto: msva/luazip
static int zip_readfile (lua_State *L) {
  ZZIP_DIRENT* ent = NULL;
  ZZIP_DIR* uf = NULL;

  uf = *(ZZIP_DIR**)lua_touserdata(L, lua_upvalueindex(1));
  if (uf == NULL)  /* file is already closed? */
    luaL_error(L, "file is already closed");

  ent = zzip_readdir(uf);

  if (ent == NULL)
    return 0;

  lua_newtable(L);
  lua_pushstring(L, "compressed_size"); lua_pushnumber(L, ent->d_csize); lua_settable(L, -3);
  lua_pushstring(L, "compression_method"); lua_pushnumber(L, ent->d_compr); lua_settable(L, -3);
  lua_pushstring(L, "uncompressed_size"); lua_pushnumber(L, ent->st_size); lua_settable(L, -3);
  lua_pushstring(L, "filename"); lua_pushstring(L, ent->d_name); lua_settable(L, -3);

  return 1;
}
Ejemplo n.º 4
0
//// read the directory entries of given dir/archive
static void b_zzip_read_dirent(task *tsk, pntr *argstack)
{
	char *fileName;
	pntr p = argstack[0];
	int badtype;
	
	CHECK_ARG(0, CELL_CONS);
	if((badtype = array_to_string(p, &fileName)) >= 0){
		set_error(tsk, "error1: argument is not a string (contains non-char: %s)", cell_types[badtype]);
		return;
	}

    ZZIP_DIR * dir;
    ZZIP_DIRENT * d;
  
    dir = zzip_opendir(fileName);
    if (! dir){
    	fprintf (stderr, "did not open %s: ", fileName);
    	set_error(tsk, "error1: could not handle file: %s", fileName);
		return;
    }

    char *singleFileName;
    char *compressionType;
    int fSize = 20;
    char fileSize[fSize];
    char compressedSize[fSize];
    pntr pSingleFileName, pCompressionType, pFileSize, pCompressedSize;
    pntr preList, singleList;
    int counter = 0;
    
	/* read each dir entry, a list for each file */
	while ((d = zzip_readdir (dir))){
		counter++;
		/* orignal size / compression-type / compression-ratio / filename */
		singleFileName = d->d_name;
		pSingleFileName = string_to_array(tsk, singleFileName);	//// convert the string to cons list
		
//		sprintf(compressionType, "%s ", zzip_compr_str(d->d_compr)); //// NOTE: executing this func will change the tsk->steamstack, very weird
																	//// NOTE: overflow caused here
		compressionType = (char *)zzip_compr_str(d->d_compr);
		pCompressionType = string_to_array(tsk, compressionType);
		
//		snprintf(fileSize, 5, "%d ", d->st_size);	//// NOTE: executing this func will change the tsk->steamstack, very weird
		format_double(fileSize, fSize, d->st_size);
		pFileSize = string_to_array(tsk, fileSize);

//		sprintf(compressedSize, "%d ", d->d_csize);
		format_double(compressedSize, fSize, d->d_csize);
		pCompressedSize = string_to_array(tsk, compressedSize);
		
//		printf("cell type: %s \t", cell_type(preList));
		//// link the cons lists to form a new list
//		singleList = connect_lists(tsk, &pSingleFileName, &pCompressionType);
//		singleList = connect_lists(tsk, &singleList, &pFileSize);
//		singleList = connect_lists(tsk, &singleList, &pCompressedSize);
		
		//// make cons from the last element to the beginning element
		singleList = make_cons(tsk, pCompressedSize, tsk->globnilpntr);
		singleList = make_cons(tsk, pFileSize, singleList);
		singleList = make_cons(tsk, pCompressionType, singleList);
		singleList = make_cons(tsk, pSingleFileName, singleList);
		
		
		if(counter == 1){
			preList = make_cons(tsk, singleList, tsk->globnilpntr);
//			printf("cell type: %s \t", cell_type(preList));
		}else{
			preList = make_cons(tsk, singleList, preList);
//			printf("cell type: %s \n", cell_type(preList));
		}
	}

	argstack[0] = preList;
//	printf("cell type: %s \n", cell_type(argstack[0]));
}