예제 #1
0
guint64
prop_copy_uint64 (guint64 prop, guint8 ** buffer, guint64 * size,
    guint64 * offset)
{
  prop = GUINT64_TO_BE (prop);
  return copy_func (&prop, sizeof (guint64), buffer, size, offset);
}
예제 #2
0
파일: object.c 프로젝트: nshi/falcon
void falcon_object_save(trie_node_t *node, void *userdata)
{
	const falcon_object_t *object = (const falcon_object_t *)trie_data(node);
	int fd = GPOINTER_TO_INT(userdata);
	guint16 len = strlen(object->name);
	guint16 len_be = GUINT16_TO_BE(len);
	guint64 size = GUINT64_TO_BE(object->size);
	guint64 time = GUINT64_TO_BE(object->time);
	guint32 mode = GUINT32_TO_BE(object->mode);

	if (write(fd, &len_be, 2) == -1 || write(fd, object->name, len) == -1
	    || write(fd, &size, 8) == -1 || write(fd, &time, 8) == -1
	    || write(fd, &mode, 4) == -1 || write(fd, &(object->watch), 1) == -1)
		g_critical(_("Failed to save object \"%s\": %s"), object->name,
		           g_strerror(errno));
}
예제 #3
0
void SHA256_Final(unsigned char out[SHA256_DIGEST_LENGTH], GChecksum *ctx)
{
  // Add padding as described in RFC 3174 (it describes SHA-1 but
  // the same padding style is used for SHA-256 too).
  size_t pos = ctx->sha256.size & 0x3F;
  ctx->buffer.u8[pos++] = 0x80;

  while (pos != 64 - 8) {
    if (pos == 64) {
      process(ctx);
      pos = 0;
    }

    ctx->buffer.u8[pos++] = 0x00;
  }

  // Convert the message size from bytes to bits.
  ctx->sha256.size *= 8;

  ctx->buffer.u64[(64 - 8) / 8] = GUINT64_TO_BE(ctx->sha256.size);

  process(ctx);

  for (size_t i = 0; i < 8; ++i)
    ctx->buffer.u32[i] = GUINT_TO_BE(ctx->sha256.state[i]);

  memcpy(out, ctx->buffer.u8, SHA256_DIGEST_LENGTH);
}
예제 #4
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;
}
예제 #5
0
GVariant *
ostree_zlib_file_header_new (GFileInfo         *file_info,
                             GVariant          *xattrs)
{
  guint64 size;
  guint32 uid;
  guint32 gid;
  guint32 mode;
  guint32 rdev;
  const char *symlink_target;
  GVariant *ret;
  ot_lvariant GVariant *tmp_xattrs = NULL;

  size = g_file_info_get_size (file_info);
  uid = g_file_info_get_attribute_uint32 (file_info, "unix::uid");
  gid = g_file_info_get_attribute_uint32 (file_info, "unix::gid");
  mode = g_file_info_get_attribute_uint32 (file_info, "unix::mode");
  rdev = g_file_info_get_attribute_uint32 (file_info, "unix::rdev");

  if (g_file_info_get_file_type (file_info) == G_FILE_TYPE_SYMBOLIC_LINK)
    symlink_target = g_file_info_get_symlink_target (file_info);
  else
    symlink_target = "";

  if (xattrs == NULL)
    tmp_xattrs = g_variant_ref_sink (g_variant_new_array (G_VARIANT_TYPE ("(ayay)"), NULL, 0));

  ret = g_variant_new ("(tuuuus@a(ayay))",
                       GUINT64_TO_BE (size), GUINT32_TO_BE (uid),
                       GUINT32_TO_BE (gid), GUINT32_TO_BE (mode), GUINT32_TO_BE (rdev),
                       symlink_target, xattrs ? xattrs : tmp_xattrs);
  g_variant_ref_sink (ret);
  return ret;
}
예제 #6
0
파일: cache.c 프로젝트: nshi/falcon
gboolean falcon_cache_save(const falcon_cache_t *cache, const gchar *name)
{
	int fd = 0;
	guint64 count = 0;

	g_return_val_if_fail(cache, FALSE);
	if (!name)
		return FALSE;

	fd = g_open(name, O_WRONLY | O_TRUNC | O_CREAT,
	            S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
	if (fd == -1) {
		g_critical(_("Failed to open cache file %s: %s"), name,
		           g_strerror(errno));
		return FALSE;
	}

	g_mutex_lock(cache->lock);
	count = GUINT64_TO_BE(cache->count);
	if (write(fd, &count, 8) == -1) {
		g_critical(_("Failed to write to file %s: %s"), name, g_strerror(errno));
		g_mutex_unlock(cache->lock);
		close(fd);
		return FALSE;
	}
	trie_foreach(cache->objects, falcon_object_save, GINT_TO_POINTER(fd));
	g_mutex_unlock(cache->lock);
	close(fd);

	return TRUE;
}
예제 #7
0
void
lx_print_uint64(RxBuffer *buf, guint64 value, GError **error)
{
    g_assert(buf != NULL); g_assert(buf->array != NULL);
    g_assert(error != NULL);

    guint64 network_value = GUINT64_TO_BE(value);
    g_byte_array_append(buf->array, (guint8*)&network_value, sizeof(network_value));
}
예제 #8
0
static void
gstring_append_double (GString *gstring,
                       double   vdouble)
{
  union { double vdouble; guint64 vuint64; } u;
  u.vdouble = vdouble;
  u.vuint64 = GUINT64_TO_BE (u.vuint64);
  g_string_append_len (gstring, (const gchar*) &u.vuint64, 8);
}
예제 #9
0
/**
 * mega_aes_key_setup_ctr:
 * @aes_key: a #MegaAesKey
 * @nonce: (element-type guint8) (array fixed-size=8) (transfer none): 8-byte nonce buffer
 * @position: Counter value (block index)
 *
 * Setup CTR mode encryption/decryption.
 */
void mega_aes_key_setup_ctr(MegaAesKey* aes_key, guchar* nonce, guint64 position)
{
    g_return_if_fail(MEGA_IS_AES_KEY(aes_key));
    g_return_if_fail(nonce != NULL);

    memcpy(aes_key->priv->ctr_nonce, nonce, 8);
    aes_key->priv->ctr_position = GUINT64_TO_BE(position);

    memset(aes_key->priv->ctr_ecount, 0, 16);
    aes_key->priv->ctr_num = 0;
}
예제 #10
0
파일: k12.c 프로젝트: ARK1988/wireshark
static gboolean k12_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
                         const guint8 *pd, int *err) {
    const union wtap_pseudo_header *pseudo_header = &phdr->pseudo_header;
    k12_dump_t *k12 = (k12_dump_t *)wdh->priv;
    guint32 len;
    union {
        guint8 buffer[8192];
        struct {
            guint32 len;
            guint32 type;
            guint32 frame_len;
            guint32 input;

            guint32 datum_1;
            guint32 datum_2;
            guint64 ts;

            guint8 frame[0x1fc0];
        } record;
    } obj;

    /* We can only write packet records. */
    if (phdr->rec_type != REC_TYPE_PACKET) {
        *err = WTAP_ERR_REC_TYPE_UNSUPPORTED;
        return FALSE;
    }

    if (k12->num_of_records == 0) {
        k12_t* file_data = (k12_t*)pseudo_header->k12.stuff;
        /* XXX: We'll assume that any fwrite errors in k12_dump_src_setting will    */
        /*      repeat during the final k12_dump_record at the end of k12_dump      */
        /*      (and thus cause an error return from k12_dump).                     */
        /*      (I don't see a reasonably clean way to handle any fwrite errors     */
        /*       encountered in k12_dump_src_setting).                              */
        g_hash_table_foreach(file_data->src_by_id,k12_dump_src_setting,wdh);
    }
    obj.record.len = 0x20 + phdr->caplen;
    obj.record.len += (obj.record.len % 4) ? 4 - obj.record.len % 4 : 0;

    len = obj.record.len;

    obj.record.len = g_htonl(obj.record.len);

    obj.record.type = g_htonl(K12_REC_PACKET);
    obj.record.frame_len = g_htonl(phdr->caplen);
    obj.record.input = g_htonl(pseudo_header->k12.input);

    obj.record.ts = GUINT64_TO_BE((((guint64)phdr->ts.secs - 631152000) * 2000000) + (phdr->ts.nsecs / 1000 * 2));

    memcpy(obj.record.frame,pd,phdr->caplen);

    return k12_dump_record(wdh,len,obj.buffer, err);
}
예제 #11
0
파일: pbap.c 프로젝트: Sork007/obexd
static DBusMessage *pull_phonebook(struct pbap_data *pbap,
					DBusMessage *message, guint8 type,
					const char *name, uint64_t filter,
					guint8 format, guint16 maxlistcount,
					guint16 liststartoffset)
{
	struct pullphonebook_apparam apparam;
	session_callback_t func;

	if (pbap->msg)
		return g_dbus_create_error(message,
				"org.openobex.Error.InProgress",
				"Transfer in progress");

	apparam.filter_tag = FILTER_TAG;
	apparam.filter_len = FILTER_LEN;
	apparam.filter = GUINT64_TO_BE(filter);
	apparam.format_tag = FORMAT_TAG;
	apparam.format_len = FORMAT_LEN;
	apparam.format = format;
	apparam.maxlistcount_tag = MAXLISTCOUNT_TAG;
	apparam.maxlistcount_len = MAXLISTCOUNT_LEN;
	apparam.maxlistcount = GUINT16_TO_BE(maxlistcount);
	apparam.liststartoffset_tag = LISTSTARTOFFSET_TAG;
	apparam.liststartoffset_len = LISTSTARTOFFSET_LEN;
	apparam.liststartoffset = GUINT16_TO_BE(liststartoffset);

	switch (type) {
	case PULLPHONEBOOK:
		func = pull_phonebook_callback;
		break;
	case GETPHONEBOOKSIZE:
		func = phonebook_size_callback;
		break;
	default:
		error("Unexpected type : 0x%2x", type);
		return NULL;
	}

	if (obc_session_get(pbap->session, "x-bt/phonebook", name, NULL,
				(guint8 *) &apparam, sizeof(apparam),
				func, pbap) < 0)
		return g_dbus_create_error(message,
				"org.openobex.Error.Failed",
				"Failed");

	pbap->msg = dbus_message_ref(message);

	return NULL;
}
예제 #12
0
파일: bundle.c 프로젝트: gavinschenk/rauc
static gboolean output_stream_write_uint64_all(GOutputStream *stream,
                                              guint64 data,
                                              GCancellable *cancellable,
                                              GError **error)
{
	gsize bytes_written;
	gboolean res;

	data = GUINT64_TO_BE(data);
	res = g_output_stream_write_all(stream, &data, sizeof(data), &bytes_written,
					 cancellable, error);
	g_assert(bytes_written == sizeof(data));
	return res;
}
예제 #13
0
gint32
thrift_binary_protocol_write_i64 (ThriftProtocol *protocol, const gint64 value,
                                  GError **error)
{
  g_return_val_if_fail (THRIFT_IS_BINARY_PROTOCOL (protocol), -1);

  gint64 net = GUINT64_TO_BE (value);
  if (thrift_transport_write (protocol->transport,
                              (const gpointer) &net, 8, error))
  {
    return 8;
  } else {
    return -1;
  }
}
예제 #14
0
파일: pbap.c 프로젝트: Sork007/obexd
static DBusMessage *pbap_pull_vcard(DBusConnection *connection,
					DBusMessage *message, void *user_data)
{
	struct pbap_data *pbap = user_data;
	struct pullvcardentry_apparam apparam;
	const char *name;

	if (!pbap->path)
		return g_dbus_create_error(message,
				ERROR_INF ".Forbidden",
				"Call Select first of all");

	if (dbus_message_get_args(message, NULL,
			DBUS_TYPE_STRING, &name,
			DBUS_TYPE_INVALID) == FALSE)
		return g_dbus_create_error(message,
				ERROR_INF ".InvalidArguments", NULL);

	if (pbap->msg)
		return g_dbus_create_error(message,
				"org.openobex.Error.InProgress",
				"Transfer in progress");

	apparam.filter_tag = FILTER_TAG;
	apparam.filter_len = FILTER_LEN;
	apparam.filter = GUINT64_TO_BE(pbap->filter);
	apparam.format_tag = FORMAT_TAG;
	apparam.format_len = FORMAT_LEN;
	apparam.format = pbap->format;

	if (obc_session_get(pbap->session, "x-bt/vcard", name, NULL,
			(guint8 *)&apparam, sizeof(apparam),
			pull_phonebook_callback, pbap) < 0)
		return g_dbus_create_error(message,
				"org.openobex.Error.Failed",
				"Failed");

	pbap->msg = dbus_message_ref(message);

	return NULL;
}
예제 #15
0
파일: directconn.c 프로젝트: VoxOx/VoxOx
void
msn_directconn_send_handshake(MsnDirectConn *directconn)
{
	MsnSlpLink *slplink;
	MsnSlpMessage *slpmsg;

	g_return_if_fail(directconn != NULL);

	slplink = directconn->slplink;

	slpmsg = msn_slpmsg_new(slplink);
	slpmsg->flags = 0x100;

	if (directconn->nonce != NULL)
	{
		guint32 t1;
		guint16 t2;
		guint16 t3;
		guint16 t4;
		guint64 t5;

		sscanf (directconn->nonce, "%08X-%04hX-%04hX-%04hX-%012" G_GINT64_MODIFIER "X", &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);

		slpmsg->ack_id     = t1;
		slpmsg->ack_sub_id = t2 | (t3 << 16);
		slpmsg->ack_size   = t4 | t5;
	}

	g_free(directconn->nonce);

	msn_slplink_send_slpmsg(slplink, slpmsg);

	directconn->acked =TRUE;
}
예제 #16
0
파일: qmi-utils.c 프로젝트: ebichu/dd-wrt
/**
 * qmi_utils_write_guint64_to_buffer:
 * @buffer: a buffer.
 * @buffer_size: size of @buffer.
 * @endian: endianness of firmware value; swapped from host byte order if necessary
 * @in: location of the variable to be written.
 *
 * Writes an unsigned 64-bit integer into the buffer. The number to be written
 * is expected to be given in host endianness, and this method takes care of
 * converting the value written to the byte order specified by @endian.
 *
 * The user needs to make sure that the buffer is at least 8 bytes long.
 *
 * Also note that both @buffer and @buffer_size get updated after the 8 bytes
 * write.
 */
void
qmi_utils_write_guint64_to_buffer (guint8  **buffer,
                                   guint16  *buffer_size,
                                   QmiEndian endian,
                                   guint64  *in)
{
    guint64 tmp;

    g_assert (in != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= 8);

    if (endian == QMI_ENDIAN_BIG)
        tmp = GUINT64_TO_BE (*in);
    else
        tmp = GUINT64_TO_LE (*in);
    memcpy (&(*buffer)[0], &tmp, sizeof (tmp));

    *buffer = &((*buffer)[8]);
    *buffer_size = (*buffer_size) - 8;
}
예제 #17
0
파일: qmi-utils.c 프로젝트: ebichu/dd-wrt
/**
 * qmi_utils_write_sized_guint_to_buffer:
 * @buffer: a buffer.
 * @buffer_size: size of @buffer.
 * @n_bytes: number of bytes to write.
 * @endian: endianness of firmware value; swapped from host byte order if necessary
 * @in: location of the variable to be written.
 *
 * Writes a @n_bytes-sized unsigned integer into the buffer. The number to be
 * written is expected to be given in host endianness, and this method takes
 * care of converting the value written to the byte order specified by @endian.
 *
 * The user needs to make sure that the buffer is at least @n_bytes bytes long.
 *
 * Also note that both @buffer and @buffer_size get updated after the @n_bytes
 * bytes write.
 */
void
qmi_utils_write_sized_guint_to_buffer (guint8  **buffer,
                                       guint16  *buffer_size,
                                       guint     n_bytes,
                                       QmiEndian endian,
                                       guint64  *in)
{
    guint64 tmp;

    g_assert (in != NULL);
    g_assert (buffer != NULL);
    g_assert (buffer_size != NULL);
    g_assert (*buffer_size >= n_bytes);

    if (endian == QMI_ENDIAN_BIG)
        tmp = GUINT64_TO_BE (*in);
    else
        tmp = GUINT64_TO_LE (*in);
    memcpy (*buffer, &tmp, n_bytes);

    *buffer = &((*buffer)[n_bytes]);
    *buffer_size = (*buffer_size) - n_bytes;
}
예제 #18
0
void
msn_write64be(char *buf, guint64 data)
{
    data = GUINT64_TO_BE(data);
    memcpy(buf, &data, sizeof(data));
}
예제 #19
0
/**
 * Writes an unsigned 64-bit native endian value into the stream as a
 * Big Endian value.
 *
 * @param value Value to write into the stream.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fput_be64(uint64_t value, VFSFile *stream)
{
    uint64_t tmp = GUINT64_TO_BE(value);
    return vfs_fwrite(&tmp, sizeof(tmp), 1, stream) == 1;
}
예제 #20
0
파일: msnutils.c 프로젝트: Draghtnod/pidgin
void
msn_write64be(char *buf, guint64 data)
{
	*(guint64 *)buf = GUINT64_TO_BE(data);
}