示例#1
0
static int TvbRange_ustring_any(lua_State* L, gboolean little_endian) {
	/* Obtain a UTF-16 encoded string from a TvbRange */
    TvbRange tvbr = checkTvbRange(L,1);
    gchar * str;

    if ( !(tvbr && tvbr->tvb)) return 0;
    if (tvbr->tvb->expired) {
        luaL_error(L,"expired tvb");
        return 0;
    }

    str = (gchar*)tvb_get_unicode_string(wmem_packet_scope(),tvbr->tvb->ws_tvb,tvbr->offset,tvbr->len,(little_endian ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN));
    lua_pushlstring(L, str, strlen(str));

    return 1; /* The string */
}
示例#2
0
static gint dissect_counted_values(tvbuff_t *tvb, gint offset, int hf_id,  packet_info *pinfo, proto_tree *tree, gboolean single, gboolean unicode, guint encoding)
{
	 proto_item *item;
	 guint32 length, count, i;

	 count = tvb_get_letohl(tvb, offset);
	 proto_tree_add_item(tree, hf_tnef_values_count, tvb, offset, 4, ENC_LITTLE_ENDIAN);

	 if(count > 1) {
		 if(single) {
			 item = proto_tree_add_expert_format(tree, pinfo, &ei_tnef_expect_single_item, tvb, offset, 4,
						    "Expecting a single item but found %d", count);
			 tree = proto_item_add_subtree(item, ett_tnef_counted_items);
		 }
	 }

	 offset += 4;

	 for(i = 0; i < count; i++) {

		 length = tvb_get_letohl(tvb, offset);
		 proto_tree_add_item(tree, hf_tnef_value_length, tvb, offset, 4, ENC_LITTLE_ENDIAN);
		 offset += 4;

		 if (unicode) {
			 char *unicode_str = tvb_get_unicode_string(wmem_packet_scope(), tvb, offset, length, ENC_LITTLE_ENDIAN);
			 proto_tree_add_string(tree, hf_id, tvb, offset, length, unicode_str);
		 } else {
			 proto_tree_add_item(tree, hf_id, tvb, offset, length, encoding);
		 }
		 offset += length;

		 /* XXX: may be padding ? */

	 }

	 return offset;
}
示例#3
0
static int
dissect_dtpt_wstring(tvbuff_t *tvb, guint offset, proto_tree *tree, int hfindex)
{
	guint32	wstring_length;
	guint32	wstring_size;
	char	*wstring_data = NULL;
	guint32	wstring_padding = 0;

	wstring_length = tvb_get_letohl(tvb, offset);
	wstring_data = tvb_get_unicode_string(wmem_packet_scope(), tvb, offset+4, wstring_length, ENC_LITTLE_ENDIAN);
	wstring_size = wstring_length;
	if (wstring_size%4) {
		wstring_padding = (4-wstring_size%4);
		wstring_size += wstring_padding;
	}
	if (tree) {
		proto_item	*dtpt_wstring_item = NULL;
		proto_tree	*dtpt_wstring_tree = NULL;
		dtpt_wstring_item = proto_tree_add_string(tree, hfindex,
			tvb, offset+0, 4+wstring_size, wstring_data);
		if (dtpt_wstring_item)
			dtpt_wstring_tree = proto_item_add_subtree(dtpt_wstring_item, ett_dtpt_wstring);
		if (dtpt_wstring_tree) {
			proto_tree_add_uint(dtpt_wstring_tree, hf_dtpt_wstring_length,
				tvb, offset+0, 4, wstring_length);
			if (wstring_length)
				proto_tree_add_string(dtpt_wstring_tree, hf_dtpt_wstring_data,
					tvb, offset+4, wstring_length, wstring_data);
			if (wstring_padding)
				proto_tree_add_text(dtpt_wstring_tree, tvb,
					offset+4+wstring_length,wstring_padding, "Padding");
		}
	}
	offset += 4+wstring_size;
	return offset;
}