コード例 #1
0
ファイル: wav.c プロジェクト: Falcon-peregrinus/mlplayer
static gint wav_open(void)
{
    memcpy(&header.main_chunk, "RIFF", 4);
    header.length = GUINT32_TO_LE(0);
    memcpy(&header.chunk_type, "WAVE", 4);
    memcpy(&header.sub_chunk, "fmt ", 4);
    header.sc_len = GUINT32_TO_LE(16);
    header.format = GUINT16_TO_LE(1);
    header.modus = GUINT16_TO_LE(input.channels);
    header.sample_fq = GUINT32_TO_LE(input.frequency);
    if (input.format == FMT_U8 || input.format == FMT_S8)
        header.bit_p_spl = GUINT16_TO_LE(8);
    else
        header.bit_p_spl = GUINT16_TO_LE(16);
    header.byte_p_sec = GUINT32_TO_LE(input.frequency * header.modus * (GUINT16_FROM_LE(header.bit_p_spl) / 8));
    header.byte_p_spl = GUINT16_TO_LE((GUINT16_FROM_LE(header.bit_p_spl) / (8 / input.channels)));
    memcpy(&header.data_chunk, "data", 4);
    header.data_length = GUINT32_TO_LE(0);

    if (vfs_fwrite (& header, 1, sizeof header, output_file) != sizeof header)
        return 0;

    written = 0;

    return 1;
}
コード例 #2
0
ファイル: xfer.c プロジェクト: allanfreitas/msn-pecan
static gchar *
gen_context(const char *file_name,
            const char *file_path)
{
    struct stat st;
    gsize size = 0;
    MsnContextHeader header;
    gchar *u8 = NULL;
    guchar *base;
    guchar *n;
    gchar *ret;
    gunichar2 *uni = NULL;
    glong currentChar = 0;
    glong uni_len = 0;
    gsize len;

    if (g_stat(file_path, &st) == 0)
        size = st.st_size;

    if(!file_name) {
        u8 = purple_utf8_try_convert(g_basename(file_path));
        file_name = u8;
    }

    uni = g_utf8_to_utf16(file_name, -1, NULL, &uni_len, NULL);

    if(u8) {
        g_free(u8);
        file_name = NULL;
        u8 = NULL;
    }

    len = sizeof(MsnContextHeader) + MAX_FILE_NAME_LEN + 4;

    header.length = GUINT32_TO_LE(len);
    header.unk1 = GUINT32_TO_LE(2);
    header.file_size = GUINT32_TO_LE(size);
    header.unk2 = GUINT32_TO_LE(0);
    header.unk3 = GUINT32_TO_LE(0);

    base = g_malloc(len + 1);
    n = base;

    memcpy(n, &header, sizeof(MsnContextHeader));
    n += sizeof(MsnContextHeader);

    memset(n, 0x00, MAX_FILE_NAME_LEN);
    for(currentChar = 0; currentChar < uni_len; currentChar++) {
        *((gunichar2 *)n + currentChar) = GUINT16_TO_LE(uni[currentChar]);
    }
    n += MAX_FILE_NAME_LEN;

    memset(n, 0xFF, 4);
    n += 4;

    g_free(uni);
    ret = purple_base64_encode(base, len);
    g_free(base);
    return ret;
}
コード例 #3
0
ファイル: gf_packet.c プロジェクト: bf4/pidgin-mac
int gfire_create_im(PurpleConnection *gc, gfire_buddy *buddy, const char *msg)
{
	int length = 68+strlen(msg);
	int index = 0;
	gfire_data *gfire = NULL;
	guint32	msgtype = 0;
	guint32 imindex = 0;
	guint16 slen = strlen(msg);

	buddy->im++;
	imindex = GUINT32_TO_LE(buddy->im);
	msgtype = GUINT32_TO_LE(msgtype);
	slen = GUINT16_TO_LE(slen);
	gfire = (gfire_data *)gc->proto_data;	
	gfire_add_header(gfire->buff_out, length, 2, 2);/*add header*/
	index += 5;	

	gfire->buff_out[index] = strlen("sid"); index++;
	memcpy(gfire->buff_out + index, "sid", strlen("sid"));
	index+= strlen("sid");
	gfire->buff_out[index++] = 0x03;
	memcpy(gfire->buff_out+index,buddy->sid, XFIRE_SID_LEN);
	index += XFIRE_SID_LEN;

	gfire->buff_out[index] = strlen("peermsg"); index++;
	memcpy(gfire->buff_out + index, "peermsg", strlen("peermsg"));
	index+= strlen("peermsg");
	gfire->buff_out[index++] = 0x05;
	gfire->buff_out[index++] = 0x03;

	gfire->buff_out[index] = strlen("msgtype"); index++;
	memcpy(gfire->buff_out + index, "msgtype", strlen("msgtype"));
	index+= strlen("msgtype");
	gfire->buff_out[index++] = 0x02;
	memcpy(gfire->buff_out + index, &msgtype, sizeof(msgtype));
	index+= sizeof(msgtype);
	
	gfire->buff_out[index] = strlen("imindex"); index++;
	memcpy(gfire->buff_out + index, "imindex", strlen("imindex"));
	index+= strlen("imindex");
	gfire->buff_out[index++] = 0x02;
	memcpy(gfire->buff_out + index, &imindex, sizeof(imindex));
	index+= sizeof(imindex);

	gfire->buff_out[index] = strlen("im"); index++;
	memcpy(gfire->buff_out + index, "im", strlen("im"));
	index+= strlen("im");
	gfire->buff_out[index++] = 0x01;
	memcpy(gfire->buff_out + index, &slen, sizeof(slen));
	index+= sizeof(slen);
	
	memcpy(gfire->buff_out+index, msg, strlen(msg));
	index += strlen(msg);

	return index;

}
コード例 #4
0
ファイル: gstwavenc.c プロジェクト: ted-n/gst-plugins-good
static void
write_metadata (GstWavEnc * wavenc)
{
  GString *info_str;
  GList *props;
  int total = 4;
  gboolean need_to_write = FALSE;

  info_str = g_string_new ("LIST    INFO");

  for (props = wavenc->metadata->properties->properties; props;
      props = props->next) {
    GstPropsEntry *entry = props->data;
    const char *name;
    guint32 id;

    name = gst_props_entry_get_name (entry);
    id = get_id_from_name (name);
    if (id != 0) {
      const char *text;
      char *tmp;
      int len, req, i;

      need_to_write = TRUE;     /* We've got at least one entry */

      gst_props_entry_get_string (entry, &text);
      len = strlen (text) + 1;  /* The length in the file includes the \0 */

      tmp = g_strdup_printf ("%" GST_FOURCC_FORMAT "%d%s", GST_FOURCC_ARGS (id),
          GUINT32_TO_LE (len), text);
      g_string_append (info_str, tmp);
      g_free (tmp);

      /* Check that we end on an even boundary */
      req = ((len + 8) + 1) & ~1;
      for (i = 0; i < req - len; i++) {
        g_string_append_printf (info_str, "%c", 0);
      }

      total += req;
    }
  }

  if (need_to_write) {
    GstBuffer *buf;

    /* Now we've got all the strings together, we can write our length in */
    info_str->str[4] = GUINT32_TO_LE (total);

    buf = gst_buffer_new ();
    gst_buffer_set_data (buf, info_str->str, info_str->len);

    gst_pad_push (wavenc->srcpad, GST_DATA (buf));
    g_string_free (info_str, FALSE);
  }
}
コード例 #5
0
static void
fill_wave_header(struct wave_header *header, int channels, int bits, 
		int freq, int block_size)
{
	int data_size = 0x0FFFFFFF;

	/* constants */
	header->id_riff = GUINT32_TO_LE(0x46464952);
	header->id_wave = GUINT32_TO_LE(0x45564157);
	header->id_fmt = GUINT32_TO_LE(0x20746d66);
	header->id_data = GUINT32_TO_LE(0x61746164);

        /* wave format */
	header->format = GUINT16_TO_LE(1);		// PCM_FORMAT
	header->channels = GUINT16_TO_LE(channels);
	header->bits = GUINT16_TO_LE(bits);
	header->freq = GUINT32_TO_LE(freq);
	header->blocksize = GUINT16_TO_LE(block_size);
	header->byterate = GUINT32_TO_LE(freq * block_size);

        /* chunk sizes (fake data length) */
	header->fmt_size = GUINT32_TO_LE(16);
	header->data_size = GUINT32_TO_LE(data_size);
	header->riff_size = GUINT32_TO_LE(4 + (8 + 16) +
					 (8 + data_size));
}
コード例 #6
0
ファイル: wav.c プロジェクト: Falcon-peregrinus/mlplayer
static void wav_close(void)
{
    if (output_file)
    {
        header.length = GUINT32_TO_LE(written + sizeof (struct wavhead) - 8);
        header.data_length = GUINT32_TO_LE(written);

        if (vfs_fseek (output_file, 0, SEEK_SET) || vfs_fwrite (& header, 1,
         sizeof header, output_file) != sizeof header)
            fprintf (stderr, "Error while writing to .wav output file.\n");
    }
}
コード例 #7
0
/* Write a record for a packet to a dump file.
   Returns TRUE on success, FALSE on failure. */
static gboolean _5views_dump(wtap_dumper *wdh,
	const struct wtap_pkthdr *phdr,
	const guint8 *pd, int *err)
{
	_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
	t_5VW_TimeStamped_Header HeaderFrame;

	/* Frame Header */
	/* constant fields */
	HeaderFrame.Key = GUINT32_TO_LE(CST_5VW_RECORDS_HEADER_KEY);
	HeaderFrame.HeaderSize = GUINT16_TO_LE(sizeof(t_5VW_TimeStamped_Header));
	HeaderFrame.HeaderType = GUINT16_TO_LE(CST_5VW_TIMESTAMPED_HEADER_TYPE);
	HeaderFrame.RecType = GUINT32_TO_LE(CST_5VW_CAPTURES_RECORD | CST_5VW_SYSTEM_RECORD);
	HeaderFrame.RecSubType = GUINT32_TO_LE(CST_5VW_FRAME_RECORD);
	HeaderFrame.RecNb = GUINT32_TO_LE(1);

	/* record-dependent fields */
	HeaderFrame.Utc = GUINT32_TO_LE(phdr->ts.secs);
	HeaderFrame.NanoSecondes = GUINT32_TO_LE(phdr->ts.nsecs);
	HeaderFrame.RecSize = GUINT32_TO_LE(phdr->len);
	HeaderFrame.RecInfo = GUINT32_TO_LE(0);

	/* write the record header */
	if (!wtap_dump_file_write(wdh, &HeaderFrame,
	    sizeof(t_5VW_TimeStamped_Header), err))
		return FALSE;

	/* write the data */
	if (!wtap_dump_file_write(wdh, pd, phdr->caplen, err))
		return FALSE;

	_5views->nframes ++;

	return TRUE;
}
コード例 #8
0
ファイル: tnef.c プロジェクト: DHODoS/wireshark
wtap_open_return_val tnef_open(wtap *wth, int *err, gchar **err_info)
{
  guint32 magic;

  if (!wtap_read_bytes(wth->fh, &magic, sizeof magic, err, err_info))
    return (*err != WTAP_ERR_SHORT_READ) ? WTAP_OPEN_ERROR : WTAP_OPEN_NOT_MINE;

  if (GUINT32_TO_LE(magic) != TNEF_SIGNATURE)
     /* Not a tnef file */
     return WTAP_OPEN_NOT_MINE;

  /* seek back to the start of the file  */
  if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
    return WTAP_OPEN_ERROR;

  wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_TNEF;
  wth->file_encap = WTAP_ENCAP_TNEF;
  wth->snapshot_length = 0;

  wth->subtype_read = tnef_read;
  wth->subtype_seek_read = tnef_seek_read;
  wth->file_tsprec = WTAP_TSPREC_SEC;

  return WTAP_OPEN_MINE;
}
コード例 #9
0
ファイル: slpmsg.c プロジェクト: arminius2/apolloim
void
msn_slpmsg_show(MsnMessage *msg)
{
	const char *info;
	gboolean text;
	guint32 flags;

	text = FALSE;

	flags = GUINT32_TO_LE(msg->msnslp_header.flags);

	switch (flags)
	{
		case 0x0:
			info = "SLP CONTROL";
			text = TRUE;
			break;
		case 0x2:
			info = "SLP ACK"; break;
		case 0x20:
		case 0x1000030:
			info = "SLP DATA"; break;
		default:
			info = "SLP UNKNOWN"; break;
	}

	msn_message_show_readable(msg, info, text);
}
コード例 #10
0
ファイル: tnef.c プロジェクト: dot-Sean/wireshark-http2
int tnef_open(wtap *wth, int *err, gchar **err_info)
{
  int bytes_read;
  guint32 magic;

  bytes_read = file_read(&magic, sizeof magic, wth->fh);
  if (bytes_read != sizeof magic) {
    *err = file_error(wth->fh, err_info);
    return (*err != 0) ? -1 : 0;
  }

  if (GUINT32_TO_LE(magic) != TNEF_SIGNATURE)
     /* Not a tnef file */
     return 0;

  /* seek back to the start of the file  */
  if (file_seek(wth->fh, 0, SEEK_SET, err) == -1)
    return -1;

  wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_TNEF;
  wth->file_encap = WTAP_ENCAP_TNEF;
  wth->snapshot_length = 0;

  wth->subtype_read = tnef_read;
  wth->subtype_seek_read = tnef_seek_read;
  wth->tsprecision = WTAP_FILE_TSPREC_SEC;

  return 1;
}
コード例 #11
0
ファイル: message.c プロジェクト: MrBitKoin/picocoin
GString *message_str(const unsigned char netmagic[4],
		     const char *command_,
		     const void *data, uint32_t data_len)
{
	GString *s = g_string_sized_new(P2P_HDR_SZ + data_len);

	/* network identifier (magic number) */
	g_string_append_len(s, (gchar *) netmagic, 4);

	/* command string */
	char command[12] = {};
	strncpy(command, command_, 12);
	g_string_append_len(s, command, 12);

	/* data length */
	uint32_t data_len_le = GUINT32_TO_LE(data_len);
	g_string_append_len(s, (gchar *) &data_len_le, 4);

	/* data checksum */
	unsigned char md32[4];

	bu_Hash4(md32, data, data_len);

	g_string_append_len(s, (gchar *) &md32[0], 4);

	/* data payload */
	if (data_len > 0)
		g_string_append_len(s, data, data_len);

	return s;
}
コード例 #12
0
static void
msn_dc_send_cb(gpointer data, gint fd, PurpleInputCondition cond)
{
	MsnDirectConn *dc = data;
	MsnDirectConnPacket *p;
	int bytes_to_send;
	int bytes_sent;

	g_return_if_fail(dc != NULL);
	g_return_if_fail(fd != -1);

	if (g_queue_is_empty(dc->out_queue)) {
		if (dc->send_handle != 0) {
			purple_input_remove(dc->send_handle);
			dc->send_handle = 0;
		}
		return;
	}

	p = g_queue_peek_head(dc->out_queue);

	if (dc->msg_pos < 0) {
		/* First we send the length of the packet */
		guint32 len = GUINT32_TO_LE(p->length);
		bytes_sent = send(fd, &len, 4, 0);
		if (bytes_sent < 0) {
			if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
				return;

			purple_debug_warning("msn", "msn_dc_send_cb: send error\n");
			msn_dc_destroy(dc);
			return;
		}
		dc->msg_pos = 0;
	}

	bytes_to_send = p->length - dc->msg_pos;
	bytes_sent = send(fd, p->data + dc->msg_pos, bytes_to_send, 0);
	if (bytes_sent < 0) {
		if ((errno == EAGAIN) || (errno == EWOULDBLOCK))
			return;

		purple_debug_warning("msn", "msn_dc_send_cb: send error\n");
		msn_dc_destroy(dc);
		return;
	}

	dc->progress = TRUE;

	dc->msg_pos += bytes_sent;
	if (dc->msg_pos == p->length) {
		if (p->sent_cb != NULL)
			p->sent_cb(p);

		g_queue_pop_head(dc->out_queue);
		msn_dc_destroy_packet(p);

		dc->msg_pos = -1;
	}
}
コード例 #13
0
ファイル: directconn.c プロジェクト: VoxOx/VoxOx
void
msn_directconn_parse_nonce(MsnDirectConn *directconn, const char *nonce)
{
	guint32 t1;
	guint16 t2;
	guint16 t3;
	guint16 t4;
	guint64 t5;

	g_return_if_fail(directconn != NULL);
	g_return_if_fail(nonce      != NULL);

	sscanf (nonce, "%08X-%04hX-%04hX-%04hX-%012llX", &t1, &t2, &t3, &t4, &t5);

	t1 = GUINT32_TO_LE(t1);
	t2 = GUINT16_TO_LE(t2);
	t3 = GUINT16_TO_LE(t3);
	t4 = GUINT16_TO_BE(t4);
	t5 = GUINT64_TO_BE(t5);

	directconn->slpheader = g_new0(MsnSlpHeader, 1);

	directconn->slpheader->ack_id     = t1;
	directconn->slpheader->ack_sub_id = t2 | (t3 << 16);
	directconn->slpheader->ack_size   = t4 | t5;
}
コード例 #14
0
ファイル: data.c プロジェクト: anarsoul/libfprint
/** \ingroup print_data
 * Convert a stored print into a unified representation inside a data buffer.
 * You can then store this data buffer in any way that suits you, and load
 * it back at some later time using fp_print_data_from_data().
 * \param data the stored print
 * \param ret output location for the data buffer. Must be freed with free()
 * after use.
 * \returns the size of the freshly allocated buffer, or 0 on error.
 */
API_EXPORTED size_t fp_print_data_get_data(struct fp_print_data *data,
	unsigned char **ret)
{
	struct fpi_print_data_fp2 *out_data;
	struct fpi_print_data_item_fp2 *out_item;
	struct fp_print_data_item *item;
	size_t buflen = 0;
	GSList *list_item;
	unsigned char *buf;

	fp_dbg("");

	list_item = data->prints;
	while (list_item) {
		item = list_item->data;
		buflen += sizeof(*out_item);
		buflen += item->length;
		list_item = g_slist_next(list_item);
	}

	buflen += sizeof(*out_data);
	out_data = g_malloc(buflen);

	*ret = (unsigned char *) out_data;
	buf = out_data->data;
	out_data->prefix[0] = 'F';
	out_data->prefix[1] = 'P';
	out_data->prefix[2] = '2';
	out_data->driver_id = GUINT16_TO_LE(data->driver_id);
	out_data->devtype = GUINT32_TO_LE(data->devtype);
	out_data->data_type = data->type;

	list_item = data->prints;
	while (list_item) {
		item = list_item->data;
		out_item = (struct fpi_print_data_item_fp2 *)buf;
		out_item->length = GUINT32_TO_LE(item->length);
		/* FIXME: fp_print_data_item->data content is not endianess agnostic */
		memcpy(out_item->data, item->data, item->length);
		buf += sizeof(*out_item);
		buf += item->length;
		list_item = g_slist_next(list_item);
	}

	return buflen;
}
コード例 #15
0
ファイル: dfu-format-dfuse.c プロジェクト: superm1/fwupd
/**
 * dfu_element_to_dfuse: (skip)
 * @element: a #DfuElement
 *
 * Packs a DfuSe element.
 *
 * Returns: (transfer full): the packed data
 **/
static GBytes *
dfu_element_to_dfuse (DfuElement *element)
{
	DfuSeElementPrefix *el;
	const guint8 *data;
	gsize length;
	guint8 *buf;

	data = g_bytes_get_data (dfu_element_get_contents (element), &length);
	buf = g_malloc0 (length + sizeof (DfuSeElementPrefix));
	el = (DfuSeElementPrefix *) buf;
	el->address = GUINT32_TO_LE (dfu_element_get_address (element));
	el->size = GUINT32_TO_LE (length);

	memcpy (buf + sizeof (DfuSeElementPrefix), data, length);
	return g_bytes_new_take (buf, length + sizeof (DfuSeElementPrefix));
}
コード例 #16
0
ファイル: directconn.c プロジェクト: VoxOx/VoxOx
static size_t
msn_directconn_write(MsnDirectConn *directconn,
					 const char *data, size_t len)
{
	char *buffer, *tmp;
	size_t buf_size;
	size_t ret;
	guint32 sent_len;

	g_return_val_if_fail(directconn != NULL, 0);

	buf_size = len + 4;
	buffer = tmp = g_malloc(buf_size);

	sent_len = GUINT32_TO_LE(len);

	memcpy(tmp, &sent_len, 4);
	tmp += 4;
	memcpy(tmp, data, len);
	tmp += len;

	ret = write(directconn->fd, buffer, buf_size);

#ifdef DEBUG_DC
	char *str;
	str = g_strdup_printf("%s/msntest/w%.4d.bin", g_get_home_dir(), directconn->c);

	FILE *tf = g_fopen(str, "w");
	fwrite(buffer, 1, buf_size, tf);
	fclose(tf);

	g_free(str);
#endif

	g_free(buffer);

#if 0
	/* Let's write the length of the data. */
	ret = write(directconn->fd, &len, sizeof(len));

	/* Let's write the data. */
	ret = write(directconn->fd, data, len);

	char *str;
	str = g_strdup_printf("/home/revo/msntest/w%.4d.bin", directconn->c);

	FILE *tf = g_fopen(str, "w");
	fwrite(&len, 1, sizeof(len), tf);
	fwrite(data, 1, len, tf);
	fclose(tf);

	g_free(str);
#endif

	directconn->c++;

	return ret;
}
コード例 #17
0
ファイル: dfu-element.c プロジェクト: attente/fwupd
/**
 * dfu_element_to_dfuse: (skip)
 * @element: a #DfuElement
 *
 * Packs a DfuSe element.
 *
 * Returns: (transfer full): the packed data
 **/
GBytes *
dfu_element_to_dfuse (DfuElement *element)
{
	DfuElementPrivate *priv = GET_PRIVATE (element);
	DfuSeElementPrefix *el;
	const guint8 *data;
	gsize length;
	guint8 *buf;

	data = g_bytes_get_data (priv->contents, &length);
	buf = g_malloc0 (length + sizeof (DfuSeElementPrefix));
	el = (DfuSeElementPrefix *) buf;
	el->address = GUINT32_TO_LE (priv->address);
	el->size = GUINT32_TO_LE (length);

	memcpy (buf + sizeof (DfuSeElementPrefix), data, length);
	return g_bytes_new_take (buf, length + sizeof (DfuSeElementPrefix));
}
コード例 #18
0
/* No need to access it from outside */
static struct message1 * encode_connection_request(struct connection_request * req) {
  struct message1 * msg;
  msg = (struct message1 *)calloc(1, sizeof(struct message1));

  msg->function = GUINT32_TO_LE(0x0003bef4);
  msg->counter = GUINT32_TO_LE(1);

  msg->client_size = 9;
  memcpy(msg->client, "TeamSpeak", 9);

  /* cut machine if too long */
  if(strlen(req->machine) > 29)
    req->machine[29] = '\0';
  msg->machine_size = (uint8_t)strlen(req->machine);
  memcpy(msg->machine, req->machine, strlen(req->machine));

  msg->data1 = GUINT32_TO_LE(0x02000000);
  msg->data2 = GUINT32_TO_LE(0x20003C00);

  msg->assign_nick = req->assign_nick;
  msg->always1 = 0x01;

  /* Insert login */
  if(strlen(req->login) > 29)
    req->login[29] = '\0';
  msg->login_size = (uint8_t)strlen(req->login);
  memcpy(msg->login, req->login, strlen(req->login));

  /* Insert password */
  if(strlen(req->pass) > 29)
    req->pass[29] = '\0';
  msg->pass_size = (uint8_t)strlen(req->pass);
  memcpy(msg->pass, req->pass, strlen(req->pass));

  /* Insert nick */
  if(strlen(req->nick) > 29)
    req->nick[29] = '\0';
  msg->nick_size = (uint8_t)strlen(req->nick);
  memcpy(msg->nick, req->nick, strlen(req->nick));

  msg->checksum = GINT32_TO_LE(crc_32(msg, sizeof(struct message1), 0xEDB88320));

  return msg;
}
コード例 #19
0
static gboolean _5views_dump_close(wtap_dumper *wdh, int *err)
{
	_5views_dump_t *_5views = (_5views_dump_t *)wdh->priv;
	t_5VW_Capture_Header file_hdr;

	if (wtap_dump_file_seek(wdh, 0, SEEK_SET, err) == -1)
		return FALSE;

	/* fill in the Info_Header */
	file_hdr.Info_Header.Signature = GUINT32_TO_LE(CST_5VW_INFO_HEADER_KEY);
	file_hdr.Info_Header.Size = GUINT32_TO_LE(sizeof(t_5VW_Info_Header));	/* Total size of Header in bytes (included Signature) */
	file_hdr.Info_Header.Version = GUINT32_TO_LE(CST_5VW_INFO_RECORD_VERSION); /* Identify version and so the format of this record */
	file_hdr.Info_Header.DataSize = GUINT32_TO_LE(sizeof(t_5VW_Attributes_Header)
					+ sizeof(guint32)
					+ sizeof(t_5VW_Attributes_Header)
					+ sizeof(guint32));
					/* Total size of data included in the Info Record (except the header size) */
	file_hdr.Info_Header.FileType = GUINT32_TO_LE(wtap_encap[wdh->encap]);	/* Type of the file */
	file_hdr.Info_Header.Reserved[0] = 0;	/* Reserved for future use */
	file_hdr.Info_Header.Reserved[1] = 0;	/* Reserved for future use */
	file_hdr.Info_Header.Reserved[2] = 0;	/* Reserved for future use */

	/* fill in the HeaderDateCreation */
	file_hdr.HeaderDateCreation.Type = GUINT32_TO_LE(CST_5VW_IA_DATE_CREATION);	/* Id of the attribute */
	file_hdr.HeaderDateCreation.Size = GUINT16_TO_LE(sizeof(guint32));	/* Size of the data part of the attribute (not including header size) */
	file_hdr.HeaderDateCreation.Nb = GUINT16_TO_LE(1);			/* Number of elements */

	/* fill in the Time field */
#ifdef _WIN32
	_tzset();
#endif
	file_hdr.Time = GUINT32_TO_LE(time(NULL));

	/* fill in the Time field */
	file_hdr.HeaderNbFrames.Type = GUINT32_TO_LE(CST_5VW_IA_CAP_INF_NB_TRAMES_STOCKEES);	/* Id of the attribute */
	file_hdr.HeaderNbFrames.Size = GUINT16_TO_LE(sizeof(guint32));	/* Size of the data part of the attribute (not including header size) */
	file_hdr.HeaderNbFrames.Nb = GUINT16_TO_LE(1);			/* Number of elements */

	/* fill in the number of frames saved */
	file_hdr.TramesStockeesInFile = GUINT32_TO_LE(_5views->nframes);

	/* Write the file header. */
	if (!wtap_dump_file_write(wdh, &file_hdr, sizeof(t_5VW_Capture_Header),
	    err))
		return FALSE;

	return TRUE;
}
コード例 #20
0
ファイル: packet_tools.c プロジェクト: Lv/soliloque-server
/**
 * Add a crc to a given data packet.
 *
 * @param data the packet
 * @param len the length of the packet
 * @param offset the offset where we want to write our checksum.
 */
void packet_add_crc(char *data, size_t len, unsigned int offset)
{
	char *ptr = data + offset;
	uint32_t new_crc;
	uint32_t *crc_ptr = (uint32_t *)ptr;
	
	*crc_ptr = 0x00000000;
	new_crc = GUINT32_TO_LE(crc_32(data, len, 0xEDB88320));
	*crc_ptr = new_crc;
}
コード例 #21
0
ファイル: dfu-format-dfuse.c プロジェクト: superm1/fwupd
/**
 * dfu_image_to_dfuse: (skip)
 * @image: a #DfuImage
 *
 * Packs a DfuSe image
 *
 * Returns: (transfer full): the packed data
 **/
static GBytes *
dfu_image_to_dfuse (DfuImage *image)
{
	DfuSeImagePrefix *im;
	GPtrArray *elements;
	guint32 length_total = 0;
	guint32 offset = sizeof (DfuSeImagePrefix);
	guint8 *buf;
	g_autoptr(GPtrArray) element_array = NULL;

	/* get total size */
	element_array = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
	elements = dfu_image_get_elements (image);
	for (guint i = 0; i < elements->len; i++) {
		DfuElement *element = g_ptr_array_index (elements, i);
		GBytes *bytes = dfu_element_to_dfuse (element);
		g_ptr_array_add (element_array, bytes);
		length_total += (guint32) g_bytes_get_size (bytes);
	}

	/* add prefix */
	buf = g_malloc0 (length_total + sizeof (DfuSeImagePrefix));
	im = (DfuSeImagePrefix *) buf;
	memcpy (im->sig, "Target", 6);
	im->alt_setting = dfu_image_get_alt_setting (image);
	if (dfu_image_get_name (image) != NULL) {
		im->target_named = GUINT32_TO_LE (0x01);
		memcpy (im->target_name, dfu_image_get_name (image), 255);
	}
	im->target_size = GUINT32_TO_LE (length_total);
	im->elements = GUINT32_TO_LE (elements->len);

	/* copy data */
	for (guint i = 0; i < element_array->len; i++) {
		gsize length;
		GBytes *bytes = g_ptr_array_index (element_array, i);
		const guint8 *data = g_bytes_get_data (bytes, &length);
		memcpy (buf + offset, data, length);
		offset += (guint32) length;
	}
	return g_bytes_new_take (buf, length_total + sizeof (DfuSeImagePrefix));
}
コード例 #22
0
ファイル: swfdec_bots.c プロジェクト: fengye/swfdec
/* If little endian x86 byte order is 0 1 2 3 4 5 6 7 and PPC32 byte order is
 * 7 6 5 4 3 2 1 0, then Flash uses 4 5 6 7 0 1 2 3. */
void
swfdec_bots_put_double (SwfdecBots *bots, double value)
{
  union {
    guint32 i[2];
    double d;
  } conv;

  swfdec_bots_ensure_bits (bots, 8);

  conv.d = value;

#if G_BYTE_ORDER == G_LITTLE_ENDIAN
  swfdec_bots_put_u32 (bots, conv.i[1]);
  swfdec_bots_put_u32 (bots, conv.i[0]);
#else
  swfdec_bots_put_u32 (bots, GUINT32_TO_LE (conv.i[0]));
  swfdec_bots_put_u32 (bots, GUINT32_TO_LE (conv.i[1]));
#endif
}
コード例 #23
0
ファイル: gf_packet.c プロジェクト: bf4/pidgin-mac
/*
*Sends the packet when we join a game or leave it (gameid 00 00)
*/
int gfire_join_game_create(PurpleConnection *gc, int game, int port, const char *ip)
{
	int index = XFIRE_HEADER_LEN;
	gfire_data *gfire = NULL;
	guint32 gport = port;
	guint32 gameid = game;
	const char nullip[4] = {0x00, 0x00, 0x00, 0x00};
	
	if (!gc || !(gfire = (gfire_data *)gc->proto_data)) return 0;
	if (!ip) ip = (char *)&nullip;

	gport = GUINT32_TO_LE(gport);
	gameid = GUINT32_TO_LE(gameid);

	gfire->buff_out[index++] = strlen("gameid");
	memcpy(gfire->buff_out + index, "gameid", strlen("gameid"));
	index += strlen("gameid");
	gfire->buff_out[index++] = 0x02;
	memcpy(gfire->buff_out + index, &gameid, sizeof(gameid));
	index += sizeof(gameid);	

	gfire->buff_out[index++] = strlen("gip");
	memcpy(gfire->buff_out + index, "gip", strlen("gip"));
	index += strlen("gip");
	gfire->buff_out[index++] = 0x02;
	gfire->buff_out[index++] = ip[0];
	gfire->buff_out[index++] = ip[1];
	gfire->buff_out[index++] = ip[2];
	gfire->buff_out[index++] = ip[3];

	gfire->buff_out[index++] = strlen("gport");
	memcpy(gfire->buff_out + index, "gport", strlen("gport"));
	index += strlen("gport");
	gfire->buff_out[index++] = 0x02;
	memcpy(gfire->buff_out + index, &gport, sizeof(gport));
	index += sizeof(gport);

	gfire_add_header(gfire->buff_out, index, 4, 3);

	return index;
}
コード例 #24
0
guint16 gfire_chat_proto_create_change_access(const guint8 *p_cid, guint32 p_access)
{
	guint32 offset = XFIRE_HEADER_LEN;

	if(!p_cid)
		return 0;

	guint32 climsg = GUINT32_TO_LE(0x4D16);
	offset = gfire_proto_write_attr_ss("climsg", 0x02, &climsg, sizeof(climsg), offset);

	offset = gfire_proto_write_attr_ss("msg", 0x09, NULL, 2, offset);

	offset = gfire_proto_write_attr_bs(0x04, 0x06, p_cid, XFIRE_CHATID_LEN, offset);

	p_access = GUINT32_TO_LE(p_access);
	offset = gfire_proto_write_attr_bs(0x17, 0x02, &p_access, sizeof(p_access), offset);

	gfire_proto_write_header(offset, 0x19, 2, 0);

	return offset;
}
コード例 #25
0
guint16 gfire_chat_proto_create_kick_buddy(const guint8 *p_cid, guint32 p_userid)
{
	guint32 offset = XFIRE_HEADER_LEN;

	if(!p_cid)
		return 0;

	guint32 climsg = GUINT32_TO_LE(0x4CFB);
	offset = gfire_proto_write_attr_ss("climsg", 0x02, &climsg, sizeof(climsg), offset);

	offset = gfire_proto_write_attr_ss("msg", 0x09, NULL, 2, offset);

	offset = gfire_proto_write_attr_bs(0x04, 0x06, p_cid, XFIRE_CHATID_LEN, offset);

	p_userid = GUINT32_TO_LE(p_userid);
	offset = gfire_proto_write_attr_bs(0x18, 0x02, &p_userid, sizeof(p_userid), offset);

	gfire_proto_write_header(offset, 0x19, 2, 0);

	return offset;
}
コード例 #26
0
ファイル: fu-wac-common.c プロジェクト: vathpela/fwupd
guint32
fu_wac_calculate_checksum32le (const guint8 *data, gsize len)
{
	guint32 csum = 0x0;
	g_return_val_if_fail (len % 4 == 0, 0xff);
	for (guint i = 0; i < len; i += 4) {
		guint32 tmp;
		memcpy (&tmp, &data[i], sizeof(guint32));
		csum += GUINT32_FROM_LE (tmp);
	}
	return GUINT32_TO_LE (csum);
}
コード例 #27
0
ファイル: partutil.c プロジェクト: paulcbetts/gformat
static gboolean
set_le_guid (guint8 *buf, const char *source)
{
	efi_guid *guid = (efi_guid *) buf;
	guint32 __attribute__((__unused__)) data1;
	guint16 __attribute__((__unused__)) data2;
	guint16 __attribute__((__unused__)) data3;
	guint8  __attribute__((__unused__)) data4[8];
	gboolean ret;
	int n;

	n = sscanf (source, "%x-%hx-%hx-%02hhx%02hhx-%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx",
		    &guid->data1,
		    &guid->data2,
		    &guid->data3,
		    &(guid->data4[0]),
		    &(guid->data4[1]),
		    &(guid->data4[2]),
		    &(guid->data4[3]),
		    &(guid->data4[4]),
		    &(guid->data4[5]),
		    &(guid->data4[6]),
		    &(guid->data4[7]));

	if (n != 11) {
		HAL_INFO (("guid '%s' is not valid"));
		goto out;
	}

#if 0
	HAL_INFO (("source = %s", source));
	HAL_INFO (("data1 = %08x", guid->data1));
	HAL_INFO (("data2 = %04x", guid->data2));
	HAL_INFO (("data3 = %04x", guid->data3));
	HAL_INFO (("data4[0] = %02x", guid->data4[0]));
	HAL_INFO (("data4[1] = %02x", guid->data4[1]));
	HAL_INFO (("data4[2] = %02x", guid->data4[2]));
	HAL_INFO (("data4[3] = %02x", guid->data4[3]));
	HAL_INFO (("data4[4] = %02x", guid->data4[4]));
	HAL_INFO (("data4[5] = %02x", guid->data4[5]));
	HAL_INFO (("data4[6] = %02x", guid->data4[6]));
	HAL_INFO (("data4[7] = %02x", guid->data4[7]));
#endif

	guid->data1 = GUINT32_TO_LE (guid->data1);
	guid->data2 = GUINT16_TO_LE (guid->data2);
	guid->data3 = GUINT16_TO_LE (guid->data3);

	ret = TRUE;

out:
	return ret;
}
コード例 #28
0
guint16 gfire_chat_proto_create_set_default_permission(const guint8 *p_cid, guint32 p_permission)
{
	guint32 offset = XFIRE_HEADER_LEN;

	if(!p_cid)
		return 0;

	guint32 climsg = GUINT32_TO_LE(0x4D08);
	offset = gfire_proto_write_attr_ss("climsg", 0x02, &climsg, sizeof(climsg), offset);

	offset = gfire_proto_write_attr_ss("msg", 0x09, NULL, 2, offset);

	offset = gfire_proto_write_attr_bs(0x04, 0x06, p_cid, XFIRE_CHATID_LEN, offset);

	p_permission = GUINT32_TO_LE(p_permission);
	offset = gfire_proto_write_attr_bs(0x13, 0x02, &p_permission, sizeof(p_permission), offset);

	gfire_proto_write_header(offset, 0x19, 2, 0);

	return offset;
}
コード例 #29
0
ファイル: dfu-format-dfuse.c プロジェクト: superm1/fwupd
/**
 * dfu_firmware_to_dfuse: (skip)
 * @firmware: a #DfuFirmware
 * @error: a #GError, or %NULL
 *
 * Packs a DfuSe firmware
 *
 * Returns: (transfer full): the packed data
 **/
GBytes *
dfu_firmware_to_dfuse (DfuFirmware *firmware, GError **error)
{
	DfuSePrefix *prefix;
	GPtrArray *images;
	guint32 image_size_total = 0;
	guint32 offset = sizeof (DfuSePrefix);
	g_autofree guint8 *buf = NULL;
	g_autoptr(GPtrArray) dfuse_images = NULL;

	/* get all the image data */
	dfuse_images = g_ptr_array_new_with_free_func ((GDestroyNotify) g_bytes_unref);
	images = dfu_firmware_get_images (firmware);
	for (guint i = 0; i < images->len; i++) {
		DfuImage *im = g_ptr_array_index (images, i);
		GBytes *contents;
		contents = dfu_image_to_dfuse (im);
		image_size_total += (guint32) g_bytes_get_size (contents);
		g_ptr_array_add (dfuse_images, contents);
	}
	g_debug ("image_size_total: %" G_GUINT32_FORMAT, image_size_total);

	buf = g_malloc0 (sizeof (DfuSePrefix) + image_size_total);

	/* DfuSe header */
	prefix = (DfuSePrefix *) buf;
	memcpy (prefix->sig, "DfuSe", 5);
	prefix->ver = 0x01;
	prefix->image_size = GUINT32_TO_LE (offset + image_size_total);
	if (images->len > G_MAXUINT8) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INTERNAL,
			     "too many (%u) images to write DfuSe file",
			     images->len);
		return NULL;
	}
	prefix->targets = (guint8) images->len;

	/* copy images */
	for (guint i = 0; i < dfuse_images->len; i++) {
		GBytes *contents = g_ptr_array_index (dfuse_images, i);
		gsize length;
		const guint8 *data;
		data = g_bytes_get_data (contents, &length);
		memcpy (buf + offset, data, length);
		offset += (guint32) length;
	}

	/* return blob */
	return g_bytes_new (buf, sizeof (DfuSePrefix) + image_size_total);
}
コード例 #30
0
ファイル: gstwavenc.c プロジェクト: ted-n/gst-plugins-good
static void
write_cues (GstWavEnc * wavenc)
{
  GString *cue_string, *point_string;
  GstBuffer *buf;
  GList *cue_list, *c;
  int num_cues, total = 4;

  if (gst_props_get (wavenc->metadata->properties,
          "cues", &cue_list, NULL) == FALSE) {
    /* No cues, move along please, nothing to see here */
    return;
  }

  /* Space for 'cue ', chunk size and number of cuepoints */
  cue_string = g_string_new ("cue         ");
#define CUEPOINT_SIZE 24
  point_string = g_string_sized_new (CUEPOINT_SIZE);

  for (c = cue_list, num_cues = 0; c; c = c->next, num_cues++) {
    GstCaps *cue_caps = c->data;
    guint32 pos;

    gst_props_get (cue_caps->properties, "position", &pos, NULL);

    point_string->str[0] = GUINT32_TO_LE (num_cues + 1);
    point_string->str[4] = GUINT32_TO_LE (0);
    /* Fixme: There is probably a macro for this */
    point_string->str[8] = 'd';
    point_string->str[9] = 'a';
    point_string->str[10] = 't';
    point_string->str[11] = 'a';
    point_string->str[12] = GUINT32_TO_LE (0);
    point_string->str[16] = GUINT32_TO_LE (0);
    point_string->str[20] = GUINT32_TO_LE (pos);

    total += CUEPOINT_SIZE;
  }

  /* Set the length and chunk size */
  cue_string->str[4] = GUINT32_TO_LE (total);
  cue_string->str[8] = GUINT32_TO_LE (num_cues);
  /* Stick the cue points on the end */
  g_string_append (cue_string, point_string->str);
  g_string_free (point_string, TRUE);

  buf = gst_buffer_new ();
  gst_buffer_set_data (buf, cue_string->str, cue_string->len);

  gst_pad_push (wavenc->srcpad, GST_DATA (buf));
  g_string_free (cue_string, FALSE);
}