/src/ndpi/src/lib/protocols/oicq.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * oicq.c |
3 | | * |
4 | | * OICQ / Tencent QQ |
5 | | * |
6 | | * Copyright (C) 2023 - ntop.org |
7 | | * |
8 | | * nDPI is free software: you can redistribute it and/or modify |
9 | | * it under the terms of the GNU Lesser General Public License as published by |
10 | | * the Free Software Foundation, either version 3 of the License, or |
11 | | * (at your option) any later version. |
12 | | * |
13 | | * nDPI is distributed in the hope that it will be useful, |
14 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | * GNU Lesser General Public License for more details. |
17 | | * |
18 | | * You should have received a copy of the GNU Lesser General Public License |
19 | | * along with nDPI. If not, see <http://www.gnu.org/licenses/>. |
20 | | * |
21 | | */ |
22 | | |
23 | | |
24 | | #include "ndpi_protocol_ids.h" |
25 | | |
26 | | #define NDPI_CURRENT_PROTO NDPI_PROTOCOL_OICQ |
27 | | |
28 | | #include "ndpi_api.h" |
29 | | #include "ndpi_private.h" |
30 | | |
31 | | PACK_ON |
32 | | struct oicq_hdr { |
33 | | uint8_t flag; |
34 | | uint16_t version; |
35 | | uint16_t command; |
36 | | uint16_t sequence; |
37 | | } PACK_OFF; |
38 | | |
39 | | static void ndpi_int_oicq_add_connection(struct ndpi_detection_module_struct * const ndpi_struct, |
40 | | struct ndpi_flow_struct * const flow) |
41 | 0 | { |
42 | 0 | NDPI_LOG_INFO(ndpi_struct, "found OICQ\n"); |
43 | |
|
44 | 0 | ndpi_set_detected_protocol(ndpi_struct, flow, |
45 | 0 | NDPI_PROTOCOL_OICQ, |
46 | 0 | NDPI_PROTOCOL_UNKNOWN, |
47 | 0 | NDPI_CONFIDENCE_DPI); |
48 | 0 | } |
49 | | |
50 | | /* ***************************************************** */ |
51 | | |
52 | | static void ndpi_search_oicq(struct ndpi_detection_module_struct *ndpi_struct, |
53 | | struct ndpi_flow_struct *flow) |
54 | 0 | { |
55 | 0 | struct ndpi_packet_struct const * const packet = &ndpi_struct->packet; |
56 | 0 | struct oicq_hdr const * const hdr = (struct oicq_hdr *)&packet->payload[0]; |
57 | |
|
58 | 0 | NDPI_LOG_DBG(ndpi_struct, "search OICQ\n"); |
59 | |
|
60 | 0 | if (packet->payload_packet_len < sizeof(*hdr)) |
61 | 0 | { |
62 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
63 | 0 | return; |
64 | 0 | } |
65 | | |
66 | 0 | if (hdr->flag != 0x02) |
67 | 0 | { |
68 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
69 | 0 | return; |
70 | 0 | } |
71 | | |
72 | 0 | if (ntohs(hdr->version) != 0x3b0b) |
73 | 0 | { |
74 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
75 | 0 | return; |
76 | 0 | } |
77 | | |
78 | 0 | uint16_t command = ntohs(hdr->command); |
79 | 0 | if (command == 0x0000 || (command > 0x00b5 && command < 0x03f7) || |
80 | 0 | command > 0x03f7) |
81 | 0 | { |
82 | 0 | NDPI_EXCLUDE_DISSECTOR(ndpi_struct, flow); |
83 | 0 | return; |
84 | 0 | } |
85 | | |
86 | 0 | ndpi_int_oicq_add_connection(ndpi_struct, flow); |
87 | 0 | } |
88 | | |
89 | | /* ***************************************************** */ |
90 | | |
91 | | void init_oicq_dissector(struct ndpi_detection_module_struct *ndpi_struct) |
92 | 1 | { |
93 | 1 | register_dissector("OICQ", ndpi_struct, |
94 | 1 | ndpi_search_oicq, |
95 | 1 | NDPI_SELECTION_BITMASK_PROTOCOL_V4_V6_UDP_WITH_PAYLOAD, |
96 | 1 | 1, NDPI_PROTOCOL_OICQ); |
97 | 1 | } |