From e59b3c23381f8f79a3d950e8509b6f84b2956ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Filipe=20La=C3=ADns?= Date: Fri, 24 Jul 2020 17:12:19 +0100 Subject: [PATCH] tvb: add tvb_get_bits_array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I2fad824ca417dcd089fabfdf06f28529c7ee9e87 Signed-off-by: Filipe LaĆ­ns Reviewed-on: https://code.wireshark.org/review/37949 Petri-Dish: Anders Broman Tested-by: Petri Dish Buildbot Reviewed-by: Anders Broman --- debian/libwireshark0.symbols | 2 ++ epan/tvbuff.c | 13 +++++++++++++ epan/tvbuff.h | 4 ++++ 3 files changed, 19 insertions(+) diff --git a/debian/libwireshark0.symbols b/debian/libwireshark0.symbols index ce95f33de9..2fb16404c6 100644 --- a/debian/libwireshark0.symbols +++ b/debian/libwireshark0.symbols @@ -245,6 +245,7 @@ libwireshark.so.0 libwireshark0 #MINVER# decode_as_default_reset@Base 1.12.0~rc1 decode_as_list@Base 1.12.0~rc1 decode_bits_in_field@Base 1.9.1 + decode_bits_in_field_long@Base 3.3.0 decode_build_reset_list@Base 2.3.0 decode_cleanup@Base 3.3.0 decode_clear_all@Base 2.3.0 @@ -1732,6 +1733,7 @@ libwireshark.so.0 libwireshark0 #MINVER# tvb_get_bits64@Base 1.9.1 tvb_get_bits8@Base 1.9.1 tvb_get_bits@Base 1.9.1 + tvb_get_bits_array@Base 3.3.0 tvb_get_const_stringz@Base 1.9.1 tvb_get_ds_tvb@Base 1.9.1 tvb_get_ether_name@Base 1.99.3 diff --git a/epan/tvbuff.c b/epan/tvbuff.c index 9352a6f73e..41e3cd0cbf 100644 --- a/epan/tvbuff.c +++ b/epan/tvbuff.c @@ -1955,6 +1955,19 @@ static const guint8 bit_mask8[] = { 0xff }; + +/* Get a variable ammount of bits + * + * Return a byte array with bit limited data. The data is aligned to the right. + */ +guint8 * +tvb_get_bits_array(wmem_allocator_t *scope, tvbuff_t *tvb, const gint bit_offset, size_t no_of_bits, size_t *data_length) +{ + tvbuff_t *sub_tvb = tvb_new_octet_aligned(tvb, bit_offset, (gint32) no_of_bits); + *data_length = tvb_reported_length(sub_tvb); + return (guint8*)tvb_memdup(scope, sub_tvb, 0, *data_length); +} + /* Get 1 - 8 bits */ guint8 tvb_get_bits8(tvbuff_t *tvb, guint bit_offset, const gint no_of_bits) diff --git a/epan/tvbuff.h b/epan/tvbuff.h index 22ffa05114..388625370f 100644 --- a/epan/tvbuff.h +++ b/epan/tvbuff.h @@ -408,6 +408,10 @@ WS_DLL_PUBLIC void tvb_get_letohguid(tvbuff_t *tvb, const gint offset, WS_DLL_PUBLIC void tvb_get_guid(tvbuff_t *tvb, const gint offset, e_guid_t *guid, const guint encoding); +/* Fetches a byte array given a bit offset in a tvb */ +WS_DLL_PUBLIC guint8* tvb_get_bits_array(wmem_allocator_t *scope, tvbuff_t *tvb, + const gint offset, size_t length, size_t *data_length); + /* Fetch a specified number of bits from bit offset in a tvb. All of these * functions are equivalent, except for the type of the return value. Note * that the parameter encoding (where supplied) is meaningless and ignored */