示例#1
0
int ZIPROMReaderRead(void * file, void * buffer, u32 size)
{
#ifdef ZZIP_OLD_READ
	return zzip_read((ZZIP_FILE*)file, (char *) buffer, size);
#else
	return zzip_read((ZZIP_FILE*)file, buffer, size);
#endif
}
示例#2
0
/**
**	Seek on compressed input. (I hope newer libs support it directly)
**
**	@param file	File handle
**	@param offset	Seek position
**	@param whence	How to seek
*/
local void zzip_seek(ZZIP_FILE* file,unsigned offset,int whence __attribute__((unused)))
{
    char buf[32];

    while( offset>sizeof(buf) ) {
	zzip_read(file,buf,sizeof(buf));
	offset-=sizeof(buf);
    }
    zzip_read(file,buf,offset);
}
示例#3
0
文件: read_odf.c 项目: skm42/opendias
size_t getEntry(const char *name, char *contentFile, char **ptr) {

  size_t size=0;
  ZZIP_DIR *dir;
  ZZIP_DIRENT entry;
  ZZIP_FILE *file;
  char *buf;

  dir = zzip_dir_open(name, 0);
  if (!dir) {
    fprintf(stderr, "failed to open %s\n", name);
    return 0;
  }

  zzip_dir_read(dir, &entry);

  file = zzip_file_open(dir, contentFile, 0);

  (void)zzip_seek(file, 0, SEEK_END);
  size = zzip_tell(file);
  (void)zzip_seek(file, 0, SEEK_SET);
  buf = (char *)malloc(size+1);
  (void)zzip_read(file, buf, size);
  buf[size] = '\0';
  *ptr = buf;

  zzip_file_close(file);
  zzip_dir_close(dir);

  return size;
}
示例#4
0
/**
**	CLread		Library file read
**
**	@param file	CLFile pointer.
**	@param buf	Pointer to read the data to.
**	@param len	number of bytes to read.
*/
global int CLread(CLFile *file, void *buf, size_t len)
{
    int tp, ret = 0;

    if (file && (tp = file->cl_type) != CLF_TYPE_INVALID) {
	if (tp == CLF_TYPE_PLAIN) {
	    ret = fread(buf, 1, len, file->cl_plain);
	}
#ifdef USE_ZLIB
	if (tp == CLF_TYPE_GZIP) {
	    ret = gzread(file->cl_gz, buf, len);
	}
#endif	// USE_ZLIB
#ifdef USE_BZ2LIB
	if (tp == CLF_TYPE_BZIP2) {
	    ret = bzread(file->cl_bz, buf, len);
	}
#endif	// USE_BZ2LIB
#ifdef USE_ZZIPLIB
	if (tp == CLF_TYPE_ZZIP) {
	    ret = zzip_read(file->cl_zz, buf, len);
	}
#endif	// USE_ZZIPLIB
    } else {
	errno = EBADF;
    }
    return ret;
}
示例#5
0
文件: file.c 项目: Exadios/xcsoar-exp
/** => zzip_read
 */
zzip_size_t
zzip_fread(void *ptr, zzip_size_t size, zzip_size_t nmemb, ZZIP_FILE * file)
{
    if (! size)
        size = 1;
    return zzip_read(file, ptr, size * nmemb) / size;
}
示例#6
0
unsigned
ZipSource::read(char *p, unsigned n)
{
  zzip_ssize_t nbytes = zzip_read(file, p, n);
  return nbytes >= 0
    ? (unsigned)nbytes
    : 0;
}
示例#7
0
文件: file.c 项目: Exadios/xcsoar-exp
static zzip_size_t
zzip_pread_fallback(ZZIP_FILE *file, void *ptr, zzip_size_t size,
                    zzip_off_t offset)
{
    zzip_off_t new_offset = zzip_seek(file, offset, SEEK_SET);
    if (new_offset < 0)
        return -1;

    return zzip_read(file, ptr, size);
}
示例#8
0
//// read a file contents from either a archive of real directory
void b_zzip_read(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_FILE* fp = zzip_open (fileName, O_RDONLY|O_BINARY);

    if (! fp){
   		perror (fileName);
    }
    
    int bufSize = 2, blockSize = 1024, numBlocks = 1;
    char buf[bufSize];
    int n, counter = 0;
    char *contents = (char *)calloc(blockSize, sizeof(char));
    
    /* read chunks of bufSize bytes into buf and concatenate them into previous string */
    while( (n = (zzip_read(fp, buf, bufSize-1))) > 0){
    	counter++;
    	
    	if(counter == 1){
//    		strcpy(contents, buf);
			strncat(contents, buf, bufSize-1);
			bufSize = 21;
    	}else{
    		int originalSize = strlen(contents);
    		if( ((blockSize*numBlocks) - (originalSize + 1)) < bufSize){
    			numBlocks++;
    			contents = string_mkroom(contents, blockSize*numBlocks);
    		}

    		strncat(contents, buf, bufSize-1);
//    		printf("%s\n\n\n", contents);
    	}
    	buf[n] = '\0';
    }
    
    argstack[0] = string_to_array(tsk, contents);
	
	zzip_close(fp);
}
示例#9
0
int
ACEXML_ZipCharStream::getchar_i (char& ch)
{
  if (this->infile_ == 0)
    return -1;

  if (this->pos_ < this->limit_)
    {
      ch = this->buf_[this->pos_++];
      return 0;
    }
  this->limit_ = zzip_read (this->infile_, this->buf_, sizeof (this->buf_));
  if (this->limit_ == 0)
    return -1;
  this->pos_ = 0;
  ch = this->buf_[this->pos_++];
  return 0;
}
示例#10
0
int
ACEXML_ZipCharStream::peekchar_i (ACE_OFF_T offset)
{
  if (this->infile_ == 0)
    return -1;

  if (offset > (ACE_OFF_T) sizeof (this->buf_))
    return -1;
  if (this->pos_ + offset < this->limit_)
    return this->buf_[this->pos_ + offset];
  int i = 0;
  for (; this->pos_ < this->limit_; ++this->pos_, ++i)
    this->buf_[i] = this->buf_[this->pos_];
  this->limit_ = zzip_read (this->infile_, this->buf_ + i,
                            sizeof (this->buf_) - i);
  this->limit_ += i;
  if (this->limit_ == 0)
    return -1;
  this->pos_ = 0;
  return this->buf_[this->pos_ + offset];
}
示例#11
0
size_t getEntry(const char *name, char *contentFile, char **ptr) {

  size_t size=0;
  ZZIP_DIR *dir;
  ZZIP_DIRENT entry;
  ZZIP_FILE *file;
  zzip_error_t error;
  char *buf;

  o_log(DEBUGM, "opening %s", name);

  dir = zzip_dir_open(name, &error);
  if (!dir) {
    o_log(ERROR, "failed to open %s", name);
    return 0;
  }

  while(zzip_dir_read(dir, &entry)) {

    if( 0 == strcmp(entry.d_name, contentFile) ) {

      file = zzip_file_open(dir, contentFile, O_RDONLY);

      (void)zzip_seek(file, 0, SEEK_END);
      size = zzip_tell(file);
      (void)zzip_seek(file, 0, SEEK_SET);

      buf = (char *)malloc(size+1);
      (void)zzip_read(file, buf, size);
      buf[size] = '\0';
      *ptr = buf;

      zzip_file_close(file);
    }
  }
  zzip_dir_close(dir);

  return size;
}
示例#12
0
int 
main (int argc, char* argv[])
{
    if (argc <= 1 || argc > 3)
    {
        printf (usage);
        exit (0);
    }

    if (strlen(argv[1]) > 128) {
        fprintf(stderr, "Please provide a filename shorter than 128 chars.\n");
        exit(1);
    }

    /* obfuscate the file */
    {
        int ch;
        FILE* fin;
        FILE* fout;
        fin  = fopen(argv[1], "rb");
        if (!fin) {
            fprintf(stderr, "Can't open input file \"%s\"\n", argv[1]);
            exit(1);
        }
        fout = fopen((argc == 2) ? "obfuscated" : "obfuscated.dat", "wb");
        if (!fout) {
            fprintf(stderr, "Can't open output file \"obfuscated\"\n");
            exit(1);
        }
        while ((ch = fgetc(fin)) != EOF) {
            ch ^= 0x55;
            fputc(ch, fout);
        }
        fclose(fout);
        fclose(fin);
    }

    /* install our I/O hander */
    zzip_init_io(&our_handlers, 0);
    our_handlers.read = &our_read;

    {
#       define argn 2
        ZZIP_FILE* fp;
        char name[256];
        if (argc == 3) {
            sprintf(name, "obfuscated/%s", argv[argn]);
        } else {
            sprintf(name, "obfuscated");
        }
        fp = zzip_open_ext_io (name, O_RDONLY|O_BINARY, ZZIP_PREFERZIP,
			       our_fileext, &our_handlers);

        if (! fp)
        {
            perror (name);
            exit(1);
        }else{
            char buf[17];
            int n;

        /* read chunks of 16 bytes into buf and print them to stdout */
            while (0 < (n = zzip_read(fp, buf, 16)))
            {
                buf[n] = '\0';
#             ifdef STDOUT_FILENO
                write (STDOUT_FILENO, buf, n);
#             else
                fwrite (buf, 1, n, stdout);
#             endif
            }

            if (n == -1) 
                perror (argv[argn]);
        }
    }
    
    return 0;
} 
示例#13
0
	static int _zzip_read(SDL_RWops *context, void *ptr, int size, int maxnum)
	{
	return zzip_read(SDL_RWOPS_ZZIP_FILE(context), (char*)ptr, size*maxnum) / size;
	}