Example #1
0
int main(int argc, char **argv) {
  ZipT *zip;
  int i;

  if (argc < 2)
    Usage(argv[0]);

  if ((zip = ZipOpen(argv[1]))) {
    if (argc == 2) {
      ZipList(zip);
    } else {
      for (i = 2; i < argc; i++) {
        RwOpsT *file;

        if ((file = ZipRead(zip, argv[i]))) {
          int size = IoSize(file);
          uint8_t *data = MemNew(size);

          IoRead(file, data, size);
          IoClose(file);
          fwrite(data, size, 1, stdout);
          MemUnref(data);
        } else {
          printf("%s: no such file!", argv[i]);
        }
      }
    }

    MemUnref(zip);
  }

  return 0;
}
Example #2
0
int IoRead_new( PspIoDrvFileArg * arg, char * data, int len )
{
	PspIoDrvArg * drv = arg->drv;
	int num = isRedirected( arg );
	if( num >= 0 && arg->fs_num == 0 )
	{
		arg->drv = ms_drv;
		int ret = fatms_drv->funcs->IoLseek( arg, 0, PSP_SEEK_CUR );
		if ( ret < 0 )
		{
			log( "error: %08x when read %s\n", ret, ctf_header[ctf_handler[num].num].name );
			arg->drv = drv;
			ret = IoReopen( arg, &num );
			if ( ret < 0 )
			{
				return ret;
			}
		}
		int sub = ret + len - ctf_header[ctf_handler[num].num].start - ctf_header[ctf_handler[num].num].size;
		if ( sub <= 0 )
		{
			sub = 0;
		}
		ret =  fatms_drv->funcs->IoRead( arg, data, len - sub );
		ctf_handler[num].offset += ret;
		arg->drv = drv;
		return ret;
	}
	int ret = IoRead( arg, data, len );
	return ret;
}
Example #3
0
static bool ReadPNG(PngT *png, RwOpsT *stream) {
  uint32_t id[2];
  bool error = false;
  PngChunkT chunk;

  memset(png, 0, sizeof(PngT));

  if (!IoRead32(stream, &id[0]) || !IoRead32(stream, &id[1])) {
    LOG("Could not read PNG header!");
    return false;
  }

  if (id[0] != PNG_ID0 || id[1] != PNG_ID1) {
    LOG("Not a PNG file!");
    return false;
  }

  memset(&chunk, 0, sizeof(chunk));

  while (chunk.id != PNG_IEND && !error) {
    uint32_t their_crc;
    uint8_t *ptr;

    if (IoRead(stream, &chunk, 8) != 8)
      return false;

    LOG("%.4s: length: %d", (char *)&chunk.id, chunk.length);

    ptr = MemNew(chunk.length);

    if (IoRead(stream, ptr, chunk.length) != chunk.length)
      return false;

    if (chunk.id == PNG_IHDR) {
      MemCopy(&png->ihdr, ptr, sizeof(IhdrT));
    } else if (chunk.id == PNG_IDAT) {
      if (!png->idat.data) {
        png->idat.length = chunk.length;
        png->idat.data = ptr;
      } else {
        IdatT *idat = &png->idat;

        while (idat->next)
          idat = idat->next;

        idat->next = NewRecord(IdatT);
        idat->next->length = chunk.length;
        idat->next->data = ptr;
      }
      ptr = NULL;
    } else if (chunk.id == PNG_PLTE) {
      png->plte.no_colors = chunk.length / 3;
      png->plte.colors = (RGB *)ptr;
      ptr = NULL;
    } else if (chunk.id == PNG_tRNS) {
      if (png->ihdr.colour_type == PNG_INDEXED) {
        png->trns = MemNew(sizeof(uint32_t) + chunk.length);
        png->trns->type3.length = chunk.length;
        MemCopy(png->trns->type3.alpha, ptr, chunk.length);
      } else {
        png->trns = (TrnsT *)ptr;
        ptr = NULL;
      }
    }

    if (ptr)
      MemUnref(ptr);

    if (!IoRead32(stream, &their_crc))
      return false;
  }

  return !error;
}