wireshark/wsutil/wmem/wmem_array.h

112 lines
2.1 KiB
C
Raw Normal View History

/** @file
* Definitions for the Wireshark Memory Manager Array
* Copyright 2013, Evan Huus <eapache@gmail.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#ifndef __WMEM_ARRAY_H__
#define __WMEM_ARRAY_H__
#include <string.h>
#include <glib.h>
#include "wmem_core.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
/** @addtogroup wmem
* @{
* @defgroup wmem-array Array
*
* A resizable array implementation on top of wmem.
*
* @{
*/
struct _wmem_array_t;
typedef struct _wmem_array_t wmem_array_t;
WS_DLL_PUBLIC
wmem_array_t *
wmem_array_sized_new(wmem_allocator_t *allocator, gsize elem_size,
guint alloc_count)
G_GNUC_MALLOC;
WS_DLL_PUBLIC
wmem_array_t *
wmem_array_new(wmem_allocator_t *allocator, const gsize elem_size)
G_GNUC_MALLOC;
WS_DLL_PUBLIC
void
wmem_array_grow(wmem_array_t *array, const guint to_add);
WS_DLL_PUBLIC
void
wmem_array_set_null_terminator(wmem_array_t *array);
WS_DLL_PUBLIC
void
wmem_array_bzero(wmem_array_t *array);
WS_DLL_PUBLIC
void
wmem_array_append(wmem_array_t *array, const void *in, guint count);
#define wmem_array_append_one(ARRAY, VAL) \
wmem_array_append((ARRAY), &(VAL), 1)
WS_DLL_PUBLIC
void *
wmem_array_index(wmem_array_t *array, guint array_index);
smb2: add support for decompression The latest iteration of Microsoft updates to SMB3 added compression to the protocol. This commit implements decompressing and dissecting compressed payloads. The compression algorithms that can be used are "Plain LZ77", "LZ77+Huffman" and "LZNT1" which you can read more about in the [MS-XCA] documentation. This set of algorithm is sometimes referred to as XPRESS. This commit reuses the existing uncompression API scheme already in place with zlib and brotli and adds 3 tvb_uncompress_*() function implemented in: * epan/tvbuff_lz77.c * epan/tvbuff_lz77huff.c * epan/tvbuff_lznt1.c A new function wmem_array_try_index() was added to the wmem_array API to make bound checked reads that fail gracefully. New tests for it have been added as well. Since both reads (tvb) and writes (wmem_array) are bound checked the risk for buffer overruns is drastically reduced. LZ77+Huffman has decoding tables and special care was taken to bound check these. Simplified versions of the implementations were succesfully tested against AFL (American Fuzzy Lop) for ~150 millions executions each. The SMB2/3 dissector was changed to deal with the new transform header for compressed packets (new protocol_id value) and READ request flags (COMPRESSED). Badly compressed or encrypted packets are now reported as such, and the decryption test suite was changed to reflect that. This commit also adds a test capture with 1 packet compressed with each algorithm as returned by Windows Server 2019, along with 3 matching tests in test/suite_dissection.py Change-Id: I2b84f56541f2f4ee7d886152794b993987dd10e7 Reviewed-on: https://code.wireshark.org/review/33855 Petri-Dish: Anders Broman <a.broman58@gmail.com> Tested-by: Petri Dish Buildbot Reviewed-by: Peter Wu <peter@lekensteyn.nl>
2019-07-05 14:08:18 +00:00
WS_DLL_PUBLIC
int
wmem_array_try_index(wmem_array_t *array, guint array_index, void *val);
WS_DLL_PUBLIC
void
wmem_array_sort(wmem_array_t *array, int (*compar)(const void*,const void*));
WS_DLL_PUBLIC
void *
wmem_array_get_raw(wmem_array_t *array);
WS_DLL_PUBLIC
guint
wmem_array_get_count(wmem_array_t *array);
WS_DLL_PUBLIC
void
wmem_destroy_array(wmem_array_t *array);
/** @}
* @} */
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __WMEM_ARRAY_H__ */
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/