Example #1
0
static gboolean
commview_read_header(commview_header_t *cv_hdr, FILE_T fh, int *err,
    gchar **err_info)
{
	wtap_file_read_expected_bytes(&cv_hdr->data_len, 2, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->source_data_len, 2, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->version, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->year, 2, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->month, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->day, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->hours, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->minutes, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->seconds, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->usecs, 4, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->flags, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->signal_level_percent, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->rate, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->band, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->channel, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->direction, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->signal_level_dbm, 1, fh, err, err_info);
	wtap_file_read_expected_bytes(&cv_hdr->noise_level, 1, fh, err, err_info);

	/* Convert multi-byte values from little endian to host endian format */
	cv_hdr->data_len = GUINT16_FROM_LE(cv_hdr->data_len);
	cv_hdr->source_data_len = GUINT16_FROM_LE(cv_hdr->source_data_len);
	cv_hdr->year = GUINT16_FROM_LE(cv_hdr->year);
	cv_hdr->usecs = GUINT32_FROM_LE(cv_hdr->usecs);

	return TRUE;
}
Example #2
0
/**
 * fwupd_guid_to_string:
 * @guid: a #fwupd_guid_t to read
 * @flags: some %FwupdGuidFlags, e.g. %FWUPD_GUID_FLAG_MIXED_ENDIAN
 *
 * Returns a text GUID of mixed or BE endian for a packed buffer.
 *
 * Returns: A new GUID
 *
 * Since: 1.2.5
 **/
gchar *
fwupd_guid_to_string (const fwupd_guid_t *guid, FwupdGuidFlags flags)
{
	fwupd_guid_native_t gnat;

	g_return_val_if_fail (guid != NULL, NULL);

	/* copy to avoid issues with aligning */
	memcpy (&gnat, guid, sizeof(gnat));

	/* mixed is bizaar, but specified as the DCE encoding */
	if (flags & FWUPD_GUID_FLAG_MIXED_ENDIAN) {
		return g_strdup_printf ("%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
					GUINT32_FROM_LE(gnat.a),
					GUINT16_FROM_LE(gnat.b),
					GUINT16_FROM_LE(gnat.c),
					GUINT16_FROM_BE(gnat.d),
					gnat.e[0], gnat.e[1],
					gnat.e[2], gnat.e[3],
					gnat.e[4], gnat.e[5]);
	}
	return g_strdup_printf ("%08x-%04x-%04x-%04x-%02x%02x%02x%02x%02x%02x",
				GUINT32_FROM_BE(gnat.a),
				GUINT16_FROM_BE(gnat.b),
				GUINT16_FROM_BE(gnat.c),
				GUINT16_FROM_BE(gnat.d),
				gnat.e[0], gnat.e[1],
				gnat.e[2], gnat.e[3],
				gnat.e[4], gnat.e[5]);
}
Example #3
0
static gint
ico_write_int16 (FILE     *fp,
                 guint16  *data,
                 gint      count)
{
  gint total;

  total = count;
  if (count > 0)
    {
#if (G_BYTE_ORDER == G_BIG_ENDIAN)
      gint i;

      for (i = 0; i < count; i++)
        data[i] = GUINT16_FROM_LE (data[i]);
#endif

      ico_write_int8 (fp, (guint8 *) data, count * 2);

#if (G_BYTE_ORDER == G_BIG_ENDIAN)
      /* Put it back like we found it */
      for (i = 0; i < count; i++)
        data[i] = GUINT16_FROM_LE (data[i]);
#endif
    }

  return total * 2;
}
Example #4
0
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;
}
Example #5
0
static gboolean
parse_acl (E2kSecurityDescriptor *sd, GByteArray *binsd, guint16 *off)
{
	E2k_ACL aclbuf;
	E2k_ACE acebuf;
	int ace_count, i;

	if (binsd->len - *off < sizeof (E2k_ACL))
		return FALSE;

	memcpy (&aclbuf, binsd->data + *off, sizeof (aclbuf));
	if (*off + GUINT16_FROM_LE (aclbuf.AclSize) > binsd->len)
		return FALSE;
	if (aclbuf.AclRevision != E2K_ACL_REVISION)
		return FALSE;

	ace_count = GUINT16_FROM_LE (aclbuf.AceCount);

	*off += sizeof (aclbuf);
	for (i = 0; i < ace_count; i++) {
		if (binsd->len - *off < sizeof (E2k_ACE))
			return FALSE;

		memcpy (&acebuf, binsd->data + *off,
			sizeof (acebuf.Header) + sizeof (acebuf.Mask));
		*off += sizeof (acebuf.Header) + sizeof (acebuf.Mask);

		/* If either of OBJECT_INHERIT_ACE or INHERIT_ONLY_ACE
		 * is set, both must be.
		 */
		if (acebuf.Header.AceFlags & E2K_OBJECT_INHERIT_ACE) {
			if (!(acebuf.Header.AceFlags & E2K_INHERIT_ONLY_ACE))
				return FALSE;
		} else {
			if (acebuf.Header.AceFlags & E2K_INHERIT_ONLY_ACE)
				return FALSE;
		}

		if (!parse_sid (sd, binsd, off, &acebuf.Sid))
			return FALSE;

		if (!g_hash_table_lookup (sd->priv->sid_order, acebuf.Sid)) {
			int size = g_hash_table_size (sd->priv->sid_order);

			g_hash_table_insert (sd->priv->sid_order, acebuf.Sid,
					     GUINT_TO_POINTER (size + 1));
		}

		g_array_append_val (sd->priv->aces, acebuf);
	}

	return TRUE;
}
Example #6
0
int gfire_read_attrib(GList **values, guint8 *buffer, int packet_len, const char *name,
					gboolean dynamic, gboolean binary, int bytes_to_first, int bytes_between, int vallen)
{
	int index = 0; int i=0; int ali = 0; int alen = 0;
	gchar tmp[100];
	guint16 numitems = 0; guint16 attr_len = 0;
	guint8 *str;

	memset(tmp, 0x00, 100);

	alen = strlen(name);
	memcpy(tmp, buffer + index, alen);
	index += strlen(name);
	if ( 0 == g_ascii_strcasecmp(name, tmp)) {
		index += 2;
		memcpy(&numitems, buffer + index, 2);
		numitems = GUINT16_FROM_LE(numitems);
		index += 2;
		purple_debug(PURPLE_DEBUG_MISC, "gfire", "Looking for %d %s's in packet.\n", numitems, NN(name));
	} else {
		purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: %s signature isn't in the correct position.\n", NN(name));
		return -1;
	} 

	/* if we are copying a string make sure we have a space for the trailing \0 */
	if (binary) ali = 0;
		else ali = 1;

	for (i = 0; i < numitems; i++) {
		if (dynamic) {
			memcpy(&attr_len, buffer + index, 2);
			attr_len = GUINT16_FROM_LE(attr_len); index+=2;
		} else attr_len = vallen;

		if (dynamic && (attr_len == 0)) str = NULL;
			else {
				str = g_malloc0(sizeof(char) * (attr_len+ali));
				memcpy(str, buffer + index, attr_len);
				if (!binary) str[attr_len] = 0x00;
			}
		index += attr_len;
		*values = g_list_append(*values,(gpointer *)str);
		if ( index > packet_len ) {
			purple_debug(PURPLE_DEBUG_MISC, "gfire", "ERROR: pkt 131: more friends then packet length.\n");
			return -1;
		}
	}
	return index;
}
Example #7
0
static gboolean hcidump_process_packet(FILE_T fh, struct wtap_pkthdr *phdr,
    Buffer *buf, int *err, gchar **err_info)
{
	struct dump_hdr dh;
	int packet_size;

	if (!wtap_read_bytes_or_eof(fh, &dh, DUMP_HDR_SIZE, err, err_info))
		return FALSE;

	packet_size = GUINT16_FROM_LE(dh.len);
	if (packet_size > WTAP_MAX_PACKET_SIZE) {
		/*
		 * Probably a corrupt capture file; don't blow up trying
		 * to allocate space for an immensely-large packet.
		 */
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("hcidump: File has %u-byte packet, bigger than maximum of %u",
			packet_size, WTAP_MAX_PACKET_SIZE);
		return FALSE;
	}

	phdr->rec_type = REC_TYPE_PACKET;
	phdr->presence_flags = WTAP_HAS_TS;
	phdr->ts.secs = GUINT32_FROM_LE(dh.ts_sec);
	phdr->ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000;
	phdr->caplen = packet_size;
	phdr->len = packet_size;

	phdr->pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);

	return wtap_read_packet_bytes(fh, buf, packet_size, err, err_info);
}
Example #8
0
static gboolean
deserialize_buffer (SBlbDeserializer *deserializer, FlowPacketQueue *packet_queue, FlowPad *output_pad)
{
    SBlbDeserializerPrivate *priv = deserializer->priv;
    union
    {
        guint16 u16;
        guchar c [2];
    }
    u;
    guchar *buf;

    if (priv->buffer_size < 0)
    {
        if (!pop_bytes_and_propagate_objects ((FlowElement *) deserializer, packet_queue, output_pad, u.c, 2))
            return TRUE;

        u.u16 = GUINT16_FROM_LE (u.u16);
        priv->buffer_size = u.u16;
    }

    buf = alloca (priv->buffer_size);

    if (!pop_bytes_and_propagate_objects ((FlowElement *) deserializer, packet_queue, output_pad, buf, priv->buffer_size))
        return TRUE;

    flow_pad_push (output_pad, flow_packet_new (FLOW_PACKET_FORMAT_BUFFER, buf, priv->buffer_size));
    return FALSE;
}
Example #9
0
static gboolean
deserialize_begin (SBlbDeserializer *deserializer, FlowPacketQueue *packet_queue, FlowPad *output_pad)
{
    SBlbDeserializerPrivate *priv = deserializer->priv;
    union
    {
        guint16 id;
        guchar c [2];
    }
    u;

    if (!pop_bytes_and_propagate_objects ((FlowElement *) deserializer, packet_queue, output_pad, u.c, 2))
        return FALSE;

    u.id = GUINT16_FROM_LE (u.id);
    if (u.id == 65535)
    {
        priv->current_type = BUFFER_TYPE;
        priv->buffer_size = -1;
    }
    else
    {
        priv->current_type = sblb_type_id_to_gtype (u.id);
        if (priv->current_type == G_TYPE_INVALID)
        {
            g_warning ("Error deserializing: Invalid message type %d.", u.id);
            return TRUE;
        }

        priv->current_context = flow_serializable_deserialize_begin (priv->current_type);
    }

    return TRUE;
}
Example #10
0
guint16
msn_read16le(const char *buf)
{
    guint16 val;
    memcpy(&val, buf, sizeof(val));
    return GUINT16_FROM_LE(val);
}
Example #11
0
static GwyDataField*
microprof_read_data_field(const MicroProfFile *mfile,
                          const guchar *buffer)
{
    const guint16 *d16 = (const guint16*)buffer;
    GwyDataField *dfield;
    GwySIUnit *siunit;
    gdouble *d;
    guint xres, yres, i, j;

    xres = mfile->xres;
    yres = mfile->yres;
    dfield = gwy_data_field_new(xres, yres,
                                mfile->xrange, mfile->yrange, FALSE);
    d = gwy_data_field_get_data(dfield);

    for (i = 0; i < yres; i++) {
        for (j = 0; j < xres; j++) {
            d[(yres-1 - i)*xres + j] = mfile->zscale*GUINT16_FROM_LE(*d16);
            d16++;
        }
    }

    siunit = gwy_data_field_get_si_unit_xy(dfield);
    gwy_si_unit_set_from_string(siunit, "m");

    siunit = gwy_data_field_get_si_unit_z(dfield);
    gwy_si_unit_set_from_string(siunit, "m");

    return dfield;
}
Example #12
0
/**
 * e2k_security_descriptor_new:
 * @xml_form: the XML form of the folder's security descriptor
 * (The "http://schemas.microsoft.com/exchange/security/descriptor"
 * property, aka %E2K_PR_EXCHANGE_SD_XML)
 * @binary_form: the binary form of the folder's security descriptor
 * (The "http://schemas.microsoft.com/exchange/ntsecuritydescriptor"
 * property, aka %E2K_PR_EXCHANGE_SD_BINARY)
 *
 * Constructs an #E2kSecurityDescriptor from the data in @xml_form and
 * @binary_form.
 *
 * Return value: the security descriptor, or %NULL if the data could
 * not be parsed.
 **/
E2kSecurityDescriptor *
e2k_security_descriptor_new (xmlNodePtr xml_form, GByteArray *binary_form)
{
	E2kSecurityDescriptor *sd;
	E2k_SECURITY_DESCRIPTOR_RELATIVE sdbuf;
	guint16 off, header_len;

	g_return_val_if_fail (xml_form != NULL, NULL);
	g_return_val_if_fail (binary_form != NULL, NULL);

	if (binary_form->len < 2)
		return NULL;

	memcpy (&header_len, binary_form->data, 2);
	header_len = GUINT16_FROM_LE (header_len);
	if (header_len + sizeof (sdbuf) > binary_form->len)
		return NULL;

	memcpy (&sdbuf, binary_form->data + header_len, sizeof (sdbuf));
	if (sdbuf.Revision != E2K_SECURITY_DESCRIPTOR_REVISION)
		return NULL;
	if ((sdbuf.Control & (E2K_SE_DACL_PRESENT | E2K_SE_SACL_PRESENT)) !=
	    E2K_SE_DACL_PRESENT)
		return NULL;

	sd = g_object_new (E2K_TYPE_SECURITY_DESCRIPTOR, NULL);
	sd->priv->header = g_byte_array_new ();
	g_byte_array_append (sd->priv->header, binary_form->data, header_len);
	sd->priv->control_flags = sdbuf.Control;

	/* Create a SID for "Default" then extract remaining SIDs from
	 * the XML form since they have display names associated with
	 * them.
	 */
	sd->priv->default_sid =
		e2k_sid_new_from_string_sid (E2K_SID_TYPE_WELL_KNOWN_GROUP,
					     E2K_SID_WKS_EVERYONE, NULL);
	g_hash_table_insert (sd->priv->sids,
			     (char *)e2k_sid_get_binary_sid (sd->priv->default_sid),
			     sd->priv->default_sid);
	extract_sids (sd, xml_form);

	off = GUINT32_FROM_LE (sdbuf.Owner) + sd->priv->header->len;
	if (!parse_sid (sd, binary_form, &off, &sd->priv->owner))
		goto lose;
	off = GUINT32_FROM_LE (sdbuf.Group) + sd->priv->header->len;
	if (!parse_sid (sd, binary_form, &off, &sd->priv->group))
		goto lose;

	off = GUINT32_FROM_LE (sdbuf.Dacl) + sd->priv->header->len;
	if (!parse_acl (sd, binary_form, &off))
		goto lose;

	return sd;

 lose:
	g_object_unref (sd);
	return NULL;
}
Example #13
0
static int convert_stereo_to_mono_u16le(struct xmms_convert_buffers* buf, void **data, int length)
{
	guint16 *output = *data, *input = *data;
	int i;
	for (i = 0; i < length / 4; i++)
	{
		guint32 tmp;
		guint16 stmp;
		tmp = GUINT16_FROM_LE(*input);
		input++;
		tmp += GUINT16_FROM_LE(*input);
		input++;
		stmp = tmp / 2;
		*output++ = GUINT16_TO_LE(stmp);
	}
	return length / 2;
}
Example #14
0
/**
 * Reads an unsigned 16-bit Little Endian value from the stream
 * into native endian format.
 *
 * @param value Pointer to the variable to read the value into.
 * @param stream A #VFSFile object representing the stream.
 * @return TRUE if read was succesful, FALSE if there was an error.
 */
EXPORT bool_t vfs_fget_le16(uint16_t *value, VFSFile *stream)
{
    uint16_t tmp;
    if (vfs_fread(&tmp, sizeof(tmp), 1, stream) != 1)
        return FALSE;
    *value = GUINT16_FROM_LE(tmp);
    return TRUE;
}
Example #15
0
/**
 * unzip_file:
 * @zip_file:   pointer to start of compressed data
 * @unzip_size: the size of the compressed data block
 *
 * Returns a pointer to uncompressed data (maybe NULL)
 */
void *unzip_file(gchar *zip_file, gulong *unzip_size)
{
	void *unzip_data = NULL;
#ifndef HAVE_LIBZ
	goto end;
#else
	gchar *zip_data;
	struct _lfh {
		guint32 sig;
		guint16 extract_version;
		guint16 flags;
		guint16 comp_method;
		guint16 time;
		guint16 date;
		guint32 crc_32;
		guint32 compressed_size;
		guint32 uncompressed_size;
		guint16 filename_len;
		guint16 extra_field_len;
	}  __attribute__ ((__packed__)) *local_file_header = NULL;


	local_file_header = (struct _lfh *) zip_file;
	if (GUINT32_FROM_LE(local_file_header->sig) != 0x04034b50) {
		g_warning("%s(): wrong format", __PRETTY_FUNCTION__);
		g_free(unzip_data);
		goto end;
	}

	zip_data = zip_file + sizeof(struct _lfh)
		+ GUINT16_FROM_LE(local_file_header->filename_len)
		+ GUINT16_FROM_LE(local_file_header->extra_field_len);
	gulong uncompressed_size = GUINT32_FROM_LE(local_file_header->uncompressed_size);
	unzip_data = g_malloc(uncompressed_size);

	if (!(*unzip_size = uncompress_data(unzip_data, uncompressed_size, zip_data, GUINT32_FROM_LE(local_file_header->compressed_size)))) {
		g_free(unzip_data);
		unzip_data = NULL;
		goto end;
	}

#endif
end:
	return(unzip_data);
}
KoneplusRmpMacroKeyInfo *koneplus_rmp_macro_key_info_v1_to_koneplus_rmp_macro_key_info(KoneplusRmpMacroKeyInfoV1 const *v1) {
	KoneplusRmpMacroKeyInfo *result;
	result = koneplus_rmp_macro_key_info_new();

	result->button_number = v1->button_number;
	result->type = v1->type;
	koneplus_rmp_macro_key_info_set_talk_device(result, GUINT16_FROM_LE(v1->talk_device));
	koneplus_rmp_macro_key_info_set_macroset_name(result, (gchar const *)v1->macroset_name);
	koneplus_rmp_macro_key_info_set_macro_name(result, (gchar const *)v1->macro_name);
	koneplus_rmp_macro_key_info_set_loop(result, GUINT32_FROM_LE(v1->loop));
	koneplus_rmp_macro_key_info_set_count(result, GUINT16_FROM_LE(v1->count));
	memcpy(&result->keystrokes[0], &v1->keystrokes[0], sizeof(result->keystrokes));
	koneplus_rmp_macro_key_info_set_timer_length(result, GUINT32_FROM_LE(v1->timer_length));
	koneplus_rmp_macro_key_info_set_timer_name(result, (gchar const *)v1->timer_name);
	koneplus_rmp_macro_key_info_set_filename(result, (gchar const *)v1->filename);

	return result;
}
Example #17
0
static WORD
GetWORD (int position, BYTE *data)
{
	WORD *value = (WORD*)(data + position);
#if G_BYTE_ORDER != G_LITTLE_ENDIAN
	return GUINT16_FROM_LE (*value);
#else
	return *value;
#endif
}
Example #18
0
static void print_obj(struct db_obj_ent *obj)
{
	uint32_t n_str = GUINT32_FROM_LE(obj->n_str);
	int i;
	void *p;
	uint16_t *slenp;
	char *dbstr;

	if (GUINT32_FROM_LE(obj->flags) & DB_OBJ_INLINE) {
		printf("%s\t%s\t%s\t[%u]\t%u\n",
			obj->bucket,
			obj->owner,
			obj->md5,
			(unsigned) GUINT64_FROM_LE(obj->size),
			n_str);
	} else {
		printf("%s\t%s\t%s\t%llX",
			obj->bucket,
			obj->owner,
			obj->md5,
			(long long) GUINT64_FROM_LE(obj->d.a.oid));
		for (i = 0; i < MAXWAY; i++) {
			if (i == 0) {
				printf("\t");
			} else {
				printf(",");
			}
			printf("%d", GUINT32_FROM_LE(obj->d.a.nidv[i]));
		}
		printf(" %u\n", n_str);
	}

	p = obj;
	p += sizeof(*obj);
	slenp = p;

	p += n_str * sizeof(uint16_t);

	for (i = 0; i < n_str; i++) {
		char pfx[16];

		dbstr = p;
		p += GUINT16_FROM_LE(*slenp);
		slenp++;

		if (i == 0)
			strcpy(pfx, "key: ");
		else
			sprintf(pfx, "str%d: ", i);

		printf("%s%s\n", pfx, dbstr);
	}

	printf("====\n");
}
Example #19
0
void
purple_pn_xfer_got_invite(struct pn_peer_call *call,
                          const char *branch,
                          const char *context)
{
    PurpleAccount *account;
    PurpleXfer *xfer;
    char *bin;
    gsize bin_len;
    guint32 file_size;
    char *file_name;
    gunichar2 *uni_name;

    account = msn_session_get_user_data (pn_peer_link_get_session (call->link));

    call->cb = xfer_completed_cb;
    call->end_cb = xfer_end_cb;
    call->progress_cb = xfer_progress_cb;
    call->branch = g_strdup(branch);

    call->pending = TRUE;

    xfer = purple_xfer_new(account, PURPLE_XFER_RECEIVE,
                           pn_peer_link_get_passport (call->link));
    if (xfer)
    {
        bin = (char *)purple_base64_decode(context, &bin_len);
        file_size = GUINT32_FROM_LE(*(gsize *)(bin + 8));

        uni_name = (gunichar2 *)(bin + 20);
        while(*uni_name != 0 && ((char *)uni_name - (bin + 20)) < MAX_FILE_NAME_LEN) {
            *uni_name = GUINT16_FROM_LE(*uni_name);
            uni_name++;
        }

        file_name = g_utf16_to_utf8((const gunichar2 *)(bin + 20), -1,
                                    NULL, NULL, NULL);

        g_free(bin);

        purple_xfer_set_filename(xfer, file_name);
        purple_xfer_set_size(xfer, file_size);
        purple_xfer_set_init_fnc(xfer, xfer_init);
        purple_xfer_set_request_denied_fnc(xfer, xfer_cancel);
        purple_xfer_set_cancel_recv_fnc(xfer, xfer_cancel);

        call->xfer = xfer;
        purple_xfer_ref(call->xfer);

        xfer->data = call;

        purple_xfer_request(xfer);
    }
}
Example #20
0
static gboolean
fu_smbios_parse_ep32 (FuSmbios *self, const gchar *buf, gsize sz, GError **error)
{
	FuSmbiosStructureEntryPoint32 *ep;
	guint8 csum = 0;

	/* verify size */
	if (sz != sizeof(FuSmbiosStructureEntryPoint32)) {
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INVALID_FILE,
			     "invalid smbios entry point got %" G_GSIZE_FORMAT
			     " bytes, expected %" G_GSIZE_FORMAT,
			     sz, sizeof(FuSmbiosStructureEntryPoint32));
		return FALSE;
	}

	/* verify checksum */
	for (guint i = 0; i < sz; i++)
		csum += buf[i];
	if (csum != 0x00) {
		g_set_error_literal (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INVALID_FILE,
				     "entry point checksum invalid");
		return FALSE;
	}

	/* verify intermediate section */
	ep = (FuSmbiosStructureEntryPoint32 *) buf;
	if (memcmp (ep->intermediate_anchor_str, "_DMI_", 5) != 0) {
		g_autofree gchar *tmp = g_strndup (ep->intermediate_anchor_str, 5);
		g_set_error (error,
			     FWUPD_ERROR,
			     FWUPD_ERROR_INVALID_FILE,
			     "intermediate anchor signature invalid, got %s", tmp);
		return FALSE;
	}
	for (guint i = 10; i < sz; i++)
		csum += buf[i];
	if (csum != 0x00) {
		g_set_error_literal (error,
				     FWUPD_ERROR,
				     FWUPD_ERROR_INVALID_FILE,
				     "intermediate checksum invalid");
		return FALSE;
	}
	self->structure_table_len = GUINT16_FROM_LE (ep->structure_table_len);
	self->smbios_ver = g_strdup_printf ("%u.%u",
					    ep->smbios_major_ver,
					    ep->smbios_minor_ver);
	return TRUE;
}
Example #21
0
static void convert_buffer(gpointer buffer, gint length)
{
	gint i;

	if (afmt == FMT_S8)
	{
		guint8 *ptr1 = buffer;
		gint8 *ptr2 = buffer;

		for (i = 0; i < length; i++)
			*(ptr1++) = *(ptr2++) ^ 128;
	}
	if (afmt == FMT_S16_BE)
	{
		gint16 *ptr = buffer;

		for (i = 0; i < length >> 1; i++, ptr++)
			*ptr = GUINT16_SWAP_LE_BE(*ptr);
	}
	if (afmt == FMT_S16_NE)
	{
		gint16 *ptr = buffer;

		for (i = 0; i < length >> 1; i++, ptr++)
			*ptr = GINT16_TO_LE(*ptr);
	}
	if (afmt == FMT_U16_BE)
	{
		gint16 *ptr1 = buffer;
		guint16 *ptr2 = buffer;

		for (i = 0; i < length >> 1; i++, ptr2++)
			*(ptr1++) = GINT16_TO_LE(GUINT16_FROM_BE(*ptr2) ^ 32768);
	}
	if (afmt == FMT_U16_LE)
	{
		gint16 *ptr1 = buffer;
		guint16 *ptr2 = buffer;

		for (i = 0; i < length >> 1; i++, ptr2++)
			*(ptr1++) = GINT16_TO_LE(GUINT16_FROM_LE(*ptr2) ^ 32768);
	}
	if (afmt == FMT_U16_NE)
	{
		gint16 *ptr1 = buffer;
		guint16 *ptr2 = buffer;

		for (i = 0; i < length >> 1; i++, ptr2++)
			*(ptr1++) = GINT16_TO_LE((*ptr2) ^ 32768);
	}
}
Example #22
0
static int init(struct sr_input *in, const char *filename)
{
	struct sr_probe *probe;
	struct context *ctx;
	char buf[40], probename[8];
	int i;

	if (get_wav_header(filename, buf) != SR_OK)
		return SR_ERR;

	if (!(ctx = g_try_malloc0(sizeof(struct context))))
		return SR_ERR_MALLOC;

	/* Create a virtual device. */
	in->sdi = sr_dev_inst_new(0, SR_ST_ACTIVE, NULL, NULL, NULL);
	in->sdi->priv = ctx;

   	ctx->samplerate = GUINT32_FROM_LE(*(uint32_t *)(buf + 24));
	ctx->samplesize = GUINT16_FROM_LE(*(uint16_t *)(buf + 34)) / 8;
	if (ctx->samplesize != 1 && ctx->samplesize != 2 && ctx->samplesize != 4) {
		sr_err("only 8, 16 or 32 bits per sample supported.");
		return SR_ERR;
	}

	if ((ctx->num_channels = GUINT16_FROM_LE(*(uint16_t *)(buf + 22))) > 20) {
		sr_err("%d channels seems crazy.", ctx->num_channels);
		return SR_ERR;
	}

	for (i = 0; i < ctx->num_channels; i++) {
		snprintf(probename, 8, "CH%d", i + 1);
		if (!(probe = sr_probe_new(0, SR_PROBE_ANALOG, TRUE, probename)))
			return SR_ERR;
		in->sdi->probes = g_slist_append(in->sdi->probes, probe);
	}

	return SR_OK;
}
Example #23
0
static gboolean hcidump_read(wtap *wth, int *err, gchar **err_info,
    gint64 *data_offset)
{
	struct dump_hdr dh;
	guint8 *buf;
	int bytes_read, packet_size;

	*data_offset = file_tell(wth->fh);

	bytes_read = file_read(&dh, DUMP_HDR_SIZE, wth->fh);
	if (bytes_read != DUMP_HDR_SIZE) {
		*err = file_error(wth->fh, err_info);
		if (*err == 0 && bytes_read != 0)
			*err = WTAP_ERR_SHORT_READ;
		return FALSE;
	}

	packet_size = GUINT16_FROM_LE(dh.len);
	if (packet_size > WTAP_MAX_PACKET_SIZE) {
		/*
		 * Probably a corrupt capture file; don't blow up trying
		 * to allocate space for an immensely-large packet.
		 */
		*err = WTAP_ERR_BAD_FILE;
		*err_info = g_strdup_printf("hcidump: File has %u-byte packet, bigger than maximum of %u",
			packet_size, WTAP_MAX_PACKET_SIZE);
		return FALSE;
	}

	buffer_assure_space(wth->frame_buffer, packet_size);
	buf = buffer_start_ptr(wth->frame_buffer);

	bytes_read = file_read(buf, packet_size, wth->fh);
	if (bytes_read != packet_size) {
		*err = file_error(wth->fh, err_info);
		if (*err == 0)
			*err = WTAP_ERR_SHORT_READ;
		return FALSE;
	}

	wth->phdr.presence_flags = WTAP_HAS_TS;
	wth->phdr.ts.secs = GUINT32_FROM_LE(dh.ts_sec);
	wth->phdr.ts.nsecs = GUINT32_FROM_LE(dh.ts_usec) * 1000;
	wth->phdr.caplen = packet_size;
	wth->phdr.len = packet_size;

	wth->phdr.pseudo_header.p2p.sent = (dh.in ? FALSE : TRUE);

	return TRUE;
}
Example #24
0
int fread_word(FILE * f, uint16_t * data)
{
  int ret = 0;

  if (data != NULL)
  {
	  ret = (fread((void *) data, sizeof(uint16_t), 1, f) < 1) ? -1 : 0;
	*data = GUINT16_FROM_LE(*data);
  }
  else
    ret = fskip(f, 2);

  return ret;
}
Example #25
0
/**
 * Initialize the mimic decoder. The frame passed in frame_buffer
 * is used to determine the resolution so that the internal state
 * can be prepared and resources allocated accordingly. Note that
 * the frame passed has to be a keyframe.
 *
 * After initializing use #mimic_get_property to determine required
 * buffer-size, resolution, quality, etc.
 *
 * Note that once a given context has been initialized
 * for either encoding or decoding it is not possible
 * to initialize it again.
 *
 * @param ctx the mimic context to initialize
 * @param frame_buffer buffer containing the first frame to decode
 * @returns #TRUE on success
 */
gboolean mimic_decoder_init(MimCtx *ctx, const guchar *frame_buffer)
{
    gint width, height;
    gboolean is_keyframe;
    
    /* Check if we've been initialized before and that
     * frame_buffer is not NULL. */
    if (ctx->encoder_initialized || ctx->decoder_initialized ||
        frame_buffer == NULL)
    {
        return FALSE;
    }
    
    /* Check resolution. */
    width  = GUINT16_FROM_LE(*((guint16 *) (frame_buffer + 4)));
    height = GUINT16_FROM_LE(*((guint16 *) (frame_buffer + 6)));
    
    if (!(width == 160 && height == 120) && !(width == 320 && height == 240))
        return FALSE;

    /* Check that we're initialized with a keyframe. */
    is_keyframe = (GUINT32_FROM_LE(*((guint32 *) (frame_buffer + 12))) == 0);
    
    if (!is_keyframe)
        return FALSE;

    /* Get quality setting (in case we get queried for it before decoding). */
    ctx->quality = GUINT16_FROM_LE(*((guint16 *) (frame_buffer + 2)));
 
    /* Initialize! */
    mimic_init(ctx, width, height);

    ctx->decoder_initialized = TRUE;

    return TRUE;
}
addr_info_t*
resolver_direct_get_meta1 (resolver_direct_t *r, const container_id_t cID, int ro, GSList *exclude, GError **err)
{
	guint16 i;
        addr_info_t *pA = NULL;

        if (!r || !cID) {
                GSETERROR (err, "invalid parameter");
                return NULL;
        }

        memcpy(&i, cID, 2);
        i = GUINT16_FROM_LE(i);

        /**/
        M0CACHE_LOCK(*r);
        if (!r->mappings)
        {
                TRACE("No META0 cache, trying a reload");
                if (!UNSAFE_resolver_direct_reload(r, 1, err))
                {
                        M0CACHE_UNLOCK(*r);
                        GSETERROR(err, "Cannot load the local META0 cache");
                        return NULL;
                }
        }
	gchar ** meta1_addresses = NULL;
	gchar *addr_str = NULL;
	meta1_addresses = r->mappings->pdata[i];

	if(!meta1_addresses) {
		GSETERROR(err, "entry not found");
		goto end_label;
	}

	guint nb_meta1 = g_strv_length(meta1_addresses);
	guint tmp = rand()%nb_meta1;
	guint try = 0;
	if(g_slist_length(exclude) == nb_meta1) {
		goto end_label;
	}


	while(try < nb_meta1) {
		if(!ro) {
			/* take the first */
			addr_str = meta1_addresses[try];
		} else {
Example #27
0
/**
 * udisks_ata_identify_get_word:
 * @identify_data: (allow-none): A 512-byte array containing ATA IDENTIFY or ATA IDENTIFY PACKET DEVICE data or %NULL.
 * @word_number: The word number to get - must be less than 256.
 *
 * Gets a <quote>word</quote> from position @word_number from
 * @identify_data.
 *
 * Returns: The word at the specified position or 0 if @identify_data is %NULL.
 */
guint16
udisks_ata_identify_get_word (const guchar *identify_data, guint word_number)
{
  const guint16 *words = (const guint16 *) identify_data;
  guint16 ret = 0;

  g_return_val_if_fail (word_number < 256, 0);

  if (identify_data == NULL)
    goto out;

  ret = GUINT16_FROM_LE (words[word_number]);

 out:
  return ret;
}
Example #28
0
static gboolean
fu_smbios_setup_from_data (FuSmbios *self, const guint8 *buf, gsize sz, GError **error)
{
	/* go through each structure */
	for (gsize i = 0; i < sz; i++) {
		FuSmbiosStructure *str = (FuSmbiosStructure *) &buf[i];
		FuSmbiosItem *item;

		/* invalid */
		if (str->len == 0x00)
			break;
		if (str->len >= sz) {
			g_set_error_literal (error,
					     FWUPD_ERROR,
					     FWUPD_ERROR_INVALID_FILE,
					     "structure larger than available data");
			return FALSE;
		}

		/* create a new result */
		item = g_new0 (FuSmbiosItem, 1);
		item->type = str->type;
		item->handle = GUINT16_FROM_LE (str->handle);
		item->data = g_bytes_new (buf + i, str->len);
		item->strings = g_ptr_array_new_with_free_func (g_free);
		g_ptr_array_add (self->items, item);

		/* jump to the end of the struct */
		i += str->len;
		if (buf[i] == '\0' && buf[i+1] == '\0') {
			i++;
			continue;
		}

		/* add strings from table */
		for (gsize start_offset = i; i < sz; i++) {
			if (buf[i] == '\0') {
				if (start_offset == i)
					break;
				g_ptr_array_add (item->strings,
						 g_strdup ((const gchar *) &buf[start_offset]));
				start_offset = i + 1;
			}
		}
	}
	return TRUE;
}
Example #29
0
static int64_t read_uint16(FILE *f, uint16_t endian) {
  uint16_t result;
  if (fread(&result, sizeof result, 1, f) != 1) {
    return -1;
  }

  switch (endian) {
  case TIFF_BIGENDIAN:
    return GUINT16_FROM_BE(result);

  case TIFF_LITTLEENDIAN:
    return GUINT16_FROM_LE(result);

  default:
    g_return_val_if_reached(-1);
  }
}
Example #30
0
static struct fp_print_data *fpi_print_data_from_fp2_data(unsigned char *buf,
	size_t buflen)
{
	size_t total_data_len, item_len;
	struct fp_print_data *data;
	struct fp_print_data_item *item;
	struct fpi_print_data_fp2 *raw = (struct fpi_print_data_fp2 *) buf;
	unsigned char *raw_buf;
	struct fpi_print_data_item_fp2 *raw_item;

	total_data_len = buflen - sizeof(*raw);
	data = print_data_new(GUINT16_FROM_LE(raw->driver_id),
		GUINT32_FROM_LE(raw->devtype), raw->data_type);
	raw_buf = raw->data;
	while (total_data_len) {
		if (total_data_len < sizeof(*raw_item))
			break;
		total_data_len -= sizeof(*raw_item);

		raw_item = (struct fpi_print_data_item_fp2 *)raw_buf;
		item_len = GUINT32_FROM_LE(raw_item->length);
		fp_dbg("item len %d, total_data_len %d", item_len, total_data_len);
		if (total_data_len < item_len) {
			fp_err("corrupted fingerprint data");
			break;
		}
		total_data_len -= item_len;

		item = fpi_print_data_item_new(item_len);
		/* FIXME: fp_print_data->data content is not endianess agnostic */
		memcpy(item->data, raw_item->data, item_len);
		data->prints = g_slist_prepend(data->prints, item);

		raw_buf += sizeof(*raw_item);
		raw_buf += item_len;
	}

	if (g_slist_length(data->prints) == 0) {
		fp_print_data_free(data);
		data = NULL;
	}

	return data;

}