Ejemplo n.º 1
0
/**
 * __mtdsplit_parse_uimage - scan partition and create kernel + rootfs parts
 *
 * @find_header: function to call for a block of data that will return offset
 *      of a valid uImage header if found
 */
static int __mtdsplit_parse_uimage(struct mtd_info *master,
				   struct mtd_partition **pparts,
				   struct mtd_part_parser_data *data,
				   ssize_t (*find_header)(u_char *buf, size_t len))
{
	struct mtd_partition *parts;
	u_char *buf;
	int nr_parts;
	size_t offset;
	size_t uimage_offset;
	size_t uimage_size = 0;
	size_t rootfs_offset;
	size_t rootfs_size = 0;
	int uimage_part, rf_part;
	int ret;
	enum mtdsplit_part_type type;

	nr_parts = 2;
	parts = kzalloc(nr_parts * sizeof(*parts), GFP_KERNEL);
	if (!parts)
		return -ENOMEM;

	buf = vmalloc(MAX_HEADER_LEN);
	if (!buf) {
		ret = -ENOMEM;
		goto err_free_parts;
	}

	/* find uImage on erase block boundaries */
	for (offset = 0; offset < master->size; offset += master->erasesize) {
		struct uimage_header *header;

		uimage_size = 0;

		ret = read_uimage_header(master, offset, buf, MAX_HEADER_LEN);
		if (ret)
			continue;

		ret = find_header(buf, MAX_HEADER_LEN);
		if (ret < 0) {
			pr_debug("no valid uImage found in \"%s\" at offset %llx\n",
				 master->name, (unsigned long long) offset);
			continue;
		}
		header = (struct uimage_header *)(buf + ret);

		uimage_size = sizeof(*header) + be32_to_cpu(header->ih_size) + ret;
		if ((offset + uimage_size) > master->size) {
			pr_debug("uImage exceeds MTD device \"%s\"\n",
				 master->name);
			continue;
		}
		break;
	}

	if (uimage_size == 0) {
		pr_debug("no uImage found in \"%s\"\n", master->name);
		ret = -ENODEV;
		goto err_free_buf;
	}

	uimage_offset = offset;

	if (uimage_offset == 0) {
		uimage_part = 0;
		rf_part = 1;

		/* find the roots after the uImage */
		ret = mtd_find_rootfs_from(master, uimage_offset + uimage_size,
					   master->size, &rootfs_offset, &type);
		if (ret) {
			pr_debug("no rootfs after uImage in \"%s\"\n",
				 master->name);
			goto err_free_buf;
		}

		rootfs_size = master->size - rootfs_offset;
		uimage_size = rootfs_offset - uimage_offset;
	} else {
		rf_part = 0;
		uimage_part = 1;

		/* check rootfs presence at offset 0 */
		ret = mtd_check_rootfs_magic(master, 0, &type);
		if (ret) {
			pr_debug("no rootfs before uImage in \"%s\"\n",
				 master->name);
			goto err_free_buf;
		}

		rootfs_offset = 0;
		rootfs_size = uimage_offset;
	}

	if (rootfs_size == 0) {
		pr_debug("no rootfs found in \"%s\"\n", master->name);
		ret = -ENODEV;
		goto err_free_buf;
	}

	parts[uimage_part].name = KERNEL_PART_NAME;
	parts[uimage_part].offset = uimage_offset;
	parts[uimage_part].size = uimage_size;

	if (type == MTDSPLIT_PART_TYPE_UBI)
		parts[rf_part].name = UBI_PART_NAME;
	else
		parts[rf_part].name = ROOTFS_PART_NAME;
	parts[rf_part].offset = rootfs_offset;
	parts[rf_part].size = rootfs_size;

	vfree(buf);

	*pparts = parts;
	return nr_parts;

err_free_buf:
	vfree(buf);

err_free_parts:
	kfree(parts);
	return ret;
}
Ejemplo n.º 2
0
Errcode open_wndo(Wndo **pw, WndoInit *wi)
/*
 * Open a window.  Returns window in *pw.  
 * (pw == NULL is valid input, but should only be used by
 * open_wscreen()).
 */
{
Errcode err;
Wndo *w = NULL;
Wscreen *ws;
Boolean was_mouse;

LONG allocsize;
LONG ydotsize;
LONG ptrsize;
SHORT screen_wndo;
SHORT is_backdrop;
SHORT max_wins;

	was_mouse = hide_mouse();
	is_backdrop = wi->flags & WNDO_BACKDROP;
	screen_wndo = (pw == NULL);
	ws = wi->screen;

	max_wins = ws->max_wins;

	if(screen_wndo)
	{
		w = &ws->wndo;
		w->type = RT_ROOTWNDO;
		w->cmap = ws->viscel->cmap;
		w->W_rastid = NULL_RASTID;
	}
	else
	{
		*pw = NULL;
		if(!is_backdrop)
		{
			if(ws->num_wins >= max_wins)
			{
				err = Err_tomany_wins;
				goto error;
			}
			--max_wins;  /* these windows can't be behind backdrops */
		}
		if((w = pj_zalloc(sizeof(Wndo) + wi->extrabuf)) == NULL)
			goto nomem_error;
		w->type = RT_WINDOW;
		w->rasts = ws->wndo.rasts;
		w->cmap = ws->wndo.cmap;

		if(is_backdrop)
			w->W_rastid = NULL_RASTID; /* the initial null raster */
		else
		{
			w->W_rastid = get_newid(ws);
			w->rasts[w->W_rastid] = &(w->behind);
		}
	}

	if(wi->cursor == NULL)
		w->cursor = ws->cursor;
	else
		w->cursor = wi->cursor;

	w->W_screen = ws; /* must get to here ok if window is allocated */

	/* move in raster header fields from root screen raster */

	w->aspect_dx = ws->viscel->aspect_dx;
	w->aspect_dy = ws->viscel->aspect_dy;
	w->pdepth	 = ws->viscel->pdepth;

	copy_rectfields(wi,w); /* copy in rectangle fields for initial size */

	/* none too small */

	if(w->width < WNDO_MINWIDTH)
		w->width = WNDO_MINWIDTH;
	if(w->height < WNDO_MINHEIGHT)
		w->height = WNDO_MINHEIGHT;

#ifdef DOESNTWORK
	/* no window ports bigger than screen !! */

	/* this should be a and cliprects type of clip to get common rect
	 * if needed */

	sclip_rect((Rectangle *)&(w->RECTSTART),
			   (Rectangle *)&(ws->viscel->RECTSTART));

#endif /*  DOESNTWORK */

	/* load cliprect variables for window port position and size */

	w->W_xmax = w->x + w->width;
	w->W_ymax = w->y + w->height;

	/* increase width and height of window to be the maximum size
	 * requested if greater than port size */

	if(wi->maxw > w->width)
		w->width = wi->maxw;
	if(wi->maxh > w->height)
		w->height = wi->maxh;


	/* initialize and copy in window maxsize rectangle fields to behind rast
	 * the width and height for both shall NEVER be changed until window is
	 * closed */

	copy_rasthdr(ws->viscel,&w->behind);
	copy_rectfields(w,&w->behind);

	if(is_backdrop)
	{
		if((err = pj_open_nullrast(&w->behind)) < 0) /* dummy backup area */
			goto error;
	}
	else
	{
		if((err = pj_open_bytemap((Rasthdr *)&w->behind,(Bytemap *)&w->behind)) < 0)
			goto error;
	}

	/* size of one column array of ydots */

	ydotsize = (w->height	  /* one byte for each dot */
				+ (w->height & 1) /* even word size */
				+ sizeof(Cliphead));	 /* cliphead for range and freelist */

	/* size of all ydots buffers */

	allocsize = (ydotsize * ((max_wins * 2) - 1));
	/* size of pointer array for ydots */

	/* size of pointer array */

	ptrsize = w->width * sizeof(PTR);

	if((w->ydots = pj_malloc(allocsize + ptrsize)) == NULL)
		goto nomem_error;

	w->free_ydots = link_free_clips(OPTR(w->ydots,ptrsize),ydotsize,allocsize);

	w->ydots[0] = get_free_clip(&w->free_ydots);
	NEXTX(w->ydots[0]) = w->width;
	free_init_ydots(w);

	/* allocate vchanes */
	if((w->vchanges = pj_malloc(w->height * sizeof(SHORT))) == NULL)
		goto nomem_error;

	pj_stuff_words(w->height,w->vchanges,w->height);

	w->lib = get_window_lib();

	/******** add window to screen ********/

	if(screen_wndo)
	{
		add_head(&ws->wilist,&w->W_node);
		build_all_clips(ws,0);
		++ws->num_wins;
		return(0);
	}

	w->flags |= wi->flags & ~(WNDO_NOCLEAR);

	if(is_backdrop)
	{
#ifdef WASTHISWAY
		insert_before(&(w->W_node),&(ws->wndo.W_node));
#endif
		if( (wi->over != NULL)
			 && (find_header(&(wi->over->W_node)) == &(ws->wilist)))
		{
			insert_before(&(w->W_node),&(wi->over->W_node));
		}
		else
		{
			add_head(&ws->wilist,&w->W_node);
		}
		build_all_clips(ws,1);
		if(!(wi->flags & WNDO_NOCLEAR))
			pj_set_rast((Raster *)w, 0); /* clear window */
	}
	else
	{
		++ws->num_wins;

		if( (wi->over != NULL)
			 && (find_header(&(wi->over->W_node)) == &(ws->wilist)))
		{
			insert_before(&(w->W_node),&(wi->over->W_node));
		}
		else
		{
			add_head(&ws->wilist,&w->W_node);
		}
		build_all_clips(ws,1);

		if(wi->flags & WNDO_NOCLEAR)
		{
			/* only blit in parts that are backups */
			blit_behind(w,blit_saveonly);
		}
		else
		{
			pj_set_rast(&w->behind,0);	 /* clear backup raster */
			blit_behind(w,pj__swaprect); /* swap window raster onto screen */
		}
	}

	*pw = w;
	err = Success;
	goto done;

nomem_error:
	err = Err_no_memory;
error:
	_close_wndo(w);
done:
	if(was_mouse)
		show_mouse();
	return(err);
}
Ejemplo n.º 3
0
static const char *check_nonce(const char *buf, size_t len)
{
	char *nonce = find_header(buf, len, "nonce");
	unsigned long stamp, ostamp;
	char *bohmac, *expect = NULL;
	const char *retval = NONCE_BAD;

	if (!nonce) {
		retval = NONCE_MISSING;
		goto leave;
	} else if (!push_cert_nonce) {
		retval = NONCE_UNSOLICITED;
		goto leave;
	} else if (!strcmp(push_cert_nonce, nonce)) {
		retval = NONCE_OK;
		goto leave;
	}

	if (!stateless_rpc) {
		/* returned nonce MUST match what we gave out earlier */
		retval = NONCE_BAD;
		goto leave;
	}

	/*
	 * In stateless mode, we may be receiving a nonce issued by
	 * another instance of the server that serving the same
	 * repository, and the timestamps may not match, but the
	 * nonce-seed and dir should match, so we can recompute and
	 * report the time slop.
	 *
	 * In addition, when a nonce issued by another instance has
	 * timestamp within receive.certnonceslop seconds, we pretend
	 * as if we issued that nonce when reporting to the hook.
	 */

	/* nonce is concat(<seconds-since-epoch>, "-", <hmac>) */
	if (*nonce <= '0' || '9' < *nonce) {
		retval = NONCE_BAD;
		goto leave;
	}
	stamp = strtoul(nonce, &bohmac, 10);
	if (bohmac == nonce || bohmac[0] != '-') {
		retval = NONCE_BAD;
		goto leave;
	}

	expect = prepare_push_cert_nonce(service_dir, stamp);
	if (strcmp(expect, nonce)) {
		/* Not what we would have signed earlier */
		retval = NONCE_BAD;
		goto leave;
	}

	/*
	 * By how many seconds is this nonce stale?  Negative value
	 * would mean it was issued by another server with its clock
	 * skewed in the future.
	 */
	ostamp = strtoul(push_cert_nonce, NULL, 10);
	nonce_stamp_slop = (long)ostamp - (long)stamp;

	if (nonce_stamp_slop_limit &&
	    labs(nonce_stamp_slop) <= nonce_stamp_slop_limit) {
		/*
		 * Pretend as if the received nonce (which passes the
		 * HMAC check, so it is not a forged by third-party)
		 * is what we issued.
		 */
		free((void *)push_cert_nonce);
		push_cert_nonce = xstrdup(nonce);
		retval = NONCE_OK;
	} else {
		retval = NONCE_SLOP;
	}

leave:
	free(nonce);
	free(expect);
	return retval;
}
Ejemplo n.º 4
0
/*
 * asynchronus input (select) with the stdin and the socket connection
 * to the server. copy input data from stdin to server, and
 * copy received data from the server to stdout/stderr.
 * destination of output is stdout or stderr are distinguished by
 * stream identifier(sid) header is 'out' or 'err'.
 */
int start_session(int fd)
{
    struct header_t headers[MAX_HEADER];

#ifdef WINDOWS
    invoke_thread(fd);
#else
    fd_set read_set;
    int ret;
    int stdin_closed = 0;
#endif

    while (1) {
#ifdef UNIX
        // initialize the set of file descriptor
        FD_ZERO(&read_set);

        // watch stdin of client and socket.
        FD_SET(STDIN_FILENO, &read_set);
        FD_SET(fd, &read_set);

        if ((ret = select(fd + 1, &read_set, (fd_set*)NULL, (fd_set*)NULL, NULL)) == -1) {
            perror("ERROR: select failure");
            exit(1);
        }
        if (ret == 0) {
            fprintf(stderr, "ERROR: timeout?\n");
            continue;
        }

        // detect changed descriptor
        if (!stdin_closed && FD_ISSET(STDIN_FILENO, &read_set)) { // stdin
#ifdef DEBUG
            fprintf(stderr, "DEBUG: detect stdin\n");
#endif
            stdin_closed = send_to_server(fd);
            continue;
        }
        if (FD_ISSET(fd, &read_set) == FALSE){ // socket
#ifdef DEBUG
            fprintf(stderr, "DEBUG: detect nothing\n");
#endif
            continue;
        }
#ifdef DEBUG
        fprintf(stderr, "DEBUG: detect socket\n");
#endif
#endif

        int size = read_headers(fd, headers);
        if (size == 0) {
            return 0; // as normal exit if header size 0
        }

        // Process exit
        char* status = find_header(headers, HEADER_KEY_STATUS, size);
        if (status != NULL) {
            int stat = atoi(status);
            return stat;
        }

        // Dispatch data from server to stdout/err.
        char* sid = find_header(headers, HEADER_KEY_CHANNEL, size);
        if (sid == NULL) {
            fprintf(stderr, "ERROR: required header %s not found\n", HEADER_KEY_CHANNEL);
            return 1;
        }
        char* chunk_size = find_header(headers, HEADER_KEY_SIZE, size);
        if (chunk_size == NULL) {
            fprintf(stderr, "ERROR: required header %s not found\n", HEADER_KEY_SIZE);
            return 1;
        }
        if (receive_from_server(fd, sid, atoi(chunk_size)) == EOF) {
            return 0;
        }
    }
}
Ejemplo n.º 5
0
 bool request_header::body_expected() const
 {
     return find_header( content_length_header ) != 0 || find_header( transfer_encoding_header );
 }
Ejemplo n.º 6
0
/* extraHeaders is either NULL or a string with extra headers separated
 * by '\r\n', ending with '\r\n'.
 */
int httpGetFileDesc(char * hostname, int port, char * remotename,
                    char *extraHeaders) {
    char * buf, *headers = NULL;
    char *status;
    char *hstr;
    int family;
    struct in_addr addr;
    struct in6_addr addr6;
    int sock;
    int rc;
    struct sockaddr_in destPort;
    struct sockaddr_in6 destPort6;
    fd_set readSet;
#ifdef ROCKS
    int bufsize;
#endif /* ROCKS */
    if (port < 0)
        port = 80;

    family = AF_INET;
    rc = getHostAddress(hostname, &addr, family);
    if (rc) {
        family = AF_INET6;
        rc = getHostAddress(hostname, &addr6, family);
        if (rc)
            return rc;
    }

    sock = socket(family, SOCK_STREAM, IPPROTO_IP);
    if (sock < 0) {
        return FTPERR_FAILED_CONNECT;
    }

    if (family == AF_INET) {
        destPort.sin_family = family;
        destPort.sin_port = htons(port);
        destPort.sin_addr = addr;

        if (connect(sock, (struct sockaddr *) &destPort, sizeof(destPort))) {
            close(sock);
            return FTPERR_FAILED_CONNECT;
        }
    } else if (family == AF_INET6) {
        destPort6.sin6_family = family;
        destPort6.sin6_port = htons(port);
        destPort6.sin6_addr = addr6;

        if (connect(sock, (struct sockaddr *) &destPort6, sizeof(destPort6))) {
            close(sock);
            return FTPERR_FAILED_CONNECT;
        }
    }

    if (extraHeaders)
        hstr = extraHeaders;
    else
        hstr = "";

#ifdef ROCKS
    bufsize = strlen(remotename) + strlen(hostname) + strlen(hstr) + 30;

    if ((buf = malloc(bufsize)) == NULL) {
        logMessage(ERROR, "ROCKS:httpGetFileDesc:malloc failed");
        return FTPERR_FAILED_CONNECT;
    }
#else
    buf = alloca(strlen(remotename) + strlen(hostname) + strlen(hstr) + 25);
#endif /* ROCKS */
    sprintf(buf, "GET %s HTTP/1.0\r\nHost: %s\r\n%s\r\n", remotename, hostname, hstr);
    rc = write(sock, buf, strlen(buf));
#ifdef ROCKS
    free(buf);
#endif /* ROCKS */

    rc = read_headers (&headers, &readSet, sock);

    if (rc < 0)
        return rc;

    status = find_status_code (headers);

    if (status == NULL) {
        close(sock);
        return FTPERR_SERVER_IO_ERROR;
    } else if (!strncmp(status, "200", 3)) {
        return sock;
    } else if (!strncmp(status, "301", 3) || !strncmp(status, "302", 3) ||
               !strncmp(status, "303", 3) || !strncmp(status, "307", 3)) {
        struct iurlinfo ui;
        char *redir_loc = find_header (headers, "Location");
        int retval;

        if (redir_loc == NULL) {
            logMessage(WARNING, "got a redirect response, but Location header is NULL");
            close(sock);
            return FTPERR_FILE_NOT_FOUND;
        }

        logMessage(INFO, "redirecting to %s", redir_loc);
        convertURLToUI(redir_loc, &ui);
        retval = httpGetFileDesc (ui.address, -1, ui.prefix, extraHeaders);
        free(redir_loc);
        return retval;
    } else if (!strncmp(status, "403", 3)) {
        close(sock);
        return FTPERR_PERMISSION_DENIED;
    } else if (!strncmp(status, "404", 3)) {
        close(sock);
        return FTPERR_FILE_NOT_FOUND;
#ifdef ROCKS
    } else if (!strncmp(status, "503", 3)) {
         /* A server nack - busy */
         close(sock);
         logMessage(WARNING, "ROCKS:server busy");
         watchdog_reset();
         return FTPERR_FAILED_DATA_CONNECT;
#endif /* ROCKS */
    } else {
        close(sock);
        logMessage(ERROR, "bad HTTP response code: %s", status);
        return FTPERR_BAD_SERVER_RESPONSE;
    }
}
Ejemplo n.º 7
0
void SuperFamicomCartridge::read_header(linput_t *li) {
  int32 size = qlsize(li);
  if(size < 0) return;

  //skip copier header
  uint32 start = 0;
  has_copier_header = (size & 0x7fff) == 512;
  if(has_copier_header) start += 512, size -= 512;

  type        = TypeUnknown;
  mapper      = LoROM;
  dsp1_mapper = DSP1Unmapped;
  region      = NTSC;
  rom_size    = size;
  ram_size    = 0;

  has_bsx_slot   = false;
  has_superfx    = false;
  has_sa1        = false;
  has_sharprtc   = false;
  has_epsonrtc   = false;
  has_sdd1       = false;
  has_spc7110    = false;
  has_cx4        = false;
  has_dsp1       = false;
  has_dsp2       = false;
  has_dsp3       = false;
  has_dsp4       = false;
  has_obc1       = false;
  has_st010      = false;
  has_st011      = false;
  has_st018      = false;

  //=====================
  //detect Game Boy carts
  //=====================

  if(size >= 0x0140) {
    uint8 data[0x140];
    qlseek(li, start);
    qlread(li, data, 0x140);

    if(data[0x0104] == 0xce && data[0x0105] == 0xed && data[0x0106] == 0x66 && data[0x0107] == 0x66
    && data[0x0108] == 0xcc && data[0x0109] == 0x0d && data[0x010a] == 0x00 && data[0x010b] == 0x0b) {
      type = TypeGameBoy;
      return;
    }
  }

  if(size < 32768) {
    type = TypeUnknown;
    return;
  }

  const unsigned index = find_header(li);
  header_offset = index;

  uint8 extended_header[16 + 64];
  qlseek(li, start + index - 16);
  qlread(li, extended_header, 16 + 64);
  uint8 * header = &extended_header[16];

  const uint8 mapperid = header[Mapper];
  const uint8 rom_type = header[RomType];
  const uint8 lrom_size = header[RomSize];
  const uint8 company  = header[Company];
  const uint8 regionid = header[CartRegion] & 0x7f;

  ram_size = 1024 << (header[RamSize] & 7);
  if(ram_size == 1024) ram_size = 0;  //no RAM present
  if(lrom_size == 0 && ram_size) ram_size = 0;  //fix for Bazooka Blitzkrieg's malformed header (swapped ROM and RAM sizes)

  //0, 1, 13 = NTSC; 2 - 12 = PAL
  region = (regionid <= 1 || regionid >= 13) ? NTSC : PAL;

  //=======================
  //detect BS-X flash carts
  //=======================

  if(header[0x13] == 0x00 || header[0x13] == 0xff) {
    if(header[0x14] == 0x00) {
      const uint8 n15 = header[0x15];
      if(n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc) {
        if(header[0x1a] == 0x33 || header[0x1a] == 0xff) {
          type = TypeBsx;
          mapper = BSXROM;
          region = NTSC;  //BS-X only released in Japan
          return;
        }
      }
    }
  }

  //=========================
  //detect Sufami Turbo carts
  //=========================

  uint8 data[32];
  qlseek(li, start);
  qlread(li, data, 32);

  if(!memcmp(data, "BANDAI SFC-ADX", 14)) {
    if(!memcmp(data + 16, "SFC-ADX BACKUP", 14)) {
      type = TypeSufamiTurboBios;
    } else {
      type = TypeSufamiTurbo;
    }
    mapper = STROM;
    region = NTSC;  //Sufami Turbo only released in Japan
    return;         //RAM size handled outside this routine
  }

  //==========================
  //detect Super Game Boy BIOS
  //==========================

  if(!memcmp(header, "Super GAMEBOY2", 14)) {
    type = TypeSuperGameBoy2Bios;
    return;
  }

  if(!memcmp(header, "Super GAMEBOY", 13)) {
    type = TypeSuperGameBoy1Bios;
    return;
  }

  //=====================
  //detect standard carts
  //=====================

  //detect presence of BS-X flash cartridge connector (reads extended header information)
  if(header[-14] == 'Z') {
    if(header[-11] == 'J') {
      uint8 n13 = header[-13];
      if((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9')) {
        if(company == 0x33 || (header[-10] == 0x00 && header[-4] == 0x00)) {
          has_bsx_slot = true;
        }
      }
    }
  }

  if(has_bsx_slot) {
    if(!memcmp(header, "Satellaview BS-X     ", 21)) {
      //BS-X base cart
      type = TypeBsxBios;
      mapper = BSXROM;
      region = NTSC;  //BS-X only released in Japan
      return;         //RAM size handled internally by load_cart_bsx() -> BSXCart class
    } else {
      type = TypeBsxSlotted;
      mapper = (index == 0x7fc0 ? BSCLoROM : BSCHiROM);
      region = NTSC;  //BS-X slotted cartridges only released in Japan
    }
  } else {
    //standard cart
    type = TypeNormal;

    if(index == 0x7fc0 && size >= 0x401000) {
      mapper = ExLoROM;
    } else if(index == 0x7fc0 && mapperid == 0x32) {
      mapper = ExLoROM;
    } else if(index == 0x7fc0) {
      mapper = LoROM;
    } else if(index == 0xffc0) {
      mapper = HiROM;
    } else {  //index == 0x40ffc0
      mapper = ExHiROM;
    }
  }

  if(mapperid == 0x20 && (rom_type == 0x13 || rom_type == 0x14 || rom_type == 0x15 || rom_type == 0x1a)) {
    has_superfx = true;
    mapper = SuperFXROM;
    ram_size = 1024 << (header[-3] & 7);
    if(ram_size == 1024) ram_size = 0;
  }

  if(mapperid == 0x23 && (rom_type == 0x32 || rom_type == 0x34 || rom_type == 0x35)) {
    has_sa1 = true;
    mapper = SA1ROM;
  }

  if(mapperid == 0x35 && rom_type == 0x55) {
    has_sharprtc = true;
  }

  if(mapperid == 0x32 && (rom_type == 0x43 || rom_type == 0x45)) {
    has_sdd1 = true;
  }

  if(mapperid == 0x3a && (rom_type == 0xf5 || rom_type == 0xf9)) {
    has_spc7110 = true;
    has_epsonrtc = (rom_type == 0xf9);
    mapper = SPC7110ROM;
  }

  if(mapperid == 0x20 && rom_type == 0xf3) {
    has_cx4 = true;
  }

  if((mapperid == 0x20 || mapperid == 0x21) && rom_type == 0x03) {
    has_dsp1 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x05 && company != 0xb2) {
    has_dsp1 = true;
  }

  if(mapperid == 0x31 && (rom_type == 0x03 || rom_type == 0x05)) {
    has_dsp1 = true;
  }

  if(has_dsp1 == true) {
    if((mapperid & 0x2f) == 0x20 && size <= 0x100000) {
      dsp1_mapper = DSP1LoROM1MB;
    } else if((mapperid & 0x2f) == 0x20) {
      dsp1_mapper = DSP1LoROM2MB;
    } else if((mapperid & 0x2f) == 0x21) {
      dsp1_mapper = DSP1HiROM;
    }
  }

  if(mapperid == 0x20 && rom_type == 0x05) {
    has_dsp2 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x05 && company == 0xb2) {
    has_dsp3 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x03) {
    has_dsp4 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x25) {
    has_obc1 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf6 && lrom_size >= 10) {
    has_st010 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf6 && lrom_size < 10) {
    has_st011 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf5) {
    has_st018 = true;
  }
}
Ejemplo n.º 8
0
struct attach *
attach_build(struct mail *m)
{
	struct attach	*atr = NULL, *at;
	char		*hdr, *ptr, *b = NULL, *type;
	size_t		 len, bl;
	int		 last;
	u_int		 n;

	hdr = find_header(m, "content-type", &len, 0);
	if (hdr == NULL)
		return (NULL);

	type = attach_type(m, hdr, "boundary", &b);
	if (type == NULL || b == NULL) {
		if (type != NULL)
			xfree(type);
		goto error;
	}
	if (strncasecmp(type, "multipart/", 10) != 0) {
		xfree(type);
		goto error;
	}
	bl = strlen(b);

	atr = xmalloc(sizeof *atr);
	memset(atr, 0, sizeof *atr);
	TAILQ_INIT(&atr->children);
	atr->type = type;

	/* Find the first boundary. */
	line_init(m, &ptr, &len);
	while (ptr != NULL) {
		if (ptr[0] == '-' && ptr[1] == '-') {
			if (len - 3 == bl && strncmp(ptr + 2, b, bl) == 0)
				break;
		}
		line_next(m, &ptr, &len);
	}
	if (ptr == NULL)
		goto error;

	/* Now iterate over the rest. */
	last = 0;
	n = 0;
	while (ptr != NULL && !last) {
		if (ptr[0] == '-' && ptr[1] == '-') {
			if (len - 5 == bl && strncmp(ptr + 2, b, bl) == 0)
				break;
		}

		at = attach_get(m, &ptr, &len, b, &last);
		if (at == NULL)
			goto error;
		at->idx = n++;
		at->parent = atr;
		TAILQ_INSERT_TAIL(&atr->children, at, entry);
	}
	if (ptr == NULL)
		goto error;

	xfree(b);
	return (atr);

error:
	if (atr != NULL)
		attach_free(atr);

	if (b != NULL)
		xfree(b);
	return (NULL);
}
Ejemplo n.º 9
0
grub_err_t
grub_multiboot_load (grub_file_t file, const char *filename)
{
  char *buffer;
  grub_ssize_t len;
  struct multiboot_header *header;
  grub_err_t err;

  buffer = grub_malloc (MULTIBOOT_SEARCH);
  if (!buffer)
    return grub_errno;

  len = grub_file_read (file, buffer, MULTIBOOT_SEARCH);
  if (len < 32)
    {
      grub_free (buffer);
      if (!grub_errno)
	grub_error (GRUB_ERR_BAD_OS, N_("premature end of file %s"),
		    filename);
      return grub_errno;
    }

  grub_tpm_measure((unsigned char*)buffer, len, GRUB_KERNEL_PCR, filename);

  header = find_header (buffer, len);

  if (header == 0)
    {
      grub_free (buffer);
      return grub_error (GRUB_ERR_BAD_ARGUMENT, "no multiboot header found");
    }

  if (header->flags & UNSUPPORTED_FLAGS)
    {
      grub_free (buffer);
      return grub_error (GRUB_ERR_UNKNOWN_OS,
			 "unsupported flag: 0x%x", header->flags);
    }

  err = load_kernel (file, filename, buffer, header);
  if (err)
    {
      grub_free (buffer);
      return err;
    }

  if (header->flags & MULTIBOOT_VIDEO_MODE)
    {
      switch (header->mode_type)
	{
	case 1:
	  err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_EGA_TEXT, 
					    GRUB_MULTIBOOT_CONSOLE_EGA_TEXT
					    | GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
					    0, 0, 0, 0);
	  break;
	case 0:
	  err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
					    GRUB_MULTIBOOT_CONSOLE_EGA_TEXT
					    | GRUB_MULTIBOOT_CONSOLE_FRAMEBUFFER,
					    header->width, header->height,
					    header->depth, 0);
	  break;
	default:
	  err = grub_error (GRUB_ERR_BAD_OS, 
			    "unsupported graphical mode type %d",
			    header->mode_type);
	  break;
	}
    }
  else
    err = grub_multiboot_set_console (GRUB_MULTIBOOT_CONSOLE_EGA_TEXT, 
				      GRUB_MULTIBOOT_CONSOLE_EGA_TEXT,
				      0, 0, 0, 0);
  return err;
}
Ejemplo n.º 10
0
int
main (int argc, char **argv)
{
  int x = 0, y = 0, result[MAXBUFSIZE];
  char buf[MAXBUFSIZE];

  if (!(config_mak = fopen ("config.mak", "wb")))
    return -1;

  if (!(config_h = fopen ("config.h", "wb")))
    {
      fclose (config_mak);
      remove ("config.mak");

      return -1;
    }

  for (x = 0; configure_in[x].config_mak ||
       configure_in[x].config_h ||
       configure_in[x].success || configure_in[x].failure; x++)
    {
      st_configure_in_t *c = &configure_in[x];
      result[x] = 1;

      if (c->lib[0] || c->header[0] || c->file[0])
        {
          if (c->lib)
            for (y = 0; c->lib[y]; y++)
              if (find_lib (c->lib[y]) == -1)
                {
                  result[x] = 0;
                  break;
                }

          if (result[x])
            if (c->header)
              for (y = 0; c->header[y]; y++)
                if (find_header (c->header[y]) == -1)
                  {
                    result[x] = 0;
                    break;
                  }

          if (result[x])
            if (c->file)
              for (y = 0; c->file[y]; y++)
                if (find_file (c->file[y]) == -1)
                  {
                    result[x] = 0;
                    break;
                  }
        }

      if (result[x])
        {
          if (c->config_mak)
            fprintf (config_mak, "%s\n", c->config_mak);
          if (c->config_h)
            fputs (c->config_h, config_h);
        }
#if 0
      else
        {
          if (c->config_mak)
            fprintf (config_mak, "#%s\n", c->config_mak);
          if (c->config_h)
            fprintf (config_h, "/*\n%s\n*/\n", c->config_h);
        }
#endif
    }

  puts ("config.status: creating config.mak\n"
        "config.status: creating config.h\n");

  fclose (config_h);
  fclose (config_mak);

  for (x = 0; configure_in[x].config_mak ||
       configure_in[x].config_h ||
       configure_in[x].success || configure_in[x].failure; x++)
    {
      st_configure_in_t *c = &configure_in[x];

      if (result[x] && c->success)
        puts (c->success);
      if (!result[x] && c->failure)
        puts (c->failure);
    }

  puts
    ("\n");
//    ("\nYou may edit config.mak and/or config.h by hand to disable features\n");

  return 0;
}
Ejemplo n.º 11
0
static int lrc_read_header(AVFormatContext *s)
{
    LRCContext *lrc = s->priv_data;
    AVBPrint line;
    AVStream *st;

    st = avformat_new_stream(s, NULL);
    if(!st) {
        return AVERROR(ENOMEM);
    }
    avpriv_set_pts_info(st, 64, 1, 1000);
    lrc->ts_offset = 0;
    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
    st->codec->codec_id   = AV_CODEC_ID_TEXT;
    av_bprint_init(&line, 0, AV_BPRINT_SIZE_UNLIMITED);

    while(!avio_feof(s->pb)) {
        int64_t pos = read_line(&line, s->pb);
        int64_t header_offset = find_header(line.str);
        if(header_offset >= 0) {
            char *comma_offset = strchr(line.str, ':');
            if(comma_offset) {
                char *right_bracket_offset = strchr(line.str, ']');
                if(!right_bracket_offset) {
                    continue;
                }

                *right_bracket_offset = *comma_offset = '\0';
                if(strcmp(line.str + 1, "offset") ||
                   sscanf(comma_offset + 1, "%"SCNd64, &lrc->ts_offset) != 1) {
                    av_dict_set(&s->metadata, line.str + 1, comma_offset + 1, 0);
                }
                *comma_offset = ':';
                *right_bracket_offset = ']';
            }

        } else {
            AVPacket *sub;
            int64_t ts_start = AV_NOPTS_VALUE;
            int64_t ts_stroffset = 0;
            int64_t ts_stroffset_incr = 0;
            int64_t ts_strlength = count_ts(line.str);

            while((ts_stroffset_incr = read_ts(line.str + ts_stroffset,
                                               &ts_start)) != 0) {
                ts_stroffset += ts_stroffset_incr;
                sub = ff_subtitles_queue_insert(&lrc->q, line.str + ts_strlength,
                                                line.len - ts_strlength, 0);
                if(!sub) {
                    return AVERROR(ENOMEM);
                }
                sub->pos = pos;
                sub->pts = ts_start - lrc->ts_offset;
                sub->duration = -1;
            }
        }
    }
    ff_subtitles_queue_finalize(&lrc->q);
    ff_metadata_conv_ctx(s, NULL, ff_lrc_metadata_conv);
    return 0;
}
Ejemplo n.º 12
0
void SNESCartridge::read_header(const uint8_t *data, unsigned size) {
  type         = TypeUnknown;
  mapper       = LoROM;
  dsp1_mapper  = DSP1Unmapped;
  bsxpack_type = FlashROM;
  region       = NTSC;
  rom_size     = size;
  ram_size     = 0;

  has_bsx_slot   = false;
  has_spc7110rtc = false;
  has_srtc       = false;
  has_cx4        = false;
  has_dsp1       = false;
  has_dsp2       = false;
  has_dsp3       = false;
  has_dsp4       = false;
  has_obc1       = false;
  has_st010      = false;
  has_st011      = false;
  has_st018      = false;

  //=====================
  //detect Game Boy carts
  //=====================

  if(size >= 0x0140) {
    if(data[0x0104] == 0xce && data[0x0105] == 0xed && data[0x0106] == 0x66 && data[0x0107] == 0x66
    && data[0x0108] == 0xcc && data[0x0109] == 0x0d && data[0x010a] == 0x00 && data[0x010b] == 0x0b) {
      type = TypeGameBoy;
      return;
    }
  }

  if(size < 32768) {
    type = TypeUnknown;
    return;
  }

  const unsigned index = find_header(data, size);
  const uint8_t mapperid = data[index + Mapper];
  const uint8_t rom_type = data[index + RomType];
  const uint8_t rom_size = data[index + RomSize];
  const uint8_t company  = data[index + Company];
  const uint8_t regionid = data[index + CartRegion] & 0x7f;

  ram_size = 1024 << (data[index + RamSize] & 7);
  if(ram_size == 1024) ram_size = 0;  //no RAM present

  //0, 1, 13 = NTSC; 2 - 12 = PAL
  region = (regionid <= 1 || regionid >= 13) ? NTSC : PAL;

  //=======================
  //detect BS-X flash carts
  //=======================

  if(data[index + 0x13] == 0x00 || data[index + 0x13] == 0xff) {
    if(data[index + 0x14] == 0x00) {
      const uint8_t n15 = data[index + 0x15];
      if(n15 == 0x00 || n15 == 0x80 || n15 == 0x84 || n15 == 0x9c || n15 == 0xbc || n15 == 0xfc) {
        if(data[index + 0x1a] == 0x33 || data[index + 0x1a] == 0xff) {
          type = TypeBsx;
          bsxpack_type = (data[index + 0x10] == 0x00) ? MaskROM : FlashROM;
          region = NTSC;  //BS-X only released in Japan
          return;
        }
      }
    }
  }

  //=========================
  //detect Sufami Turbo carts
  //=========================

  if(!memcmp(data, "BANDAI SFC-ADX", 14)) {
    if(!memcmp(data + 16, "SFC-ADX BACKUP", 14)) {
      type = TypeSufamiTurboBios;
    } else {
      type = TypeSufamiTurbo;
    }
    mapper = STROM;
    region = NTSC;  //Sufami Turbo only released in Japan
    return;         //RAM size handled outside this routine
  }

  //==========================
  //detect Super Game Boy BIOS
  //==========================

  if(!memcmp(data + index, "Super GAMEBOY2", 14)) {
    type = TypeSuperGameBoy2Bios;
    mapper = SGBROM;
    return;
  }

  if(!memcmp(data + index, "Super GAMEBOY", 13)) {
    type = TypeSuperGameBoy1Bios;
    mapper = SGBROM;
    return;
  }

  //=====================
  //detect standard carts
  //=====================

  //detect presence of BS-X flash cartridge connector (reads extended header information)
  if(data[index - 14] == 'Z') {
    if(data[index - 11] == 'J') {
      uint8_t n13 = data[index - 13];
      if((n13 >= 'A' && n13 <= 'Z') || (n13 >= '0' && n13 <= '9')) {
        if(company == 0x33 || (data[index - 10] == 0x00 && data[index - 4] == 0x00)) {
          has_bsx_slot = true;
        }
      }
    }
  }

  if(has_bsx_slot) {
    if(!memcmp(data + index, "Satellaview BS-X     ", 21)) {
      //BS-X base cart
      type = TypeBsxBios;
      mapper = BSXROM;
      region = NTSC;  //BS-X only released in Japan
      return;         //RAM size handled internally by load_cart_bsx() -> BSXCart class
    } else {
      type = TypeBsxSlotted;
      mapper = (index == 0x7fc0 ? BSCLoROM : BSCHiROM);
      region = NTSC;  //BS-X slotted cartridges only released in Japan
    }
  } else {
    //standard cart
    type = TypeNormal;

    if(index == 0x7fc0) {
      mapper = LoROM;
    } else if(index == 0xffc0) {
      mapper = HiROM;
    } else {  //index == 0x40ffc0
      mapper = ExHiROM;
    }
  }

  if(mapperid == 0x20 && (rom_type == 0x13 || rom_type == 0x14 || rom_type == 0x15 || rom_type == 0x1a)) {
    mapper = SuperFXROM;
    ram_size = 1024 << (data[index - 3] & 7);
    if(ram_size == 1024) ram_size = 0;
  }

  if(mapperid == 0x23 && (rom_type == 0x32 || rom_type == 0x34 || rom_type == 0x35)) {
    mapper = SA1ROM;
  }

  if(mapperid == 0x32 && (rom_type == 0x43 || rom_type == 0x45)) {
    mapper = SDD1ROM;
  }

  if(mapperid == 0x3a && (rom_type == 0xf5 || rom_type == 0xf9)) {
    mapper = SPC7110ROM;
    has_spc7110rtc = (rom_type == 0xf9);
  }

  if(mapperid == 0x35 && rom_type == 0x55) {
    has_srtc = true;
  }

  if(mapperid == 0x20 && rom_type == 0xf3) {
    has_cx4 = true;
  }

  if((mapperid == 0x20 || mapperid == 0x21) && rom_type == 0x03) {
    has_dsp1 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x05 && company != 0xb2) {
    has_dsp1 = true;
  }

  if(mapperid == 0x31 && (rom_type == 0x03 || rom_type == 0x05)) {
    has_dsp1 = true;
  }

  if(has_dsp1) {
    if((mapperid & 0x2f) == 0x20 && size <= 0x100000) {
      dsp1_mapper = DSP1LoROM1MB;
    } else if((mapperid & 0x2f) == 0x20) {
      dsp1_mapper = DSP1LoROM2MB;
    } else if((mapperid & 0x2f) == 0x21) {
      dsp1_mapper = DSP1HiROM;
    }
  }

  if(mapperid == 0x20 && rom_type == 0x05) {
    has_dsp2 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x05 && company == 0xb2) {
    has_dsp3 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x03) {
    has_dsp4 = true;
  }

  if(mapperid == 0x30 && rom_type == 0x25) {
    has_obc1 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf6 && rom_size >= 10) {
    has_st010 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf6 && rom_size < 10) {
    has_st011 = true;
  }

  if(mapperid == 0x30 && rom_type == 0xf5) {
    has_st018 = true;
  }
}
Ejemplo n.º 13
0
LIBCOUCHSTORE_API
couchstore_error_t couchstore_open_db_ex(const char *filename,
                                         couchstore_open_flags flags,
                                         const couch_file_ops *ops,
                                         Db **pDb)
{
    couchstore_error_t errcode = COUCHSTORE_SUCCESS;
    Db *db;
    int openflags;

    /* Sanity check input parameters */
    if (filename == NULL || pDb == NULL || ops == NULL ||
            ops->version != 3 || ops->constructor == NULL || ops->open == NULL ||
            ops->close == NULL || ops->pread == NULL ||
            ops->pwrite == NULL || ops->goto_eof == NULL ||
            ops->sync == NULL || ops->destructor == NULL ||
            ((flags & COUCHSTORE_OPEN_FLAG_RDONLY) &&
             (flags & COUCHSTORE_OPEN_FLAG_CREATE))) {
        return COUCHSTORE_ERROR_INVALID_ARGUMENTS;
    }

    if ((db = calloc(1, sizeof(Db))) == NULL) {
        return COUCHSTORE_ERROR_ALLOC_FAIL;
    }

    if (flags & COUCHSTORE_OPEN_FLAG_RDONLY) {
        openflags = O_RDONLY;
    } else {
        openflags = O_RDWR;
    }

    if (flags & COUCHSTORE_OPEN_FLAG_CREATE) {
        openflags |= O_CREAT;
    }

    db->filename = strdup(filename);
    error_unless(db->filename, COUCHSTORE_ERROR_ALLOC_FAIL);

    db->file_ops = couch_get_buffered_file_ops(ops, &db->file_handle);
    error_unless(db->file_ops, COUCHSTORE_ERROR_ALLOC_FAIL);

    error_pass(db->file_ops->open(&db->file_handle, filename, openflags));

    if ((db->file_pos = db->file_ops->goto_eof(db->file_handle)) == 0) {
        /* This is an empty file. Create a new fileheader unless the
         * user wanted a read-only version of the file
         */
        if (flags & COUCHSTORE_OPEN_FLAG_RDONLY) {
            error_pass(COUCHSTORE_ERROR_NO_HEADER);
        } else {
            error_pass(create_header(db));
        }
    } else {
        error_pass(find_header(db));
    }

    *pDb = db;
    return COUCHSTORE_SUCCESS;

cleanup:
    couchstore_close_db(db);
    return errcode;
}