mirror of
https://github.com/vel21ripn/nDPI.git
synced 2026-04-29 15:39:42 +00:00
Replaced ndpiReader's libjson-c support with libnDPI's internal serialization interface. (#1535)
* Fixes #1528 * Serialization Interface should also fuzzed * libjson-c may only be used in the unit test to verify the internal serialization interface * Serialization Interface supports tlv(broken), csv and json * Unit test does work again and requires libjson-c Signed-off-by: lns <matzeton@googlemail.com>
This commit is contained in:
parent
2e0dedbaae
commit
87f93ea4fd
7 changed files with 591 additions and 1123 deletions
|
|
@ -4,6 +4,8 @@
|
|||
#include <stdio.h>
|
||||
|
||||
struct ndpi_detection_module_struct *ndpi_info_mod = NULL;
|
||||
static ndpi_serializer json_serializer = {};
|
||||
static ndpi_serializer csv_serializer = {};
|
||||
|
||||
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
||||
uint8_t protocol_was_guessed;
|
||||
|
|
@ -17,12 +19,27 @@ int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size) {
|
|||
ndpi_set_log_level(ndpi_info_mod, 4);
|
||||
ndpi_set_debug_bitmask(ndpi_info_mod, debug_bitmask);
|
||||
ndpi_finalize_initialization(ndpi_info_mod);
|
||||
ndpi_init_serializer(&json_serializer, ndpi_serialization_format_json);
|
||||
ndpi_init_serializer(&csv_serializer, ndpi_serialization_format_csv);
|
||||
}
|
||||
|
||||
struct ndpi_flow_struct *ndpi_flow = ndpi_flow_malloc(SIZEOF_FLOW_STRUCT);
|
||||
memset(ndpi_flow, 0, SIZEOF_FLOW_STRUCT);
|
||||
ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, Data, Size, 0);
|
||||
ndpi_detection_giveup(ndpi_info_mod, ndpi_flow, 1, &protocol_was_guessed);
|
||||
ndpi_protocol detected_protocol =
|
||||
ndpi_detection_process_packet(ndpi_info_mod, ndpi_flow, Data, Size, 0);
|
||||
ndpi_protocol guessed_protocol =
|
||||
ndpi_detection_giveup(ndpi_info_mod, ndpi_flow, 1, &protocol_was_guessed);
|
||||
|
||||
ndpi_reset_serializer(&json_serializer);
|
||||
ndpi_reset_serializer(&csv_serializer);
|
||||
if (protocol_was_guessed == 0)
|
||||
{
|
||||
ndpi_dpi2json(ndpi_info_mod, ndpi_flow, detected_protocol, &json_serializer);
|
||||
ndpi_dpi2json(ndpi_info_mod, ndpi_flow, detected_protocol, &csv_serializer);
|
||||
} else {
|
||||
ndpi_dpi2json(ndpi_info_mod, ndpi_flow, guessed_protocol, &json_serializer);
|
||||
ndpi_dpi2json(ndpi_info_mod, ndpi_flow, guessed_protocol, &csv_serializer);
|
||||
}
|
||||
ndpi_free_flow(ndpi_flow);
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue