### Bug Summary

File: | builds/wireshark/wireshark/extcap/androiddump.c
Warning: | line 1965, column 9 An undefined value may be read from 'errno'

### Annotated Source Code

Press '?' to see keyboard shortcuts

Show analyzer invocation
clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name androiddump.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -fno-delete-null-pointer-checks -mframe-pointer=all -relaxed-aliasing -fmath-errno -ffp-contract=on -fno-rounding-math -ffloat16-excess-precision=fast -fbfloat16-excess-precision=fast -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/builds/wireshark/wireshark/build -fcoverage-compilation-dir=/builds/wireshark/wireshark/build -resource-dir /usr/lib/llvm-22/lib/clang/22 -isystem /usr/include/glib-2.0 -isystem /usr/lib/x86_64-linux-gnu/glib-2.0/include -D CARES_NO_DEPRECATED -D G_DISABLE_DEPRECATED -D G_DISABLE_SINGLE_INCLUDES -D WS_DEBUG -D WS_DEBUG_UTF_8 -I /builds/wireshark/wireshark/build -I /builds/wireshark/wireshark -I /builds/wireshark/wireshark/include -I /builds/wireshark/wireshark/wiretap -D _GLIBCXX_ASSERTIONS -internal-isystem /usr/lib/llvm-22/lib/clang/22/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/16/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fmacro-prefix-map=/builds/wireshark/wireshark/= -fmacro-prefix-map=/builds/wireshark/wireshark/build/= -fmacro-prefix-map=../= -Wno-format-nonliteral -std=gnu17 -ferror-limit 19 -fvisibility=hidden -fwrapv -fwrapv-pointer -fstrict-flex-arrays=3 -stack-protector 2 -fstack-clash-protection -fcf-protection=full -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fexceptions -fcolor-diagnostics -analyzer-output=html -faddrsig -fdwarf2-cfi-asm -o /builds/wireshark/wireshark/sbout/2026-09-02-100927-3660-1 -x c /builds/wireshark/wireshark/extcap/androiddump.c

Keyboard shortcuts:

- Use 'j/k' keys for keyboard navigation
- Use 'Shift+S' to show/hide relevant lines
- Use '?' to toggle this window

Close
Show only relevant lines Show control flow arrows

1 | /* androiddump.c
2 | * androiddump is extcap tool used to capture Android specific stuff
3 | *
4 | * Copyright 2015, Michal Labedzki for Tieto Corporation
5 | *
6 | * Wireshark - Network traffic analyzer
7 | * By Gerald Combs <gerald@wireshark.org>
8 | * Copyright 1998 Gerald Combs
9 | *
10 | * SPDX-License-Identifier: GPL-2.0-or-later
11 | */
12 | #include "config.h"
13 | #define WS_LOG_DOMAIN"androiddump" "androiddump"
14 |
15 | #include "extcap-base.h"
16 |
17 | #include <stdio.h>
18 | #include <stdint.h>
19 | #include <string.h>
20 | #include <errno(*__errno_location ()).h>
21 | #include <time.h>
22 | #include <fcntl.h>
23 | #include <wsutil/strtoi.h>
24 | #include <wsutil/filesystem.h>
25 | #include <wsutil/privileges.h>
26 | #include <wsutil/please_report_bug.h>
27 | #include <wsutil/wslog.h>
28 | #include <wsutil/cmdarg_err.h>
29 | #include <wsutil/inet_addr.h>
30 | #include <wsutil/exported_pdu_tlvs.h>
31 | #include <wsutil/report_message.h>
32 | #include <app/application_flavor.h>
33 |
34 | #ifdef HAVE_NETINET_IN_H1
35 | # include <netinet/in.h>
36 | #endif
37 |
38 | #ifdef HAVE_UNISTD_H1
39 | #include <unistd.h>
40 | #endif
41 |
42 | #ifdef HAVE_SYS_SOCKET_H1
43 | #include <sys/socket.h>
44 | #endif
45 |
46 | #ifdef HAVE_ARPA_INET_H1
47 | #include <arpa/inet.h>
48 | #endif
49 |
50 | #ifdef HAVE_SYS_TIME_H1
51 | #include <sys/time.h>
52 | #endif
53 |
54 | /* Configuration options */
55 | /* #define ANDROIDDUMP_USE_LIBPCAP */
56 |
57 | #define PCAP_GLOBAL_HEADER_LENGTH24 24
58 | #define PCAP_RECORD_HEADER_LENGTH16 16
59 |
60 | #ifdef ANDROIDDUMP_USE_LIBPCAP
61 | #include <pcap/pcap.h>
62 | #include <pcap/bpf.h>
63 | #include <pcap/bluetooth.h>
64 |
65 | #ifndef DLT_BLUETOOTH_H4_WITH_PHDR
66 | #define DLT_BLUETOOTH_H4_WITH_PHDR 201
67 | #endif
68 |
69 | #ifndef DLT_WIRESHARK_UPPER_PDU
70 | #define DLT_WIRESHARK_UPPER_PDU 252
71 | #endif
72 |
73 | #ifndef PCAP_TSTAMP_PRECISION_MICRO
74 | #define PCAP_TSTAMP_PRECISION_MICRO 0
75 | #endif
76 |
77 | #ifndef PCAP_TSTAMP_PRECISION_NANO
78 | #define PCAP_TSTAMP_PRECISION_NANO 1
79 | #endif
80 | #else
81 | #include "wiretap/wtap.h"
82 | #include "wiretap/pcap-encap.h"
83 | #include "ui/failure_message.h"
84 | #endif
85 |
86 | #ifdef ANDROIDDUMP_USE_LIBPCAP
87 | #define EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99 DLT_BLUETOOTH_H4_WITH_PHDR
88 | #define EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155 DLT_WIRESHARK_UPPER_PDU
89 | #define EXTCAP_ENCAP_ETHERNET1 DLT_EN10MB
90 | #define EXTCAP_ENCAP_LINUX_SLL25 DLT_LINUX_SLL
91 | #define EXTCAP_ENCAP_IEEE802_11_RADIO23 DLT_IEEE802_11_RADIO
92 | #define EXTCAP_ENCAP_NETLINK158 DLT_NETLINK
93 | #else
94 | #define EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99 WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99
95 | #define EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155 WTAP_ENCAP_WIRESHARK_UPPER_PDU155
96 | #define EXTCAP_ENCAP_ETHERNET1 WTAP_ENCAP_ETHERNET1
97 | #define EXTCAP_ENCAP_LINUX_SLL25 WTAP_ENCAP_SLL25
98 | #define EXTCAP_ENCAP_IEEE802_11_RADIO23 WTAP_ENCAP_IEEE_802_11_RADIOTAP23
99 | #define EXTCAP_ENCAP_NETLINK158 WTAP_ENCAP_NETLINK158
100 | #endif
101 |
102 | #define INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main" "android-logcat-main"
103 | #define INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system" "android-logcat-system"
104 | #define INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio" "android-logcat-radio"
105 | #define INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events" "android-logcat-events"
106 | #define INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main" "android-logcat-text-main"
107 | #define INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system" "android-logcat-text-system"
108 | #define INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio" "android-logcat-text-radio"
109 | #define INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events" "android-logcat-text-events"
110 | #define INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash" "android-logcat-text-crash"
111 | #define INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump" "android-bluetooth-hcidump"
112 | #define INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser" "android-bluetooth-external-parser"
113 | #define INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net" "android-bluetooth-btsnoop-net"
114 | #define INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "android-tcpdump"
115 | #define INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s" INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "-%s"
116 | #define INTERFACE_ANDROID_TCPDUMP_SERIAL_FORMAT"android-tcpdump" "-%s" "-%s" INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s" "-%s"
117 |
118 | #define ANDROIDDUMP_VERSION_MAJOR"1" "1"
119 | #define ANDROIDDUMP_VERSION_MINOR"1" "1"
120 | #define ANDROIDDUMP_VERSION_RELEASE"0" "0"
121 |
122 | #define SERIAL_NUMBER_LENGTH_MAX512 512
123 | #define MODEL_NAME_LENGTH_MAX64 64
124 |
125 | #define PACKET_LENGTH65535 65535
126 |
127 | #define SOCKET_RW_TIMEOUT_MS2000 2000
128 | #define SOCKET_CONNECT_TIMEOUT_TRIES10 10
129 | #define SOCKET_CONNECT_DELAY_US1000 1000 /* (1000us = 1ms) * SOCKET_CONNECT_TIMEOUT_TRIES (10) = 10ms worst-case */
130 |
131 | #define ADB_HEX4_FORMAT"%04zx" "%04zx"
132 | #define ADB_HEX4_LEN4 4
133 |
134 | #define BTSNOOP_HDR_LEN16 16
135 |
136 | enum exit_code {
137 | EXIT_CODE_SUCCESS = 0,
138 | EXIT_CODE_CANNOT_GET_INTERFACES_LIST = 1,
139 | EXIT_CODE_UNKNOWN_ENCAPSULATION_WIRETAP,
140 | EXIT_CODE_UNKNOWN_ENCAPSULATION_LIBPCAP,
141 | EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP,
142 | EXIT_CODE_CANNOT_SAVE_LIBPCAP_DUMP,
143 | EXIT_CODE_NO_INTERFACE_SPECIFIED,
144 | EXIT_CODE_INVALID_INTERFACE,
145 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_1,
146 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_2,
147 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_3,
148 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_4,
149 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_5,
150 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_6,
151 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_7,
152 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_8,
153 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_9,
154 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_10,
155 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_11,
156 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_12,
157 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_13,
158 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_14,
159 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_15,
160 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_16,
161 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_17,
162 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_18,
163 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_19,
164 | EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_20,
165 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1,
166 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_2,
167 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_3,
168 | EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_4,
169 | EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_STATUS,
170 | EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_DATA,
171 | EXIT_CODE_INVALID_SOCKET_INTERFACES_LIST,
172 | EXIT_CODE_INVALID_SOCKET_1,
173 | EXIT_CODE_INVALID_SOCKET_2,
174 | EXIT_CODE_INVALID_SOCKET_3,
175 | EXIT_CODE_INVALID_SOCKET_4,
176 | EXIT_CODE_INVALID_SOCKET_5,
177 | EXIT_CODE_INVALID_SOCKET_6,
178 | EXIT_CODE_INVALID_SOCKET_7,
179 | EXIT_CODE_INVALID_SOCKET_8,
180 | EXIT_CODE_INVALID_SOCKET_9,
181 | EXIT_CODE_INVALID_SOCKET_10,
182 | EXIT_CODE_INVALID_SOCKET_11,
183 | EXIT_CODE_GENERIC = -1
184 | };
185 |
186 | enum {
187 | EXTCAP_BASE_OPTIONS_ENUMEXTCAP_OPT_LIST_INTERFACES, EXTCAP_OPT_VERSION, EXTCAP_OPT_LIST_DLTS , EXTCAP_OPT_INTERFACE, EXTCAP_OPT_CONFIG, EXTCAP_OPT_CONFIG_OPTION_NAME , EXTCAP_OPT_CONFIG_OPTION_VALUE, EXTCAP_OPT_CLEANUP_POSTKILL , EXTCAP_OPT_CAPTURE, EXTCAP_OPT_CAPTURE_FILTER, EXTCAP_OPT_FIFO , EXTCAP_OPT_CONTROL_OUT, EXTCAP_OPT_CONTROL_IN, EXTCAP_OPT_LOG_LEVEL , EXTCAP_OPT_LOG_FILE,
188 | OPT_HELP,
189 | OPT_VERSION,
190 | OPT_CONFIG_ADB_SERVER_IP,
191 | OPT_CONFIG_ADB_SERVER_TCP_PORT,
192 | OPT_CONFIG_LOGCAT_TEXT,
193 | OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER,
194 | OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS,
195 | OPT_CONFIG_BT_SERVER_TCP_PORT,
196 | OPT_CONFIG_BT_FORWARD_SOCKET,
197 | OPT_CONFIG_BT_LOCAL_IP,
198 | OPT_CONFIG_BT_LOCAL_TCP_PORT
199 | };
200 |
201 | static const struct ws_option longopts[] = {
202 | EXTCAP_BASE_OPTIONS{ "extcap-interfaces", 0, ((void*)0), EXTCAP_OPT_LIST_INTERFACES }, { "extcap-version", 2, ((void*)0), EXTCAP_OPT_VERSION}, { "extcap-dlts" , 0, ((void*)0), EXTCAP_OPT_LIST_DLTS}, { "extcap-interface", 1, ((void*)0), EXTCAP_OPT_INTERFACE}, { "extcap-config", 0, ( (void*)0), EXTCAP_OPT_CONFIG}, { "extcap-config-option-name", 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_NAME}, { "extcap-config-option-value" , 1, ((void*)0), EXTCAP_OPT_CONFIG_OPTION_VALUE }, { "extcap-cleanup-postkill" , 0, ((void*)0), EXTCAP_OPT_CLEANUP_POSTKILL }, { "capture", 0 , ((void*)0), EXTCAP_OPT_CAPTURE}, { "extcap-capture-filter", 1, ((void*)0), EXTCAP_OPT_CAPTURE_FILTER}, { "fifo", 1, ((void *)0), EXTCAP_OPT_FIFO}, { "extcap-control-out", 1, ((void*)0) , EXTCAP_OPT_CONTROL_OUT}, { "extcap-control-in", 1, ((void*) 0), EXTCAP_OPT_CONTROL_IN}, { "log-level", 1, ((void*)0), EXTCAP_OPT_LOG_LEVEL }, { "log-file", 1, ((void*)0), EXTCAP_OPT_LOG_FILE},
203 | { "help", ws_no_argument0, NULL((void*)0), OPT_HELP},
204 | { "version", ws_no_argument0, NULL((void*)0), OPT_VERSION},
205 | { "adb-server-ip", ws_required_argument1, NULL((void*)0), OPT_CONFIG_ADB_SERVER_IP},
206 | { "adb-server-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_ADB_SERVER_TCP_PORT},
207 | { "logcat-text", ws_optional_argument2, NULL((void*)0), OPT_CONFIG_LOGCAT_TEXT},
208 | { "logcat-ignore-log-buffer", ws_optional_argument2, NULL((void*)0), OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER},
209 | { "logcat-custom-options", ws_required_argument1, NULL((void*)0), OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS},
210 | { "bt-server-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_SERVER_TCP_PORT},
211 | { "bt-forward-socket", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_FORWARD_SOCKET},
212 | { "bt-local-ip", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_LOCAL_IP},
213 | { "bt-local-tcp-port", ws_required_argument1, NULL((void*)0), OPT_CONFIG_BT_LOCAL_TCP_PORT},
214 | { 0, 0, 0, 0 }
215 | };
216 |
217 | struct interface_t {
218 | const char *display_name;
219 | const char *interface_name;
220 | struct interface_t *next;
221 | };
222 |
223 | struct exported_pdu_header {
224 | uint16_t tag;
225 | uint16_t length;
226 | /* unsigned char value[0]; */
227 | };
228 |
229 |
230 | typedef struct _own_pcap_bluetooth_h4_header {
231 | uint32_t direction;
232 | } own_pcap_bluetooth_h4_header;
233 |
234 | typedef struct pcap_hdr_s {
235 | uint32_t magic_number; /* magic number */
236 | uint16_t version_major; /* major version number */
237 | uint16_t version_minor; /* minor version number */
238 | int32_t thiszone; /* GMT to local correction */
239 | uint32_t sigfigs; /* accuracy of timestamps */
240 | uint32_t snaplen; /* max length of captured packets, in octets */
241 | uint32_t network; /* data link type */
242 | } pcap_hdr_t;
243 |
244 |
245 | typedef struct pcaprec_hdr_s {
246 | uint32_t ts_sec; /* timestamp seconds */
247 | uint32_t ts_usec; /* timestamp microseconds */
248 | uint32_t incl_len; /* number of octets of packet saved in file */
249 | uint32_t orig_len; /* actual length of packet */
250 | } pcaprec_hdr_t;
251 |
252 | /* This fix compilator warning like "warning: cast from 'char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 " */
253 | typedef union {
254 | char *value_char;
255 | uint8_t *value_u8;
256 | uint16_t *value_u16;
257 | uint32_t *value_u32;
258 | uint64_t *value_u64;
259 | int8_t *value_i8;
260 | int16_t *value_i16;
261 | int32_t *value_i32;
262 | int64_t *value_i64;
263 | own_pcap_bluetooth_h4_header *value_own_pcap_bluetooth_h4_header;
264 | } data_aligned_t;
265 |
266 | #define SET_DATA(dest, type, src){ data_aligned_t data_aligned; data_aligned.value_char = src; dest = data_aligned.type; } \
267 | { \
268 | data_aligned_t data_aligned; \
269 | \
270 | data_aligned.value_char = src; \
271 | dest = data_aligned.type; \
272 | }
273 |
274 | struct extcap_dumper {
275 | int encap;
276 | union {
277 | #ifdef ANDROIDDUMP_USE_LIBPCAP
278 | pcap_dumper_t *pcap;
279 | #else
280 | wtap_dumper *wtap;
281 | #endif
282 | } dumper;
283 | };
284 |
285 | /* Globals */
286 | static int endless_loop = 1;
287 |
288 | /* Functions */
289 | static inline int is_specified_interface(const char *interface, const char *interface_prefix) {
290 | return !strncmp(interface, interface_prefix, strlen(interface_prefix));
291 | }
292 |
293 | static bool_Bool is_logcat_interface(const char *interface) {
294 | return is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main") ||
295 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system") ||
296 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio") ||
297 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events");
298 | }
299 |
300 | static bool_Bool is_logcat_text_interface(const char *interface) {
301 | return is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main") ||
302 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system") ||
303 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio") ||
304 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events") ||
305 | is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash");
306 | }
307 |
308 | static char* get_serial_from_interface(char *interface)
309 | {
310 | static const char* const iface_prefix[] = {
311 | INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main",
312 | INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system",
313 | INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio",
314 | INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events",
315 | INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main",
316 | INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system",
317 | INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio",
318 | INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events",
319 | INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash",
320 | INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump",
321 | INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser",
322 | INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net",
323 | NULL((void*)0)
324 | };
325 | int i;
326 | const char* curr = NULL((void*)0);
327 | for (i = 0; (curr = iface_prefix[i]); i++) {
328 | if (is_specified_interface(interface, curr) &&
329 | strlen(interface) > strlen(curr) + 1) {
330 | return interface + strlen(curr) + 1;
331 | }
332 | }
333 | return NULL((void*)0);
334 | }
335 |
336 | static const char* interface_to_logbuf(char* interface)
337 | {
338 | const char *const adb_log_main = "log:main";
339 | const char *const adb_log_system = "log:system";
340 | const char *const adb_log_radio = "log:radio";
341 | const char *const adb_log_events = "log:events";
342 | const char *logbuf = NULL((void*)0);
343 |
344 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main"))
345 | logbuf = adb_log_main;
346 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system"))
347 | logbuf = adb_log_system;
348 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio"))
349 | logbuf = adb_log_radio;
350 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events"))
351 | logbuf = adb_log_events;
352 | return logbuf;
353 | }
354 |
355 | /* "Error codes set by Windows Sockets are not made available through the errno
356 | * variable."
357 | * https://learn.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2
358 | */
359 | #ifdef _WIN32
360 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
361 | if (length == SOCKET_ERROR(-1)) { \
362 | int last_err = WSAGetLastError(); \
363 | if (last_err == WSAETIMEDOUT || last_err == WSAEWOULDBLOCK) \
364 | continue; \
365 | }
366 | #elif EWOULDBLOCK11 != EAGAIN11
367 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
368 | if (errno(*__errno_location ()) == EAGAIN11 || errno(*__errno_location ()) == EWOULDBLOCK11) \
369 | continue;
370 | #else
371 | #define CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue; \
372 | if (errno(*__errno_location ()) == EAGAIN11) \
373 | continue;
374 | #endif /* _WIN32 */
375 |
376 | static void useSndTimeout(socket_handle_tint sock) {
377 | int res;
378 | #ifdef _WIN32
379 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
380 |
381 | res = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char *) &socket_timeout, (socklen_t)sizeof(socket_timeout));
382 | #else
383 | const struct timeval socket_timeout = {
384 | .tv_sec = SOCKET_RW_TIMEOUT_MS2000 / 1000,
385 | .tv_usec = (SOCKET_RW_TIMEOUT_MS2000 % 1000) * 1000
386 | };
387 |
388 | res = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, &socket_timeout, (socklen_t)sizeof(socket_timeout));
389 | #endif
390 | if (res != 0)
391 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 391, __func__, "Can't set socket timeout, using default"); } } while (0);
392 | }
393 |
394 | static void useNonBlockingConnectTimeout(socket_handle_tint sock) {
395 | #ifdef _WIN32
396 | int res_snd;
397 | int res_rcv;
398 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
399 | unsigned long non_blocking = 1;
400 |
401 | /* set timeout when non-blocking to 2s on Windows */
402 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char*)&socket_timeout, sizeof(socket_timeout));
403 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, (const char*)&socket_timeout, sizeof(socket_timeout));
404 | /* set socket to non-blocking */
405 | ioctlsocket(sock, FIONBIO, &non_blocking);
406 | if (res_snd != 0)
407 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 407, __func__, "Can't set socket timeout, using default"); } } while (0);
408 | if (res_rcv != 0)
409 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 409, __func__, "Can't set socket timeout, using default"); } } while (0);
410 | #else
411 | int flags = fcntl(sock, F_GETFL3);
412 | if (-1 == fcntl(sock, F_SETFL4, flags | O_NONBLOCK04000)) {
413 | ws_info("Failure setting socket to non-blocking: %s", g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_INFO, ((void *)0), -1, ((void*)0), "Failure setting socket to non-blocking: %s" , g_strerror((*__errno_location ()))); } } while (0);
414 | }
415 | #endif
416 | }
417 |
418 | static void useNormalConnectTimeout(socket_handle_tint sock) {
419 | int res_snd;
420 | int res_rcv;
421 | #ifdef _WIN32
422 | const DWORD socket_timeout = SOCKET_RW_TIMEOUT_MS2000;
423 | unsigned long non_blocking = 0;
424 |
425 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, (const char *) &socket_timeout, sizeof(socket_timeout));
426 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, (const char *) &socket_timeout, sizeof(socket_timeout));
427 | ioctlsocket(sock, FIONBIO, &non_blocking);
428 | #else
429 | int flags = fcntl(sock, F_GETFL3);
430 | if (-1 == fcntl(sock, F_SETFL4, flags & ~O_NONBLOCK04000)) {
431 | ws_info("Failure setting socket to blocking: %s", g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_INFO, ((void *)0), -1, ((void*)0), "Failure setting socket to blocking: %s" , g_strerror((*__errno_location ()))); } } while (0);
432 | }
433 | const struct timeval socket_timeout = {
434 | .tv_sec = SOCKET_RW_TIMEOUT_MS2000 / 1000,
435 | .tv_usec = (SOCKET_RW_TIMEOUT_MS2000 % 1000) * 1000
436 | };
437 |
438 | res_snd = setsockopt(sock, SOL_SOCKET1, SO_SNDTIMEO21, &socket_timeout, sizeof(socket_timeout));
439 | res_rcv = setsockopt(sock, SOL_SOCKET1, SO_RCVTIMEO20, &socket_timeout, sizeof(socket_timeout));
440 | #endif
441 | if (res_snd != 0)
442 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 442, __func__, "Can't set socket timeout, using default"); } } while (0);
443 | if (res_rcv != 0)
444 | ws_debug("Can't set socket timeout, using default")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 444, __func__, "Can't set socket timeout, using default"); } } while (0);
445 | }
446 |
447 | static struct extcap_dumper extcap_dumper_open(char *fifo, int encap) {
448 | struct extcap_dumper extcap_dumper;
449 |
450 | #ifdef ANDROIDDUMP_USE_LIBPCAP
451 | pcap_t *pcap;
452 |
453 | pcap = pcap_open_dead_with_tstamp_precision(encap, PACKET_LENGTH65535, PCAP_TSTAMP_PRECISION_NANO);
454 | extcap_dumper.dumper.pcap = pcap_dump_open(pcap, fifo);
455 | if (!extcap_dumper.dumper.pcap) {
456 | ws_warning("Can't open %s for saving packets: %s", fifo, pcap_geterr(pcap))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 456, __func__, "Can't open %s for saving packets: %s", fifo , pcap_geterr(pcap)); } } while (0);
457 | pcap_close(pcap);
458 | exit(EXIT_CODE_CANNOT_SAVE_LIBPCAP_DUMP);
459 | }
460 | extcap_dumper.encap = encap;
461 | if (pcap_dump_flush(extcap_dumper.dumper.pcap) == -1) {
462 | ws_warning("Write to %s failed: %s", fifo, g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 462, __func__, "Write to %s failed: %s", fifo, g_strerror(( *__errno_location ()))); } } while (0);
463 | }
464 | #else
465 | wtap_dump_params params = WTAP_DUMP_PARAMS_INIT{.snaplen=0};
466 | int file_type_subtype;
467 | int err = 0;
468 | char *err_info = NULL((void*)0);
469 | const struct file_extension_info* file_extensions;
470 | unsigned num_extensions;
471 |
472 | application_file_extensions(&file_extensions, &num_extensions);
473 | wtap_init(false0, application_configuration_environment_prefix(), file_extensions, num_extensions);
474 |
475 | params.encap = encap;
476 | params.snaplen = PACKET_LENGTH65535;
477 | file_type_subtype = wtap_pcap_nsec_file_type_subtype();
478 | extcap_dumper.dumper.wtap = wtap_dump_open(fifo, file_type_subtype, WS_FILE_UNCOMPRESSED, &params, &err, &err_info);
479 | if (!extcap_dumper.dumper.wtap) {
480 | report_cfile_dump_open_failure(fifo, err, err_info, file_type_subtype);
481 | exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
482 | }
483 | extcap_dumper.encap = encap;
484 | if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
485 | report_cfile_dump_open_failure(fifo, err, NULL((void*)0), file_type_subtype);
486 | exit(EXIT_CODE_CANNOT_SAVE_WIRETAP_DUMP);
487 | }
488 | #endif
489 |
490 | return extcap_dumper;
491 | }
492 |
493 | static bool_Bool extcap_dumper_dump(struct extcap_dumper extcap_dumper,
494 | char *fifo, char *buffer,
495 | ssize_t captured_length, ssize_t reported_length,
496 | time_t seconds, int nanoseconds) {
497 | #ifdef ANDROIDDUMP_USE_LIBPCAP
498 | struct pcap_pkthdr pcap_header;
499 |
500 | pcap_header.caplen = (bpf_u_int32) captured_length;
501 | pcap_header.len = (bpf_u_int32) reported_length;
502 | pcap_header.ts.tv_sec = seconds;
503 | pcap_header.ts.tv_usec = nanoseconds / 1000;
504 |
505 | pcap_dump((u_char *) extcap_dumper.dumper.pcap, &pcap_header, (uint8_t*)buffer);
506 | if (pcap_dump_flush(extcap_dumper.dumper.pcap) == -1) {
507 | ws_warning("Write to %s failed: %s", fifo, g_strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 507, __func__, "Write to %s failed: %s", fifo, g_strerror(( *__errno_location ()))); } } while (0);
508 | }
509 | #else
510 | int err = 0;
511 | char *err_info;
512 | wtap_rec rec;
513 |
514 | wtap_rec_init(&rec, captured_length);
515 | wtap_setup_packet_rec(&rec, extcap_dumper.encap);
516 |
517 | rec.presence_flags = WTAP_HAS_TS0x00000001;
518 | rec.ts.secs = seconds;
519 | rec.ts.nsecs = (int) nanoseconds;
520 |
521 | /* NOTE: Try to handle pseudoheaders manually */
522 | if (extcap_dumper.encap == EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99) {
523 | uint32_t *direction;
524 |
525 | SET_DATA(direction, value_u32, buffer){ data_aligned_t data_aligned; data_aligned.value_char = buffer ; direction = data_aligned.value_u32; }
526 |
527 | rec.rec_header.packet_header.pseudo_header.bthci.sent = GINT32_FROM_BE(*direction)(((gint32) (((guint32) ( (((guint32) (*direction) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*direction) & ( guint32) 0x0000ff00U) << 8) | (((guint32) (*direction) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*direction ) & (guint32) 0xff000000U) >> 24)))))) ? 0 : 1;
528 |
529 | buffer += sizeof(own_pcap_bluetooth_h4_header);
530 | captured_length -= sizeof(own_pcap_bluetooth_h4_header);
531 | }
532 |
533 | rec.rec_header.packet_header.caplen = (uint32_t) captured_length;
534 | rec.rec_header.packet_header.len = (uint32_t) reported_length;
535 |
536 | ws_buffer_append(&rec.data, (const uint8_t*)buffer, captured_length);
537 |
538 | if (!wtap_dump(extcap_dumper.dumper.wtap, &rec, &err, &err_info)) {
539 | report_cfile_write_failure(NULL((void*)0), fifo, err, err_info, 0,
540 | wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
541 | wtap_rec_cleanup(&rec);
542 | return false0;
543 | }
544 |
545 | if (!wtap_dump_flush(extcap_dumper.dumper.wtap, &err)) {
546 | report_cfile_write_failure(NULL((void*)0), fifo, err, NULL((void*)0), 0,
547 | wtap_dump_file_type_subtype(extcap_dumper.dumper.wtap));
548 | wtap_rec_cleanup(&rec);
549 | return false0;
550 | }
551 |
552 | wtap_rec_cleanup(&rec);
553 | #endif
554 |
555 | return true1;
556 | }
557 |
558 |
559 | static socket_handle_tint adb_connect(const char *server_ip, unsigned short *server_tcp_port) {
560 | socket_handle_tint sock;
561 | socklen_t length;
562 | struct sockaddr_in server;
563 | struct sockaddr_in client;
564 | int status;
565 | #ifndef _WIN32
566 | int result;
567 | #endif
568 | int tries = 0;
569 |
570 | memset(&server, 0x0, sizeof(server));
571 |
572 | server.sin_family = AF_INET2;
573 | server.sin_port = GINT16_TO_BE(*server_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*server_tcp_port ) >> 8) | (guint16) ((guint16) (*server_tcp_port) << 8)))));
574 | ws_inet_pton4(server_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
575 |
576 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
577 | ws_warning("Cannot open system TCP socket: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 577, __func__, "Cannot open system TCP socket: %s", strerror ((*__errno_location ()))); } } while (0);
578 | return INVALID_SOCKET(-1);
579 | }
580 |
581 | useNonBlockingConnectTimeout(sock);
582 | status = connect(sock, (struct sockaddr *) &server, (socklen_t)sizeof(server));
583 | #ifdef _WIN32
584 | if ((status == SOCKET_ERROR(-1)) && (WSAGetLastError() == WSAEWOULDBLOCK)) {
585 | #else
586 | if ((status == SOCKET_ERROR(-1)) && (errno(*__errno_location ()) == EINPROGRESS115)) {
587 | #endif
588 | while (tries < SOCKET_CONNECT_TIMEOUT_TRIES10) {
589 | tries += 1;
590 | struct timeval timeout = {
591 | .tv_sec = 0,
592 | .tv_usec = SOCKET_CONNECT_DELAY_US1000,
593 | };
594 | fd_set fdset;
595 | FD_ZERO(&fdset)do { unsigned int __i; fd_set *__arr = (&fdset); for (__i = 0; __i < sizeof (fd_set) / sizeof (__fd_mask); ++__i) ( (__arr)->__fds_bits)[__i] = 0; } while (0);
596 | FD_SET(sock, &fdset)((void) (((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof (__fd_mask)))] |= ((__fd_mask) (1UL << ((sock) % (8 * ( int) sizeof (__fd_mask)))))));
597 | #ifdef _WIN32
598 | if ((select(0, NULL((void*)0), &fdset, NULL((void*)0), &timeout) != 0) && (FD_ISSET(sock, &fdset)((((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof ( __fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))) {
599 | status = 0;
600 | break;
601 | #else
602 | if ((select(sock+1, NULL((void*)0), &fdset, NULL((void*)0), &timeout) != 0) && (FD_ISSET(sock, &fdset)((((&fdset)->__fds_bits)[((sock) / (8 * (int) sizeof ( __fd_mask)))] & ((__fd_mask) (1UL << ((sock) % (8 * (int) sizeof (__fd_mask)))))) != 0))) {
603 | length = sizeof(result);
604 | getsockopt(sock, SOL_SOCKET1, SO_ERROR4, &result, &length);
605 | if (result == 0) {
606 | status = 0;
607 | } else {
608 | ws_debug("Error connecting to ADB: <%s>", strerror(result))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 608, __func__, "Error connecting to ADB: <%s>", strerror (result)); } } while (0);
609 | }
610 | break;
611 | #endif
612 | } else {
613 | ws_debug("Try %i: Timeout connecting to ADB", tries)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 613, __func__, "Try %i: Timeout connecting to ADB", tries); } } while (0);
614 | }
615 | }
616 | }
617 | useNormalConnectTimeout(sock);
618 |
619 | if (status == SOCKET_ERROR(-1)) {
620 | #if 0
621 | /* NOTE: This does not work well - make significant delay while initializing Wireshark.
622 | Do fork() then call "adb" also does not make sense, because there is need to
623 | do something like sleep(1) to ensure adb is started... system() cannot be used
624 | on Windows, because open console window. This helper does not work as expected,
625 | so disable it and user must ensure that adb is started (adb start-server,
626 | but also all other command start-server automatically)
627 | */
628 | #ifdef _WIN32
629 | if (_execlp("adb", "adb", "start-server", NULL((void*)0))) {
630 | #else
631 | if (execlp("adb", "adb", "start-server", NULL((void*)0))) {
632 | #endif
633 | errmsg("WARNING: Cannot execute system command to start adb: %s", strerror(errno(*__errno_location ())));
634 | closesocket(sock)close(sock);
635 | return INVALID_SOCKET(-1);
636 | };
637 |
638 | if (connect(sock, (struct sockaddr *) &server, (socklen_t)sizeof(server)) == SOCKET_ERROR(-1)) {
639 | ws_warning("Cannot connect to ADB: <%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 639, __func__, "Cannot connect to ADB: <%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
640 | closesocket(sock)close(sock);
641 | return INVALID_SOCKET(-1);
642 | }
643 | #else
644 | ws_debug("Cannot connect to ADB: Please check that adb daemon is running.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 644, __func__, "Cannot connect to ADB: Please check that adb daemon is running." ); } } while (0);
645 | closesocket(sock)close(sock);
646 | return INVALID_SOCKET(-1);
647 | #endif
648 | }
649 |
650 | length = sizeof(client);
651 | if (getsockname(sock, (struct sockaddr *) &client, &length)) {
652 | ws_warning("getsockname: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 652, __func__, "getsockname: %s", strerror((*__errno_location ()))); } } while (0);
653 | closesocket(sock)close(sock);
654 | return INVALID_SOCKET(-1);
655 | }
656 |
657 | if (length != sizeof(client)) {
658 | ws_warning("incorrect length")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 658, __func__, "incorrect length"); } } while (0);
659 | closesocket(sock)close(sock);
660 | return INVALID_SOCKET(-1);
661 | }
662 |
663 | ws_debug("Client port %u", GUINT16_FROM_BE(client.sin_port))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 663, __func__, "Client port %u", (((((guint16) ( (guint16) ( (guint16) (client.sin_port) >> 8) | (guint16) ((guint16 ) (client.sin_port) << 8))))))); } } while (0);
664 |
665 | return sock;
666 | }
667 |
668 |
669 | static char *adb_send_and_receive(socket_handle_tint sock, const char *adb_service,
670 | char *buffer, size_t buffer_length, size_t *data_length) {
671 | size_t used_buffer_length;
672 | size_t bytes_to_read;
673 | uint32_t length;
674 | ssize_t result;
675 | char status[4];
676 | char tmp_buffer;
677 | size_t adb_service_length;
678 |
679 | adb_service_length = strlen(adb_service);
680 | if (adb_service_length > INT_MAX2147483647) {
681 | ws_warning("Service name too long when sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 681, __func__, "Service name too long when sending <%s> to ADB daemon" , adb_service); } } while (0);
682 | if (data_length)
683 | *data_length = 0;
684 | return NULL((void*)0);
685 | }
686 |
687 | /* 8 bytes of hex length + terminating NUL */
688 | if (buffer_length < 9) {
689 | ws_warning("Buffer for response too short while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 689, __func__, "Buffer for response too short while sending <%s> to ADB daemon" , adb_service); } } while (0);
690 | if (data_length)
691 | *data_length = 0;
692 | return NULL((void*)0);
693 | }
694 |
695 | snprintf(buffer, buffer_length, ADB_HEX4_FORMAT"%04zx", adb_service_length);
696 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
697 | if (result < ADB_HEX4_LEN4) {
698 | ws_warning("Error while sending <%s> length to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 698, __func__, "Error while sending <%s> length to ADB daemon" , adb_service); } } while (0);
699 | return NULL((void*)0);
700 | }
701 |
702 | result = send(sock, adb_service, (int) adb_service_length, 0);
703 | if (result != (ssize_t) adb_service_length) {
704 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 704, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
705 | if (data_length)
706 | *data_length = 0;
707 | return NULL((void*)0);
708 | }
709 |
710 | used_buffer_length = 0;
711 | while (used_buffer_length < 8) {
712 | bytes_to_read = buffer_length - used_buffer_length;
713 | if (bytes_to_read > INT_MAX2147483647)
714 | bytes_to_read = INT_MAX2147483647;
715 | result = recv(sock, buffer + used_buffer_length, (int)bytes_to_read, 0);
716 |
717 | if (result <= 0) {
718 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 718, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
719 | if (data_length)
720 | *data_length = 0;
721 | return NULL((void*)0);
722 | }
723 |
724 | used_buffer_length += result;
725 | }
726 |
727 | memcpy(status, buffer, 4);
728 | tmp_buffer = buffer[8];
729 | buffer[8] = '\0';
730 | if (!ws_hexstrtou32(buffer + 4, NULL((void*)0), &length)) {
731 | ws_warning("Invalid reply length <%s> while reading reply for <%s>", buffer + 4, adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 731, __func__, "Invalid reply length <%s> while reading reply for <%s>" , buffer + 4, adb_service); } } while (0);
732 | if (data_length)
733 | *data_length = 0;
734 | return NULL((void*)0);
735 | }
736 | buffer[8] = tmp_buffer;
737 |
738 | if (buffer_length < length + 8) {
739 | ws_warning("Buffer for response too short while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 739, __func__, "Buffer for response too short while sending <%s> to ADB daemon" , adb_service); } } while (0);
740 | if (data_length)
741 | *data_length = 0;
742 | return NULL((void*)0);
743 | }
744 |
745 | while (used_buffer_length < length + 8) {
746 | bytes_to_read = buffer_length - used_buffer_length;
747 | if (bytes_to_read > INT_MAX2147483647)
748 | bytes_to_read = INT_MAX2147483647;
749 | result = recv(sock, buffer + used_buffer_length, (int)bytes_to_read, 0);
750 |
751 | if (result <= 0) {
752 | ws_warning("Broken socket connection while reading reply for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 752, __func__, "Broken socket connection while reading reply for <%s>" , adb_service); } } while (0);
753 | if (data_length)
754 | *data_length = 0;
755 | return NULL((void*)0);
756 | }
757 |
758 | used_buffer_length += result;
759 | }
760 |
761 | if (data_length)
762 | *data_length = used_buffer_length - 8;
763 |
764 | if (memcmp(status, "OKAY", 4)) {
765 | ws_warning("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 765, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
766 | if (data_length)
767 | *data_length = 0;
768 | return NULL((void*)0);
769 | }
770 |
771 | return buffer + 8;
772 | }
773 |
774 |
775 | static char *adb_send_and_read(socket_handle_tint sock, const char *adb_service, char *buffer,
776 | int buffer_length, ssize_t *data_length) {
777 | ssize_t used_buffer_length;
778 | ssize_t result;
779 | char status[4];
780 | size_t adb_service_length;
781 |
782 | adb_service_length = strlen(adb_service);
783 | snprintf(buffer, buffer_length, ADB_HEX4_FORMAT"%04zx", adb_service_length);
784 |
785 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
786 | if (result < ADB_HEX4_LEN4) {
787 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 787, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
788 | return NULL((void*)0);
789 | }
790 |
791 | result = send(sock, adb_service, (int) adb_service_length, 0);
792 | if (result != (ssize_t) adb_service_length) {
793 | ws_warning("Error while sending <%s> to ADB", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 793, __func__, "Error while sending <%s> to ADB", adb_service ); } } while (0);
794 | if (data_length)
795 | *data_length = 0;
796 | return NULL((void*)0);
797 | }
798 |
799 | used_buffer_length = 0;
800 | while (used_buffer_length < 4) {
801 | result = recv(sock, buffer + used_buffer_length, (int)(buffer_length - used_buffer_length), 0);
802 |
803 | if (result <= 0) {
804 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 804, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
805 |
806 | return NULL((void*)0);
807 | }
808 |
809 | used_buffer_length += result;
810 | }
811 |
812 | memcpy(status, buffer, 4);
813 |
814 | while (result > 0) {
815 | result= recv(sock, buffer + used_buffer_length, (int)(buffer_length - used_buffer_length), 0);
816 |
817 | if (result < 0) {
818 | ws_warning("Broken socket connection while reading reply for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 818, __func__, "Broken socket connection while reading reply for <%s>" , adb_service); } } while (0);
819 |
820 | return NULL((void*)0);
821 | } else if (result == 0) {
822 | break;
823 | }
824 |
825 | used_buffer_length += result;
826 | }
827 |
828 | if (data_length)
829 | *data_length = used_buffer_length - 4;
830 |
831 | if (memcmp(status, "OKAY", 4)) {
832 | ws_warning("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 832, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
833 | if (data_length)
834 | *data_length = 0;
835 | return NULL((void*)0);
836 | }
837 |
838 | return buffer + 4;
839 | }
840 |
841 |
842 | static int adb_send(socket_handle_tint sock, const char *adb_service) {
843 | char buffer[5];
844 | int used_buffer_length;
845 | ssize_t result;
846 | size_t adb_service_length;
847 |
848 | adb_service_length = strlen(adb_service);
849 | result = snprintf(buffer, sizeof(buffer), ADB_HEX4_FORMAT"%04zx", adb_service_length);
850 | if ((size_t)result >= sizeof(buffer)) {
851 | /* Truncation (or failure somehow) */
852 | ws_warning("Service name too long when sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 852, __func__, "Service name too long when sending <%s> to ADB daemon" , adb_service); } } while (0);
853 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
854 | }
855 |
856 | result = send(sock, buffer, ADB_HEX4_LEN4, 0);
857 | if (result < ADB_HEX4_LEN4) {
858 | ws_warning("Error while sending <%s> to ADB daemon", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 858, __func__, "Error while sending <%s> to ADB daemon" , adb_service); } } while (0);
859 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
860 | }
861 |
862 | result = send(sock, adb_service, (int) adb_service_length, 0);
863 | if (result != (ssize_t) adb_service_length) {
864 | ws_warning("Error while sending <%s> to ADB", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 864, __func__, "Error while sending <%s> to ADB", adb_service ); } } while (0);
865 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_1;
866 | }
867 |
868 | used_buffer_length = 0;
869 | while (used_buffer_length < 4) {
870 | result = recv(sock, buffer + used_buffer_length, 4 - used_buffer_length, 0);
871 |
872 | if (result <= 0) {
873 | ws_warning("Broken socket connection while fetching reply status for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 873, __func__, "Broken socket connection while fetching reply status for <%s>" , adb_service); } } while (0);
874 |
875 | return EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_STATUS;
876 | }
877 |
878 | used_buffer_length += (int)result;
879 | }
880 |
881 | if (memcmp(buffer, "OKAY", 4)) {
882 | ws_debug("Error while receiving by ADB for <%s>", adb_service)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 882, __func__, "Error while receiving by ADB for <%s>" , adb_service); } } while (0);
883 |
884 | return EXIT_CODE_ERROR_WHILE_RECEIVING_ADB_PACKET_DATA;
885 | }
886 |
887 | return EXIT_CODE_SUCCESS;
888 | }
889 |
890 |
891 | static socket_handle_tint
892 | adb_connect_transport(const char *server_ip, unsigned short *server_tcp_port,
893 | const char* serial_number)
894 | {
895 | static const char *const adb_transport_serial_templace = "host:transport:%s";
896 | static const char *const adb_transport_any = "host:transport-any";
897 | char transport_buf[80];
898 | const char* transport = transport_buf;
899 | socket_handle_tint sock;
900 | ssize_t result;
901 |
902 | sock = adb_connect(server_ip, server_tcp_port);
903 | if (sock == INVALID_SOCKET(-1)) {
904 | ws_warning("Error while connecting to adb server")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 904, __func__, "Error while connecting to adb server"); } } while (0);
905 | return sock;
906 | }
907 |
908 | if (!serial_number) {
909 | transport = adb_transport_any;
910 | } else {
911 | result = snprintf(transport_buf, sizeof(transport_buf), adb_transport_serial_templace, serial_number);
912 | if (result <= 0 || result > (int)sizeof(transport_buf)) {
913 | ws_warning("Error while completing adb packet for transport")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 913, __func__, "Error while completing adb packet for transport" ); } } while (0);
914 | closesocket(sock)close(sock);
915 | return INVALID_SOCKET(-1);
916 | }
917 | }
918 |
919 | result = adb_send(sock, transport);
920 | if (result) {
921 | ws_warning("Error while setting adb transport for <%s>", transport_buf)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 921, __func__, "Error while setting adb transport for <%s>" , transport_buf); } } while (0);
922 | closesocket(sock)close(sock);
923 | return INVALID_SOCKET(-1);
924 | }
925 | return sock;
926 | }
927 |
928 |
929 | static void new_interface(extcap_parameters * extcap_conf, const char *interface_id,
930 | const char *model_name, const char *serial_number, const char *display_name)
931 | {
932 | char *interface = ws_strdup_printf("%s-%s", interface_id, serial_number)wmem_strdup_printf(((void*)0), "%s-%s", interface_id, serial_number );
933 | char *ifdisplay = ws_strdup_printf("%s %s %s", display_name, model_name, serial_number)wmem_strdup_printf(((void*)0), "%s %s %s", display_name, model_name , serial_number);
934 |
935 | if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
936 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser") ||
937 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")) {
938 |
939 | extcap_base_register_interface_ext(extcap_conf, interface, ifdisplay, 99, "BluetoothH4", "Bluetooth HCI UART transport layer plus pseudo-header", EXTCAP_CONTROL_NONE0);
940 | } else if (is_logcat_interface(interface) || is_logcat_text_interface(interface)) {
941 | extcap_base_register_interface(extcap_conf, interface, ifdisplay, 252, "Upper PDU" );
942 | } else if (is_specified_interface(interface, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
943 | extcap_base_register_interface(extcap_conf, interface, ifdisplay, 1, "Ethernet");
944 | }
945 | g_free(interface)(__builtin_object_size ((interface), 0) != ((size_t) - 1)) ? g_free_sized (interface, __builtin_object_size ((interface), 0)) : (g_free ) (interface);
946 | g_free(ifdisplay)(__builtin_object_size ((ifdisplay), 0) != ((size_t) - 1)) ? g_free_sized (ifdisplay, __builtin_object_size ((ifdisplay), 0)) : (g_free ) (ifdisplay);
947 | }
948 |
949 |
950 | static void new_fake_interface_for_list_dlts(extcap_parameters * extcap_conf,
951 | const char *ifname)
952 | {
953 | if (is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
954 | is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser") ||
955 | is_specified_interface(ifname, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")) {
956 | extcap_base_register_interface_ext(extcap_conf, ifname, ifname, 99, "BluetoothH4", "Bluetooth HCI UART transport layer plus pseudo-header", EXTCAP_CONTROL_NONE0);
957 | } else if (is_logcat_interface(ifname) || is_logcat_text_interface(ifname)) {
958 | extcap_base_register_interface(extcap_conf, ifname, ifname, 252, "Upper PDU" );
959 | } else if (is_specified_interface(ifname, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
960 | extcap_base_register_interface(extcap_conf, ifname, ifname, 1, "Ethernet");
961 | }
962 | }
963 |
964 |
965 | static int add_tcpdump_interfaces(extcap_parameters * extcap_conf, const char *adb_server_ip, unsigned short *adb_server_tcp_port, const char *serial_number)
966 | {
967 | static const char *const adb_tcpdump_list = "shell:tcpdump -D";
968 | static const char *const regex_ifaces = "\\d+\\.(?<iface>\\S+)(\\s+?(?:(?:\\(.*\\))*)(\\s*?\\[(?<flags>.*?)\\])?)?";
969 | static char recv_buffer[PACKET_LENGTH65535];
970 | char *response;
971 | ssize_t data_length;
972 | socket_handle_tint sock;
973 | GRegex* regex = NULL((void*)0);
974 | GError *err = NULL((void*)0);
975 | GMatchInfo *match = NULL((void*)0);
976 | char* tok;
977 | char iface_name[80];
978 | bool_Bool flags_supported;
979 |
980 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
981 | if (sock == INVALID_SOCKET(-1)) {
982 | ws_warning("Failed to connect to adb server")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 982, __func__, "Failed to connect to adb server"); } } while (0);
983 | return EXIT_CODE_GENERIC;
984 | }
985 |
986 | response = adb_send_and_read(sock, adb_tcpdump_list, recv_buffer, sizeof(recv_buffer), &data_length);
987 | closesocket(sock)close(sock);
988 |
989 | if (!response) {
990 | ws_warning("Failed to get list of available tcpdump interfaces")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 990, __func__, "Failed to get list of available tcpdump interfaces" ); } } while (0);
991 | return EXIT_CODE_GENERIC;
992 | }
993 | response[data_length] = '\0';
994 |
995 | regex = g_regex_new(regex_ifaces, G_REGEX_RAW, (GRegexMatchFlags)0, &err);
996 | if (!regex) {
997 | ws_warning("Failed to compile regex for tcpdump interface matching")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 997, __func__, "Failed to compile regex for tcpdump interface matching" ); } } while (0);
998 | return EXIT_CODE_GENERIC;
999 | }
1000 |
1001 | flags_supported = (strstr(response, "[") != 0) && (strstr(response, "]") != 0);
1002 |
1003 | tok = strtok(response, "\n");
1004 | while (tok != NULL((void*)0)) {
1005 | g_regex_match(regex, tok, (GRegexMatchFlags)0, &match);
1006 | if (g_match_info_matches(match)) {
1007 | char *iface = g_match_info_fetch_named(match, "iface");
1008 | char *flags = g_match_info_fetch_named(match, "flags");
1009 |
1010 | if (!flags_supported || (flags && strstr(flags, "Up"))) {
1011 | snprintf(iface_name, sizeof(iface_name), INTERFACE_ANDROID_TCPDUMP_FORMAT"android-tcpdump" "-%s", iface);
1012 | new_interface(extcap_conf, iface_name, iface, serial_number, "Android tcpdump");
1013 | }
1014 | g_free(flags)(__builtin_object_size ((flags), 0) != ((size_t) - 1)) ? g_free_sized (flags, __builtin_object_size ((flags), 0)) : (g_free) (flags );
1015 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
1016 | }
1017 | g_match_info_free(match);
1018 | tok = strtok(NULL((void*)0), "\n");
1019 | }
1020 | g_regex_unref(regex);
1021 | return 0;
1022 | }
1023 |
1024 |
1025 | static int register_interfaces(extcap_parameters * extcap_conf, const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1026 | static char packet[PACKET_LENGTH65535];
1027 | static char helpful_packet[PACKET_LENGTH65535];
1028 | char check_port_buf[80];
1029 | char *response;
1030 | char *device_list;
1031 | ssize_t data_length;
1032 | size_t device_length;
1033 | socket_handle_tint sock;
1034 | const char *adb_check_port_templace = "shell:cat /proc/%s/net/tcp";
1035 | const char *adb_devices = "host:devices-l";
1036 | const char *adb_api_level = "shell:getprop ro.build.version.sdk";
1037 | const char *adb_hcidump_version = "shell:hcidump --version";
1038 | const char *adb_ps_droid_bluetooth = "shell:ps droid.bluetooth";
1039 | const char *adb_ps_bluetooth_app = "shell:ps com.android.bluetooth";
1040 | const char *adb_ps_with_grep = "shell:ps | grep com.android.bluetooth";
1041 | const char *adb_ps_all_with_grep = "shell:ps -A | grep com.*android.bluetooth";
1042 | char serial_number[SERIAL_NUMBER_LENGTH_MAX512];
1043 | char model_name[MODEL_NAME_LENGTH_MAX64];
1044 | int result;
1045 | char *pos;
1046 | char *i_pos;
1047 | char *model_pos;
1048 | char *device_pos;
1049 | char *prev_pos;
1050 | int api_level;
1051 | int disable_interface;
1052 |
1053 | /* NOTE: It seems that "adb devices" and "adb shell" closed connection
1054 | so cannot send next command after them, there is need to reconnect */
1055 |
1056 | sock = adb_connect(adb_server_ip, adb_server_tcp_port);
1057 | if (sock == INVALID_SOCKET(-1))
1058 | return EXIT_CODE_INVALID_SOCKET_INTERFACES_LIST;
1059 |
1060 | device_list = adb_send_and_receive(sock, adb_devices, packet, sizeof(packet), &device_length);
1061 | closesocket(sock)close(sock);
1062 |
1063 | if (!device_list) {
1064 | ws_warning("Cannot get list of interfaces from devices")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1064, __func__, "Cannot get list of interfaces from devices" ); } } while (0);
1065 |
1066 | return EXIT_CODE_CANNOT_GET_INTERFACES_LIST;
1067 | }
1068 |
1069 | device_list[device_length] = '\0';
1070 | pos = (char *) device_list;
1071 |
1072 | while (pos < (char *) (device_list + device_length)) {
1073 | prev_pos = pos;
1074 | pos = strchr(pos, ' ');
1075 | i_pos = pos;
1076 | result = (int) (pos - prev_pos);
1077 | pos = strchr(pos, '\n') + 1;
1078 | if (result >= (int) sizeof(serial_number)) {
1079 | ws_warning("Serial number too long, ignore device")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1079, __func__, "Serial number too long, ignore device"); } } while (0);
1080 | continue;
1081 | }
1082 | memcpy(serial_number, prev_pos, result);
1083 | serial_number[result] = '\0';
1084 |
1085 | model_name[0] = '\0';
1086 | model_pos = g_strstr_len(i_pos, pos - i_pos, "model:");
1087 | if (model_pos) {
1088 | device_pos = g_strstr_len(i_pos, pos - i_pos, "device:");
1089 | if (device_pos && device_pos - model_pos - 6 - 1 < MODEL_NAME_LENGTH_MAX64) {
1090 | memcpy(model_name, model_pos + 6, device_pos - model_pos - 6 - 1);
1091 | model_name[device_pos - model_pos - 6 - 1] = '\0';
1092 | }
1093 | }
1094 |
1095 | if (model_name[0] == '\0')
1096 | strcpy(model_name, "unknown");
1097 |
1098 | ws_debug("Processing device: \"%s\" <%s>" , serial_number, model_name)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1098, __func__, "Processing device: \"%s\" <%s>" , serial_number , model_name); } } while (0);
1099 |
1100 | /* Function will only add tcpdump interfaces if tcpdump is present on the device */
1101 | result = add_tcpdump_interfaces(extcap_conf, adb_server_ip, adb_server_tcp_port, serial_number );
1102 | if (result) {
1103 | ws_warning("Error while adding tcpdump interfaces")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1103, __func__, "Error while adding tcpdump interfaces"); } } while (0);
1104 | }
1105 |
1106 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1107 | if (sock == INVALID_SOCKET(-1)) continue;
1108 |
1109 | response = adb_send_and_read(sock, adb_api_level, helpful_packet, sizeof(helpful_packet), &data_length);
1110 | closesocket(sock)close(sock);
1111 |
1112 | if (!response) {
1113 | ws_warning("Error on socket: <%s>", helpful_packet)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1113, __func__, "Error on socket: <%s>", helpful_packet ); } } while (0);
1114 | continue;
1115 | }
1116 |
1117 | response[data_length] = '\0';
1118 | api_level = (int) g_ascii_strtoll(response, NULL((void*)0), 10);
1119 | ws_debug("Android API Level for %s is %i", serial_number, api_level)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1119, __func__, "Android API Level for %s is %i", serial_number , api_level); } } while (0);
1120 |
1121 | if (api_level < 21) {
1122 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main", model_name, serial_number, "Android Logcat Main");
1123 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system", model_name, serial_number, "Android Logcat System");
1124 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio", model_name, serial_number, "Android Logcat Radio");
1125 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events", model_name, serial_number, "Android Logcat Events");
1126 |
1127 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main", model_name, serial_number, "Android Logcat Main");
1128 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system", model_name, serial_number, "Android Logcat System");
1129 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio", model_name, serial_number, "Android Logcat Radio");
1130 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events", model_name, serial_number, "Android Logcat Events");
1131 | } else {
1132 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main", model_name, serial_number, "Android Logcat Main");
1133 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system", model_name, serial_number, "Android Logcat System");
1134 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio", model_name, serial_number, "Android Logcat Radio");
1135 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events", model_name, serial_number, "Android Logcat Events");
1136 | new_interface(extcap_conf, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash", model_name, serial_number, "Android Logcat Crash");
1137 | }
1138 |
1139 | if (api_level >= 5 && api_level < 17) {
1140 | disable_interface = 0;
1141 |
1142 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1143 | if (sock == INVALID_SOCKET(-1)) continue;
1144 |
1145 | response = adb_send_and_read(sock, adb_hcidump_version, helpful_packet, sizeof(helpful_packet), &data_length);
1146 | closesocket(sock)close(sock);
1147 |
1148 | if (!response || data_length < 1) {
1149 | ws_warning("Error while getting hcidump version by <%s> (%p len=%"PRIdMAX")",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1150, __func__, "Error while getting hcidump version by <%s> (%p len=%" "l" "d"")", adb_hcidump_version, (void*)response, (intmax_t)data_length ); } } while (0)
1150 | adb_hcidump_version, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1150, __func__, "Error while getting hcidump version by <%s> (%p len=%" "l" "d"")", adb_hcidump_version, (void*)response, (intmax_t)data_length ); } } while (0);
1151 | ws_debug("Android hcidump version for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1151, __func__, "Android hcidump version for %s is unknown" , serial_number); } } while (0);
1152 | disable_interface = 1;
1153 | } else {
1154 | response[data_length] = '\0';
1155 |
1156 | if (g_ascii_strtoull(response, NULL((void*)0), 10) == 0) {
1157 | ws_debug("Android hcidump version for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1157, __func__, "Android hcidump version for %s is unknown" , serial_number); } } while (0);
1158 | disable_interface = 1;
1159 | } else {
1160 | ws_debug("Android hcidump version for %s is %s", serial_number, response)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1160, __func__, "Android hcidump version for %s is %s", serial_number , response); } } while (0);
1161 | }
1162 | }
1163 |
1164 | if (!disable_interface) {
1165 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump", model_name, serial_number, "Android Bluetooth Hcidump");
1166 | }
1167 | }
1168 |
1169 | if (api_level >= 17 && api_level < 21) {
1170 | disable_interface = 0;
1171 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1172 | if (sock == INVALID_SOCKET(-1)) continue;
1173 |
1174 | response = adb_send_and_read(sock, adb_ps_droid_bluetooth, helpful_packet, sizeof(helpful_packet), &data_length);
1175 | closesocket(sock)close(sock);
1176 | if (!response || data_length < 1) {
1177 | ws_warning("Error while getting Bluetooth application process id by <%s> "do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1178, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", adb_ps_droid_bluetooth, (void*)response , (intmax_t)data_length); } } while (0)
1178 | "(%p len=%"PRIdMAX")", adb_ps_droid_bluetooth, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1178, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", adb_ps_droid_bluetooth, (void*)response , (intmax_t)data_length); } } while (0);
1179 | ws_debug( "Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1179, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1180 | disable_interface = 1;
1181 | } else {
1182 | char *data_str;
1183 | char pid[16];
1184 |
1185 | memset(pid, 0, sizeof(pid));
1186 | response[data_length] = '\0';
1187 |
1188 | data_str = strchr(response, '\n');
1189 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1) {
1190 | ws_debug("Android Bluetooth application PID for %s is %s", serial_number, pid)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1190, __func__, "Android Bluetooth application PID for %s is %s" , serial_number, pid); } } while (0);
1191 |
1192 | result = snprintf(check_port_buf, sizeof(check_port_buf), adb_check_port_templace, pid);
1193 | if (result <= 0 || result > (int)sizeof(check_port_buf)) {
1194 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1194, __func__, "Error while completing adb packet"); } } while (0);
1195 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_6;
1196 | }
1197 |
1198 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1199 | if (sock == INVALID_SOCKET(-1)) continue;
1200 |
1201 | response = adb_send_and_read(sock, check_port_buf, helpful_packet, sizeof(helpful_packet), &data_length);
1202 | closesocket(sock)close(sock);
1203 |
1204 | if (!response) {
1205 | disable_interface = 1;
1206 | } else {
1207 | response[data_length] = '\0';
1208 |
1209 | data_str = strchr(response, '\n');
1210 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1 && strlen(pid) > 10 && strcmp(pid + 9, "10EA") == 0) {
1211 | ws_debug("Bluedroid External Parser Port for %s is %s", serial_number, pid + 9)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1211, __func__, "Bluedroid External Parser Port for %s is %s" , serial_number, pid + 9); } } while (0);
1212 | } else {
1213 | disable_interface = 1;
1214 | ws_debug("Bluedroid External Parser Port for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1214, __func__, "Bluedroid External Parser Port for %s is unknown" , serial_number); } } while (0);
1215 | }
1216 | }
1217 | } else {
1218 | disable_interface = 1;
1219 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1219, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1220 | }
1221 | }
1222 |
1223 | if (!disable_interface) {
1224 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser", model_name, serial_number, "Android Bluetooth External Parser");
1225 | }
1226 | }
1227 |
1228 | if (api_level >= 21) {
1229 | const char* ps_cmd;
1230 | disable_interface = 0;
1231 |
1232 | if (api_level >= 26) {
1233 | ps_cmd = adb_ps_all_with_grep;
1234 | } else if (api_level >= 24) {
1235 | ps_cmd = adb_ps_with_grep;
1236 | } else if (api_level >= 23) {
1237 | ps_cmd = adb_ps_bluetooth_app;
1238 | } else {
1239 | ps_cmd = adb_ps_droid_bluetooth;
1240 | }
1241 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1242 | if (sock == INVALID_SOCKET(-1)) continue;
1243 |
1244 | response = adb_send_and_read(sock, ps_cmd, helpful_packet, sizeof(helpful_packet), &data_length);
1245 | closesocket(sock)close(sock);
1246 |
1247 | if (!response || data_length < 1) {
1248 | ws_warning("Error while getting Bluetooth application process id by <%s> "do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1249, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", ps_cmd, (void*)response, (intmax_t)data_length ); } } while (0)
1249 | "(%p len=%"PRIdMAX")", ps_cmd, (void*)response, (intmax_t)data_length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1249, __func__, "Error while getting Bluetooth application process id by <%s> " "(%p len=%""l" "d"")", ps_cmd, (void*)response, (intmax_t)data_length ); } } while (0);
1250 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1250, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1251 | disable_interface = 1;
1252 | } else {
1253 | char *data_str;
1254 | char pid[16];
1255 |
1256 | memset(pid, 0, sizeof(pid));
1257 | response[data_length] = '\0';
1258 |
1259 | if (api_level >= 24)
1260 | data_str = response;
1261 | else
1262 | data_str = strchr(response, '\n');
1263 |
1264 | if (data_str && sscanf(data_str, "%*s %15s", pid) == 1) {
1265 | ws_debug("Android Bluetooth application PID for %s is %s", serial_number, pid)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1265, __func__, "Android Bluetooth application PID for %s is %s" , serial_number, pid); } } while (0);
1266 |
1267 | result = snprintf(check_port_buf, sizeof(check_port_buf), adb_check_port_templace, pid);
1268 | if (result <= 0 || result > (int)sizeof(check_port_buf)) {
1269 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1269, __func__, "Error while completing adb packet"); } } while (0);
1270 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_9;
1271 | }
1272 |
1273 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1274 | if (sock == INVALID_SOCKET(-1)) continue;
1275 |
1276 | response = adb_send_and_read(sock, check_port_buf, helpful_packet, sizeof(helpful_packet), &data_length);
1277 | closesocket(sock)close(sock);
1278 |
1279 | if (!response) {
1280 | disable_interface = 1;
1281 | } else {
1282 | response[data_length] = '\0';
1283 | data_str = strtok(response, "\n");
1284 | while (data_str != NULL((void*)0)) {
1285 | if (sscanf(data_str, "%*s %15s", pid) == 1 && strlen(pid) > 10 && strcmp(pid + 9, "22A8") == 0) {
1286 | ws_debug("Btsnoop Net Port for %s is %s", serial_number, pid + 9)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1286, __func__, "Btsnoop Net Port for %s is %s", serial_number , pid + 9); } } while (0);
1287 | break;
1288 | }
1289 | data_str = strtok(NULL((void*)0), "\n");
1290 | }
1291 | if (data_str == NULL((void*)0)) {
1292 | disable_interface = 1;
1293 | ws_debug("Btsnoop Net Port for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1293, __func__, "Btsnoop Net Port for %s is unknown", serial_number ); } } while (0);
1294 | }
1295 | }
1296 | } else {
1297 | disable_interface = 1;
1298 | ws_debug("Android Bluetooth application PID for %s is unknown", serial_number)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1298, __func__, "Android Bluetooth application PID for %s is unknown" , serial_number); } } while (0);
1299 | }
1300 | }
1301 |
1302 | if (!disable_interface) {
1303 | new_interface(extcap_conf, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net", model_name, serial_number, "Android Bluetooth Btsnoop Net");
1304 | }
1305 | }
1306 | }
1307 |
1308 | return EXIT_CODE_SUCCESS;
1309 | }
1310 |
1311 | static int list_config(char *interface) {
1312 | int ret = EXIT_CODE_INVALID_INTERFACE;
1313 | unsigned inc = 0;
1314 |
1315 | if (!interface) {
1316 | ws_warning("No interface specified.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1316, __func__, "No interface specified."); } } while (0);
1317 | return EXIT_CODE_NO_INTERFACE_SPECIFIED;
1318 | }
1319 |
1320 | if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser")) {
1321 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1322 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1323 | printf("arg {number=%u}{call=--bt-server-tcp-port}{display=Bluetooth Server TCP Port}{type=integer}{range=0,65535}{default=4330}\n", inc++);
1324 | printf("arg {number=%u}{call=--bt-forward-socket}{display=Forward Bluetooth Socket}{type=boolean}{default=false}\n", inc++);
1325 | printf("arg {number=%u}{call=--bt-local-ip}{display=Bluetooth Local IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1326 | printf("arg {number=%u}{call=--bt-local-tcp-port}{display=Bluetooth Local TCP Port}{type=integer}{range=0,65535}{default=4330}{tooltip=Used to do \"adb forward tcp:LOCAL_TCP_PORT tcp:SERVER_TCP_PORT\"}\n", inc++);
1327 | ret = EXIT_CODE_SUCCESS;
1328 | } else if (is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump") ||
1329 | is_specified_interface(interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net") ||
1330 | is_specified_interface(interface, INTERFACE_ANDROID_TCPDUMP"android-tcpdump")) {
1331 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1332 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1333 | ret = EXIT_CODE_SUCCESS;
1334 | } else if (is_logcat_interface(interface)) {
1335 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1336 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1337 | printf("arg {number=%u}{call=--logcat-text}{display=Use text logcat}{type=boolean}{default=false}\n", inc++);
1338 | printf("arg {number=%u}{call=--logcat-ignore-log-buffer}{display=Ignore log buffer}{type=boolean}{default=false}\n", inc++);
1339 | printf("arg {number=%u}{call=--logcat-custom-options}{display=Custom logcat parameters}{type=string}\n", inc++);
1340 | ret = EXIT_CODE_SUCCESS;
1341 | } else if (is_logcat_text_interface(interface)) {
1342 | printf("arg {number=%u}{call=--adb-server-ip}{display=ADB Server IP Address}{type=string}{default=127.0.0.1}\n", inc++);
1343 | printf("arg {number=%u}{call=--adb-server-tcp-port}{display=ADB Server TCP Port}{type=integer}{range=0,65535}{default=5037}\n", inc++);
1344 | printf("arg {number=%u}{call=--logcat-ignore-log-buffer}{display=Ignore log buffer}{type=boolean}{default=false}\n", inc++);
1345 | printf("arg {number=%u}{call=--logcat-custom-options}{display=Custom logcat parameters}{type=string}\n", inc++);
1346 | ret = EXIT_CODE_SUCCESS;
1347 | }
1348 |
1349 | if (ret != EXIT_CODE_SUCCESS)
1350 | ws_warning("Invalid interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1350, __func__, "Invalid interface: <%s>", interface) ; } } while (0);
1351 | else
1352 | extcap_config_debug(&inc);
1353 |
1354 | return ret;
1355 | }
1356 |
1357 | /*----------------------------------------------------------------------------*/
1358 | /* Android Bluetooth Hcidump */
1359 | /*----------------------------------------------------------------------------*/
1360 |
1361 | static int capture_android_bluetooth_hcidump(char *interface, char *fifo,
1362 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1363 | struct extcap_dumper extcap_dumper;
1364 | static char data[PACKET_LENGTH65535];
1365 | static char packet[PACKET_LENGTH65535];
1366 | ssize_t length;
1367 | ssize_t used_buffer_length = 0;
1368 | socket_handle_tint sock = INVALID_SOCKET(-1);
1369 | const char *adb_shell_hcidump = "shell:hcidump -R -t";
1370 | const char *adb_shell_su_hcidump = "shell:su -c hcidump -R -t";
1371 | int result;
1372 | char *serial_number;
1373 | time_t ts = 0;
1374 | unsigned int captured_length;
1375 | int64_t hex;
1376 | char *hex_data;
1377 | char *new_hex_data;
1378 | own_pcap_bluetooth_h4_header *h4_header;
1379 | int64_t raw_length = 0;
1380 | int64_t frame_length;
1381 | int ms = 0;
1382 | struct tm date;
1383 | char direction_character;
1384 |
1385 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, packet){ data_aligned_t data_aligned; data_aligned.value_char = packet ; h4_header = data_aligned.value_own_pcap_bluetooth_h4_header ; };
1386 |
1387 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1388 |
1389 | serial_number = get_serial_from_interface(interface);
1390 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1391 | if (sock == INVALID_SOCKET(-1))
1392 | return EXIT_CODE_INVALID_SOCKET_3;
1393 |
1394 | result = adb_send(sock, adb_shell_hcidump);
1395 | if (result) {
1396 | ws_warning("Error while starting capture by sending command: %s", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1396, __func__, "Error while starting capture by sending command: %s" , adb_shell_hcidump); } } while (0);
1397 | closesocket(sock)close(sock);
1398 | return EXIT_CODE_GENERIC;
1399 | }
1400 |
1401 | while (endless_loop) {
1402 | char *i_position;
1403 |
1404 | errno(*__errno_location ()) = 0;
1405 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1406 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1407 | else if (errno(*__errno_location ()) != 0) {
1408 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1408, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1409 | closesocket(sock)close(sock);
1410 | return EXIT_CODE_GENERIC;
1411 | }
1412 |
1413 | if (length <= 0) {
1414 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1414, __func__, "Broken socket connection."); } } while (0);
1415 | closesocket(sock)close(sock);
1416 | return EXIT_CODE_GENERIC;
1417 | }
1418 |
1419 | used_buffer_length += length;
1420 | i_position = (char *) memchr(data, '\n', used_buffer_length);
1421 | if (i_position && i_position < data + used_buffer_length) {
1422 | char *state_line_position = i_position + 1;
1423 |
1424 | if (!strncmp(data, "/system/bin/sh: hcidump: not found", 34)) {
1425 | ws_warning("Command not found for <%s>", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1425, __func__, "Command not found for <%s>", adb_shell_hcidump ); } } while (0);
1426 | closesocket(sock)close(sock);
1427 | return EXIT_CODE_GENERIC;
1428 | }
1429 |
1430 | i_position = (char *) memchr(i_position + 1, '\n', used_buffer_length);
1431 | if (i_position) {
1432 | i_position += 1;
1433 | if (!strncmp(state_line_position, "Can't access device: Permission denied", 38)) {
1434 | ws_warning("No permission for command <%s>", adb_shell_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1434, __func__, "No permission for command <%s>", adb_shell_hcidump ); } } while (0);
1435 | used_buffer_length = 0;
1436 | closesocket(sock)close(sock);
1437 | sock = INVALID_SOCKET(-1);
1438 | break;
1439 | }
1440 | memmove(data, i_position, used_buffer_length - (i_position - data));
1441 | used_buffer_length = used_buffer_length - (ssize_t)(i_position - data);
1442 | break;
1443 | }
1444 | }
1445 | }
1446 |
1447 | if (sock == INVALID_SOCKET(-1)) {
1448 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1449 | if (sock == INVALID_SOCKET(-1))
1450 | return EXIT_CODE_INVALID_SOCKET_4;
1451 |
1452 | result = adb_send(sock, adb_shell_su_hcidump);
1453 | if (result) {
1454 | ws_warning("Error while starting capture by sending command: <%s>", adb_shell_su_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1454, __func__, "Error while starting capture by sending command: <%s>" , adb_shell_su_hcidump); } } while (0);
1455 | closesocket(sock)close(sock);
1456 | return EXIT_CODE_GENERIC;
1457 | }
1458 |
1459 | used_buffer_length = 0;
1460 | while (endless_loop) {
1461 | char *i_position;
1462 |
1463 | errno(*__errno_location ()) = 0;
1464 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1465 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1466 | else if (errno(*__errno_location ()) != 0) {
1467 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1467, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1468 | closesocket(sock)close(sock);
1469 | return EXIT_CODE_GENERIC;
1470 | }
1471 |
1472 | if (length <= 0) {
1473 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1473, __func__, "Broken socket connection."); } } while (0);
1474 | closesocket(sock)close(sock);
1475 | return EXIT_CODE_GENERIC;
1476 | }
1477 |
1478 | used_buffer_length += length;
1479 | i_position = (char *) memchr(data, '\n', used_buffer_length);
1480 | if (i_position && i_position < data + used_buffer_length) {
1481 | if (!strncmp(data, "/system/bin/sh: su: not found", 29)) {
1482 | ws_warning("Command 'su' not found for <%s>", adb_shell_su_hcidump)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1482, __func__, "Command 'su' not found for <%s>", adb_shell_su_hcidump ); } } while (0);
1483 | closesocket(sock)close(sock);
1484 | return EXIT_CODE_GENERIC;
1485 | }
1486 |
1487 | i_position = (char *) memchr(i_position + 1, '\n', used_buffer_length);
1488 | if (i_position) {
1489 | i_position += 1;
1490 | memmove(data, i_position, used_buffer_length - (i_position - data));
1491 | used_buffer_length = used_buffer_length - (ssize_t)(i_position - data);
1492 | break;
1493 | }
1494 | }
1495 | }
1496 | }
1497 |
1498 | while (endless_loop) {
1499 | errno(*__errno_location ()) = 0;
1500 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1501 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1502 | else if (errno(*__errno_location ()) != 0) {
1503 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1503, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1504 | closesocket(sock)close(sock);
1505 | return EXIT_CODE_GENERIC;
1506 | }
1507 |
1508 | if (length <= 0) {
1509 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1509, __func__, "Broken socket connection."); } } while (0);
1510 | closesocket(sock)close(sock);
1511 | return EXIT_CODE_GENERIC;
1512 | }
1513 |
1514 | while (endless_loop) {
1515 | if (used_buffer_length + length >= 1) {
1516 | hex_data = data + 29;
1517 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1518 |
1519 | if ((hex == 0x01 && used_buffer_length + length >= 4) ||
1520 | (hex == 0x02 && used_buffer_length + length >= 5) ||
1521 | (hex == 0x04 && used_buffer_length + length >= 3)) {
1522 |
1523 | if (hex == 0x01) {
1524 | hex_data = new_hex_data;
1525 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1526 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1527 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1527, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1528 | closesocket(sock)close(sock);
1529 | return EXIT_CODE_GENERIC;
1530 | }
1531 |
1532 | hex_data = new_hex_data;
1533 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1534 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1535 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1535, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1536 | closesocket(sock)close(sock);
1537 | return EXIT_CODE_GENERIC;
1538 | }
1539 |
1540 | hex_data = new_hex_data;
1541 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1542 |
1543 | raw_length = hex + 4;
1544 | } else if (hex == 0x04) {
1545 | hex_data = new_hex_data;
1546 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1547 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1548 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1548, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1549 | closesocket(sock)close(sock);
1550 | return EXIT_CODE_GENERIC;
1551 | }
1552 |
1553 | hex_data = new_hex_data;
1554 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1555 |
1556 | raw_length = hex + 3;
1557 | } else if (hex == 0x02) {
1558 | hex_data = new_hex_data;
1559 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1560 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1561 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1561, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1562 | closesocket(sock)close(sock);
1563 | return EXIT_CODE_GENERIC;
1564 | }
1565 |
1566 | hex_data = new_hex_data;
1567 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1568 | if (hex < 0 || hex >= 256 || hex_data == new_hex_data) {
1569 | ws_warning("data format %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1569, __func__, "data format %s", strerror((*__errno_location ()))); } } while (0);
1570 | closesocket(sock)close(sock);
1571 | return EXIT_CODE_GENERIC;
1572 | }
1573 |
1574 | hex_data = new_hex_data;
1575 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1576 | raw_length = hex + 5;
1577 |
1578 | hex_data = new_hex_data;
1579 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1580 | raw_length += hex << 8;
1581 | }
1582 |
1583 | } else {
1584 | ws_warning("bad raw stream")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1584, __func__, "bad raw stream"); } } while (0);
1585 | closesocket(sock)close(sock);
1586 | return EXIT_CODE_GENERIC;
1587 | }
1588 | } else {
1589 | used_buffer_length += length;
1590 | break;
1591 | }
1592 |
1593 | frame_length = raw_length * 3 + (raw_length / 20) * 4 + ((raw_length % 20) ? 2 : -2) + 29;
1594 |
1595 | if ((used_buffer_length + length) < frame_length) {
1596 | used_buffer_length += length;
1597 | break;
1598 | }
1599 |
1600 | if (8 == sscanf(data, "%04d-%02d-%02d %02d:%02d:%02d.%06d %c",
1601 | &date.tm_year, &date.tm_mon, &date.tm_mday, &date.tm_hour,
1602 | &date.tm_min, &date.tm_sec, &ms, &direction_character)) {
1603 |
1604 | ws_debug("time %04d-%02d-%02d %02d:%02d:%02d.%06d %c",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1606, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0)
1605 | date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour,do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1606, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0)
1606 | date.tm_min, date.tm_sec, ms, direction_character)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1606, __func__, "time %04d-%02d-%02d %02d:%02d:%02d.%06d %c" , date.tm_year, date.tm_mon, date.tm_mday, date.tm_hour, date .tm_min, date.tm_sec, ms, direction_character); } } while (0);
1607 | date.tm_mon -= 1;
1608 | date.tm_year -= 1900;
1609 | date.tm_isdst = -1;
1610 | ts = mktime(&date);
1611 |
1612 | new_hex_data = data + 29;
1613 | }
1614 |
1615 | captured_length = 0;
1616 |
1617 | while ((long)(new_hex_data - data + sizeof(own_pcap_bluetooth_h4_header)) < frame_length) {
1618 | hex_data = new_hex_data;
1619 | hex = g_ascii_strtoll(hex_data, &new_hex_data, 16);
1620 |
1621 | packet[sizeof(own_pcap_bluetooth_h4_header) + captured_length] = (char) hex;
1622 | captured_length += 1;
1623 | }
1624 |
1625 | h4_header->direction = GINT32_TO_BE(direction_character == '>')((gint32) (((guint32) ( (((guint32) (direction_character == '>' ) & (guint32) 0x000000ffU) << 24) | (((guint32) (direction_character == '>') & (guint32) 0x0000ff00U) << 8) | (((guint32 ) (direction_character == '>') & (guint32) 0x00ff0000U ) >> 8) | (((guint32) (direction_character == '>') & (guint32) 0xff000000U) >> 24)))));
1626 |
1627 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
1628 | captured_length + sizeof(own_pcap_bluetooth_h4_header),
1629 | captured_length + sizeof(own_pcap_bluetooth_h4_header),
1630 | ts,
1631 | ms * 1000);
1632 |
1633 | memmove(data, data + frame_length, (size_t)(used_buffer_length + length - frame_length));
1634 | used_buffer_length = (ssize_t)(used_buffer_length + length - frame_length);
1635 | length = 0;
1636 | }
1637 | }
1638 |
1639 | closesocket(sock)close(sock);
1640 | return EXIT_CODE_SUCCESS;
1641 | }
1642 |
1643 | /*----------------------------------------------------------------------------*/
1644 | /* Android Bluetooth External Parser */
1645 | /*----------------------------------------------------------------------------*/
1646 |
1647 | #define BLUEDROID_H4_PACKET_TYPE0 0
1648 | #define BLUEDROID_TIMESTAMP_SIZE8 8
1649 | #define BLUEDROID_H4_SIZE1 1
1650 |
1651 | static const uint64_t BLUEDROID_TIMESTAMP_BASE = UINT64_C(0x00dcddb30f2f8000)0x00dcddb30f2f8000UL;
1652 |
1653 | #define BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01 0x01
1654 | #define BLUEDROID_H4_PACKET_TYPE_ACL0x02 0x02
1655 | #define BLUEDROID_H4_PACKET_TYPE_SCO0x03 0x03
1656 | #define BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04 0x04
1657 |
1658 | #define BLUEDROID_DIRECTION_SENT0 0
1659 | #define BLUEDROID_DIRECTION_RECV1 1
1660 |
1661 | static int adb_forward(char *serial_number, const char *adb_server_ip, unsigned short *adb_server_tcp_port,
1662 | unsigned short local_tcp_port, unsigned short server_tcp_port) {
1663 | socket_handle_tint sock;
1664 | int result;
1665 | static char helpful_packet[PACKET_LENGTH65535];
1666 | static const char *adb_forward_template = "%s%s:forward:tcp:%05u;tcp:%05u";
1667 |
1668 | sock = adb_connect(adb_server_ip, adb_server_tcp_port);
1669 | if (sock == INVALID_SOCKET(-1))
1670 | return EXIT_CODE_INVALID_SOCKET_5;
1671 |
1672 | result = snprintf(helpful_packet, PACKET_LENGTH65535, adb_forward_template, (serial_number) ? "host-serial:" : "host", (serial_number) ? serial_number: "", local_tcp_port, server_tcp_port);
1673 | if (result <= 0 || result > PACKET_LENGTH65535) {
1674 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1674, __func__, "Error while completing adb packet"); } } while (0);
1675 | closesocket(sock)close(sock);
1676 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_12;
1677 | }
1678 |
1679 | result = adb_send(sock, helpful_packet);
1680 | closesocket(sock)close(sock);
1681 |
1682 | return result;
1683 | }
1684 |
1685 | static int capture_android_bluetooth_external_parser(char *interface,
1686 | char *fifo, const char *adb_server_ip, unsigned short *adb_server_tcp_port,
1687 | unsigned short *bt_server_tcp_port, unsigned int bt_forward_socket, const char *bt_local_ip,
1688 | unsigned short *bt_local_tcp_port) {
1689 | struct extcap_dumper extcap_dumper;
1690 | static char buffer[PACKET_LENGTH65535];
1691 | uint64_t *timestamp;
1692 | char *packet = buffer + BLUEDROID_TIMESTAMP_SIZE8 - sizeof(own_pcap_bluetooth_h4_header); /* skip timestamp (8 bytes) and reuse its space for header */
1693 | own_pcap_bluetooth_h4_header *h4_header;
1694 | uint8_t *payload = (uint8_t*)(packet + sizeof(own_pcap_bluetooth_h4_header));
1695 | const char *adb_tcp_bluedroid_external_parser_template = "tcp:%05u";
1696 | socklen_t slen;
1697 | ssize_t length;
1698 | ssize_t used_buffer_length = 0;
1699 | uint64_t ts;
1700 | socket_handle_tint sock;
1701 | struct sockaddr_in server;
1702 | int captured_length;
1703 | char *serial_number;
1704 | static unsigned int id = 1;
1705 | struct sockaddr_in client;
1706 |
1707 | SET_DATA(timestamp, value_u64, buffer){ data_aligned_t data_aligned; data_aligned.value_char = buffer ; timestamp = data_aligned.value_u64; };
1708 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, packet){ data_aligned_t data_aligned; data_aligned.value_char = packet ; h4_header = data_aligned.value_own_pcap_bluetooth_h4_header ; };
1709 |
1710 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1711 | serial_number = get_serial_from_interface(interface);
1712 |
1713 | if (bt_forward_socket) {
1714 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
1715 | ws_warning("Cannot open system TCP socket: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1715, __func__, "Cannot open system TCP socket: %s", strerror ((*__errno_location ()))); } } while (0);
1716 | return EXIT_CODE_GENERIC;
1717 | }
1718 |
1719 | ws_debug("Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1720, __func__, "Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u" , *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port); } } while (0)
1720 | *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1720, __func__, "Using config: Server TCP Port=%u, Local IP=%s, Local TCP Port=%u" , *bt_server_tcp_port, bt_local_ip, *bt_local_tcp_port); } } while (0);
1721 |
1722 | if (*bt_local_tcp_port != 0) {
1723 | int result;
1724 |
1725 | result = adb_forward(serial_number, adb_server_ip, adb_server_tcp_port, *bt_local_tcp_port, *bt_server_tcp_port);
1726 | ws_debug("DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1727, __func__, "DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i" , *bt_local_tcp_port, *bt_server_tcp_port, result); } } while (0)
1727 | *bt_local_tcp_port, *bt_server_tcp_port, result)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1727, __func__, "DO: adb forward tcp:%u (local) tcp:%u (remote) result=%i" , *bt_local_tcp_port, *bt_server_tcp_port, result); } } while (0);
1728 | }
1729 |
1730 | memset(&server, 0 , sizeof(server));
1731 | server.sin_family = AF_INET2;
1732 | server.sin_port = GINT16_TO_BE(*bt_local_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*bt_local_tcp_port ) >> 8) | (guint16) ((guint16) (*bt_local_tcp_port) << 8)))));
1733 | ws_inet_pton4(bt_local_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
1734 |
1735 | useSndTimeout(sock);
1736 |
1737 | if (connect(sock, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR(-1)) {
1738 | ws_warning("<%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1738, __func__, "<%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
1739 | closesocket(sock)close(sock);
1740 | return EXIT_CODE_GENERIC;
1741 | }
1742 |
1743 | slen = (socklen_t)sizeof(client);
1744 | if (getsockname(sock, (struct sockaddr *) &client, &slen)) {
1745 | ws_warning("getsockname: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1745, __func__, "getsockname: %s", strerror((*__errno_location ()))); } } while (0);
1746 | closesocket(sock)close(sock);
1747 | return EXIT_CODE_GENERIC;
1748 | }
1749 |
1750 | if (slen != sizeof(client)) {
1751 | ws_warning("incorrect length")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1751, __func__, "incorrect length"); } } while (0);
1752 | closesocket(sock)close(sock);
1753 | return EXIT_CODE_GENERIC;
1754 | }
1755 |
1756 | ws_debug("Client port %u", GUINT16_FROM_BE(client.sin_port))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1756, __func__, "Client port %u", (((((guint16) ( (guint16) ((guint16) (client.sin_port) >> 8) | (guint16) ((guint16 ) (client.sin_port) << 8))))))); } } while (0);
1757 | } else {
1758 | int result;
1759 |
1760 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1761 | if (sock == INVALID_SOCKET(-1))
1762 | return EXIT_CODE_INVALID_SOCKET_6;
1763 |
1764 | result = snprintf((char *) buffer, PACKET_LENGTH65535, adb_tcp_bluedroid_external_parser_template, *bt_server_tcp_port);
1765 | if (result <= 0 || result > PACKET_LENGTH65535) {
1766 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1766, __func__, "Error while completing adb packet"); } } while (0);
1767 | closesocket(sock)close(sock);
1768 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_14;
1769 | }
1770 |
1771 | result = adb_send(sock, buffer);
1772 | if (result) {
1773 | ws_warning("Error while forwarding adb port")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1773, __func__, "Error while forwarding adb port"); } } while (0);
1774 | closesocket(sock)close(sock);
1775 | return EXIT_CODE_GENERIC;
1776 | }
1777 | }
1778 |
1779 | while (endless_loop) {
1780 | errno(*__errno_location ()) = 0;
1781 | length = recv(sock, buffer + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
1782 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
1783 | else if (errno(*__errno_location ()) != 0) {
1784 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1784, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1785 | closesocket(sock)close(sock);
1786 | return EXIT_CODE_GENERIC;
1787 | }
1788 |
1789 | if (length <= 0) {
1790 | if (bt_forward_socket) {
1791 | /* NOTE: Workaround... It seems that Bluedroid is slower and we can connect to socket that are not really ready... */
1792 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1792, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
1793 | closesocket(sock)close(sock);
1794 |
1795 | if ((sock = socket(AF_INET2, SOCK_STREAMSOCK_STREAM, IPPROTO_TCPIPPROTO_TCP)) == INVALID_SOCKET(-1)) {
1796 | ws_warning("%s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1796, __func__, "%s", strerror((*__errno_location ()))); } } while (0);
1797 | return EXIT_CODE_GENERIC;
1798 | }
1799 |
1800 | server.sin_family = AF_INET2;
1801 | server.sin_port = GINT16_TO_BE(*bt_local_tcp_port)((gint16) (((guint16) ( (guint16) ((guint16) (*bt_local_tcp_port ) >> 8) | (guint16) ((guint16) (*bt_local_tcp_port) << 8)))));
1802 | ws_inet_pton4(bt_local_ip, (ws_in4_addr *)&(server.sin_addr.s_addr));
1803 |
1804 | useSndTimeout(sock);
1805 |
1806 | if (connect(sock, (struct sockaddr *) &server, sizeof(server)) == SOCKET_ERROR(-1)) {
1807 | ws_warning("ERROR reconnect: <%s> Please check that adb daemon is running.", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1807, __func__, "ERROR reconnect: <%s> Please check that adb daemon is running." , strerror((*__errno_location ()))); } } while (0);
1808 | closesocket(sock)close(sock);
1809 | return EXIT_CODE_GENERIC;
1810 | }
1811 | } else {
1812 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1812, __func__, "Broken socket connection."); } } while (0);
1813 | closesocket(sock)close(sock);
1814 | return EXIT_CODE_GENERIC;
1815 | }
1816 |
1817 | continue;
1818 | }
1819 |
1820 | used_buffer_length += length;
1821 |
1822 | ws_debug("Received: length=%"PRIdMAX, (intmax_t)length)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1822, __func__, "Received: length=%""l" "d", (intmax_t)length ); } } while (0);
1823 |
1824 | while (((payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01 || payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_SCO0x03) &&
1825 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 1 &&
1826 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + 1 <= used_buffer_length) ||
1827 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_ACL0x02 &&
1828 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 2 &&
1829 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + (payload[BLUEDROID_H4_SIZE1 + 2 + 1] << 8) + 2 <= used_buffer_length) ||
1830 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_SCO0x03 &&
1831 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + 1 &&
1832 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 2 + payload[BLUEDROID_H4_SIZE1 + 2] + 1 <= used_buffer_length) ||
1833 | (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04 &&
1834 | used_buffer_length >= BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 1 + 1 &&
1835 | BLUEDROID_TIMESTAMP_SIZE8 + BLUEDROID_H4_SIZE1 + 1 + payload[BLUEDROID_H4_SIZE1 + 1] + 1 <= used_buffer_length)) {
1836 |
1837 | ts = GINT64_FROM_BE(*timestamp)(((gint64) (((guint64) ( (((guint64) (*timestamp) & (guint64 ) (0x00000000000000ffUL)) << 56) | (((guint64) (*timestamp ) & (guint64) (0x000000000000ff00UL)) << 40) | (((guint64 ) (*timestamp) & (guint64) (0x0000000000ff0000UL)) << 24) | (((guint64) (*timestamp) & (guint64) (0x00000000ff000000UL )) << 8) | (((guint64) (*timestamp) & (guint64) (0x000000ff00000000UL )) >> 8) | (((guint64) (*timestamp) & (guint64) (0x0000ff0000000000UL )) >> 24) | (((guint64) (*timestamp) & (guint64) (0x00ff000000000000UL )) >> 40) | (((guint64) (*timestamp) & (guint64) (0xff00000000000000UL )) >> 56))))));
1838 |
1839 | switch (payload[BLUEDROID_H4_PACKET_TYPE0]) {
1840 | case BLUEDROID_H4_PACKET_TYPE_HCI_CMD0x01:
1841 | h4_header->direction = GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1842 |
1843 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + 4;
1844 |
1845 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 1 + payload[3];
1846 |
1847 | break;
1848 | case BLUEDROID_H4_PACKET_TYPE_ACL0x02:
1849 | h4_header->direction = (payload[2] & 0x80) ? GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 ))))) : GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1850 |
1851 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + (payload[3 + 1] << 8) + 5;
1852 |
1853 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 2 + payload[3] + (ssize_t)(payload[3 + 1] << 8);
1854 |
1855 | break;
1856 | case BLUEDROID_H4_PACKET_TYPE_SCO0x03:
1857 | h4_header->direction = (payload[2] & 0x80) ? GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 ))))) : GINT32_TO_BE(BLUEDROID_DIRECTION_SENT)((gint32) (((guint32) ( (((guint32) (0) & (guint32) 0x000000ffU ) << 24) | (((guint32) (0) & (guint32) 0x0000ff00U) << 8) | (((guint32) (0) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (0) & (guint32) 0xff000000U) >> 24 )))));
1858 |
1859 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[3] + 4;
1860 |
1861 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 2 + 1 + payload[3];
1862 |
1863 | break;
1864 | case BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04:
1865 | h4_header->direction = GINT32_TO_BE(BLUEDROID_DIRECTION_RECV)((gint32) (((guint32) ( (((guint32) (1) & (guint32) 0x000000ffU ) << 24) | (((guint32) (1) & (guint32) 0x0000ff00U) << 8) | (((guint32) (1) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (1) & (guint32) 0xff000000U) >> 24 )))));
1866 |
1867 | captured_length = (unsigned int)sizeof(own_pcap_bluetooth_h4_header) + payload[2] + 3;
1868 |
1869 | length = sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_H4_SIZE1 + 1 + 1 + payload[2];
1870 |
1871 | break;
1872 | default:
1873 | ws_warning("Invalid stream")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1873, __func__, "Invalid stream"); } } while (0);
1874 | closesocket(sock)close(sock);
1875 | return EXIT_CODE_GENERIC;
1876 | }
1877 |
1878 | ws_debug("\t Packet %u: used_buffer_length=%"PRIdMAX" length=%"PRIdMAX" captured_length=%i type=0x%02x", id, (intmax_t)used_buffer_length, (intmax_t)length, captured_length, payload[BLUEDROID_H4_PACKET_TYPE])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1878, __func__, "\t Packet %u: used_buffer_length=%""l" "d" " length=%""l" "d"" captured_length=%i type=0x%02x", id, (intmax_t )used_buffer_length, (intmax_t)length, captured_length, payload [0]); } } while (0);
1879 | if (payload[BLUEDROID_H4_PACKET_TYPE0] == BLUEDROID_H4_PACKET_TYPE_HCI_EVT0x04)
1880 | ws_debug("\t Packet: %02x %02x %02x", (unsigned int) payload[0], (unsigned int) payload[1], (unsigned int)payload[2])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_DEBUG, "extcap/androiddump.c" , 1880, __func__, "\t Packet: %02x %02x %02x", (unsigned int) payload[0], (unsigned int) payload[1], (unsigned int)payload [2]); } } while (0);
1881 | id +=1;
1882 |
1883 | ts -= BLUEDROID_TIMESTAMP_BASE;
1884 |
1885 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
1886 | captured_length,
1887 | captured_length,
1888 | (uint32_t)(ts / 1000000),
1889 | ((uint32_t)(ts % 1000000)) * 1000);
1890 |
1891 | used_buffer_length -= length - sizeof(own_pcap_bluetooth_h4_header) + BLUEDROID_TIMESTAMP_SIZE8;
1892 | if (used_buffer_length < 0) {
1893 | ws_warning("Internal Negative used buffer length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1893, __func__, "Internal Negative used buffer length."); } } while (0);
1894 | closesocket(sock)close(sock);
1895 | return EXIT_CODE_GENERIC;
1896 | }
1897 | memmove(buffer, packet + length, used_buffer_length);
1898 | }
1899 | }
1900 |
1901 | closesocket(sock)close(sock);
1902 | return EXIT_CODE_SUCCESS;
1903 | }
1904 |
1905 | /*----------------------------------------------------------------------------*/
1906 | /* Android Btsnoop Net */
1907 | /*----------------------------------------------------------------------------*/
1908 |
1909 | static int capture_android_bluetooth_btsnoop_net(char *interface, char *fifo,
1910 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
1911 | struct extcap_dumper extcap_dumper;
1912 | static char packet[PACKET_LENGTH65535];
1913 | ssize_t length;
1914 | ssize_t used_buffer_length = 0;
1915 | socket_handle_tint sock;
1916 | const char *adb_tcp_btsnoop_net = "tcp:8872";
1917 | int result;
1918 | char *serial_number;
1919 | uint64_t ts;
1920 | static const uint64_t BTSNOOP_TIMESTAMP_BASE = UINT64_C(0x00dcddb30f2f8000)0x00dcddb30f2f8000UL;
1921 | uint32_t *reported_length;
1922 | uint32_t *captured_length;
1923 | uint32_t *flags;
1924 | /* uint32_t *cumulative_dropped_packets; */
1925 | uint64_t *timestamp;
1926 | char *payload = packet + sizeof(own_pcap_bluetooth_h4_header) + 24;
1927 | own_pcap_bluetooth_h4_header *h4_header;
1928 |
1929 | SET_DATA(reported_length, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 0){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 0; reported_length = data_aligned.value_u32; };
1930 | SET_DATA(captured_length, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 4){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 4; captured_length = data_aligned.value_u32; };
1931 | SET_DATA(flags, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 8){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 8; flags = data_aligned .value_u32; };
1932 | /* SET_DATA(cumulative_dropped_packets, value_u32, packet + sizeof(own_pcap_bluetooth_h4_header) + 12); */
1933 | SET_DATA(timestamp, value_u64, packet + sizeof(own_pcap_bluetooth_h4_header) + 16){ data_aligned_t data_aligned; data_aligned.value_char = packet + sizeof(own_pcap_bluetooth_h4_header) + 16; timestamp = data_aligned .value_u64; };
1934 | SET_DATA(h4_header, value_own_pcap_bluetooth_h4_header, payload - sizeof(own_pcap_bluetooth_h4_header)){ data_aligned_t data_aligned; data_aligned.value_char = payload - sizeof(own_pcap_bluetooth_h4_header); h4_header = data_aligned .value_own_pcap_bluetooth_h4_header; };
1935 |
1936 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_BLUETOOTH_H4_WITH_PHDR99);
1937 | serial_number = get_serial_from_interface(interface);
1938 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
1939 | if (sock == INVALID_SOCKET(-1))
30 | ← | Taking false branch | →
1940 | return EXIT_CODE_INVALID_SOCKET_7;
1941 |
1942 | result = adb_send(sock, adb_tcp_btsnoop_net);
1943 | if (result) {
31 | ← | Assuming 'result' is 0 | →
32 | ← | Taking false branch | →
1944 | ws_warning("Error while sending command <%s>", adb_tcp_btsnoop_net)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1944, __func__, "Error while sending command <%s>", adb_tcp_btsnoop_net ); } } while (0);
1945 | closesocket(sock)close(sock);
1946 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_2;
1947 | }
1948 |
1949 | /* Read "btsnoop" file header - 16 bytes */
1950 | while (used_buffer_length < BTSNOOP_HDR_LEN16) {
33 | ← | Loop condition is true. Entering loop body | →
35 | ← | Assuming 'used_buffer_length' is >= BTSNOOP_HDR_LEN | →
36 | ← | Loop condition is false. Execution continues on line 1959 | →
1951 | length = recv(sock, packet + used_buffer_length, (int)(BTSNOOP_HDR_LEN16 - used_buffer_length), 0);
1952 | if (length
33.1 | 'length' is > 0
<= 0) {
34 | ← | Taking false branch | →
1953 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1953, __func__, "Broken socket connection."); } } while (0);
1954 | closesocket(sock)close(sock);
1955 | return EXIT_CODE_GENERIC;
1956 | }
1957 | used_buffer_length += length;
1958 | }
1959 | used_buffer_length = 0;
1960 |
1961 | while (endless_loop) {
37 | ← | Loop condition is true. Entering loop body | →
1962 | errno(*__errno_location ()) = 0;
1963 | length = recv(sock, packet + used_buffer_length + sizeof(own_pcap_bluetooth_h4_header),
38 | ← | Assuming that 'recv' is successful; 'errno' becomes undefined after the call | →
1964 | (int)(PACKET_LENGTH65535 - sizeof(own_pcap_bluetooth_h4_header) - used_buffer_length), 0);
1965 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
39 | ← | An undefined value may be read from 'errno'
1966 | else if (errno(*__errno_location ()) != 0) {
1967 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1967, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
1968 | closesocket(sock)close(sock);
1969 | return EXIT_CODE_GENERIC;
1970 | }
1971 |
1972 | if (length <= 0) {
1973 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1973, __func__, "Broken socket connection."); } } while (0);
1974 | closesocket(sock)close(sock);
1975 | return EXIT_CODE_GENERIC;
1976 | }
1977 |
1978 | used_buffer_length += length;
1979 |
1980 | while (used_buffer_length >= 24) {
1981 | /* We have the next record header. */
1982 | uint32_t record_reported_length = GUINT32_FROM_BE(*reported_length)(((((guint32) ( (((guint32) (*reported_length) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*reported_length) & (guint32) 0x0000ff00U) << 8) | (((guint32) (*reported_length ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*reported_length ) & (guint32) 0xff000000U) >> 24))))));
1983 | uint32_t record_captured_length = GUINT32_FROM_BE(*captured_length)(((((guint32) ( (((guint32) (*captured_length) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (*captured_length) & (guint32) 0x0000ff00U) << 8) | (((guint32) (*captured_length ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (*captured_length ) & (guint32) 0xff000000U) >> 24))))));
1984 | int32_t direction;
1985 |
1986 | /* Check that the captured length fits in our allocated packet buf,
1987 | * and that the reported length is at least as long as the captured
1988 | * length and won't overflow. */
1989 | if (record_captured_length > PACKET_LENGTH65535 - sizeof(own_pcap_bluetooth_h4_header) - 24 ||
1990 | record_reported_length < record_captured_length ||
1991 | record_reported_length > UINT32_MAX(4294967295U) - sizeof(own_pcap_bluetooth_h4_header)) {
1992 | ws_warning("Invalid btsnoop packet length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 1992, __func__, "Invalid btsnoop packet length."); } } while (0);
1993 | closesocket(sock)close(sock);
1994 | return EXIT_CODE_GENERIC;
1995 | }
1996 |
1997 | /* Check if we have the entire record. */
1998 | if ((size_t)used_buffer_length < 24 + record_captured_length)
1999 | break;
2000 |
2001 | ts = GINT64_FROM_BE(*timestamp)(((gint64) (((guint64) ( (((guint64) (*timestamp) & (guint64 ) (0x00000000000000ffUL)) << 56) | (((guint64) (*timestamp ) & (guint64) (0x000000000000ff00UL)) << 40) | (((guint64 ) (*timestamp) & (guint64) (0x0000000000ff0000UL)) << 24) | (((guint64) (*timestamp) & (guint64) (0x00000000ff000000UL )) << 8) | (((guint64) (*timestamp) & (guint64) (0x000000ff00000000UL )) >> 8) | (((guint64) (*timestamp) & (guint64) (0x0000ff0000000000UL )) >> 24) | (((guint64) (*timestamp) & (guint64) (0x00ff000000000000UL )) >> 40) | (((guint64) (*timestamp) & (guint64) (0xff00000000000000UL )) >> 56))))));
2002 | ts -= BTSNOOP_TIMESTAMP_BASE;
2003 |
2004 | direction = GINT32_FROM_BE(*flags)(((gint32) (((guint32) ( (((guint32) (*flags) & (guint32) 0x000000ffU) << 24) | (((guint32) (*flags) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (*flags) & (guint32 ) 0x00ff0000U) >> 8) | (((guint32) (*flags) & (guint32 ) 0xff000000U) >> 24)))))) & 0x01;
2005 | h4_header->direction = GINT32_TO_BE(direction)((gint32) (((guint32) ( (((guint32) (direction) & (guint32 ) 0x000000ffU) << 24) | (((guint32) (direction) & ( guint32) 0x0000ff00U) << 8) | (((guint32) (direction) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (direction) & (guint32) 0xff000000U) >> 24)))));
2006 |
2007 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo,
2008 | payload - sizeof(own_pcap_bluetooth_h4_header),
2009 | (ssize_t)(record_captured_length + sizeof(own_pcap_bluetooth_h4_header)),
2010 | (ssize_t)(record_reported_length + sizeof(own_pcap_bluetooth_h4_header)),
2011 | (uint32_t)(ts / 1000000),
2012 | ((uint32_t)(ts % 1000000)) * 1000);
2013 |
2014 | used_buffer_length -= 24 + record_captured_length;
2015 | if (used_buffer_length < 0) {
2016 | ws_warning("Internal Negative used buffer length.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2016, __func__, "Internal Negative used buffer length."); } } while (0);
2017 | closesocket(sock)close(sock);
2018 | return EXIT_CODE_GENERIC;
2019 | }
2020 |
2021 | if (used_buffer_length > 0)
2022 | memmove(packet + sizeof(own_pcap_bluetooth_h4_header), payload + record_captured_length, used_buffer_length);
2023 | }
2024 | }
2025 |
2026 | closesocket(sock)close(sock);
2027 | return EXIT_CODE_SUCCESS;
2028 | }
2029 |
2030 | /*----------------------------------------------------------------------------*/
2031 | /* Android Logcat Text*/
2032 | /*----------------------------------------------------------------------------*/
2033 |
2034 |
2035 | static int capture_android_logcat_text(char *interface, char *fifo,
2036 | const char *adb_server_ip, unsigned short *adb_server_tcp_port,
2037 | int logcat_ignore_log_buffer, const char *logcat_custom_parameter) {
2038 | struct extcap_dumper extcap_dumper;
2039 | static char packet[PACKET_LENGTH65535];
2040 | ssize_t length;
2041 | size_t used_buffer_length = 0;
2042 | socket_handle_tint sock;
2043 | const char *protocol_name;
2044 | size_t exported_pdu_headers_size = 0;
2045 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2046 | struct exported_pdu_header *exported_pdu_header_protocol;
2047 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2048 | static const char *wireshark_protocol_logcat_text = "logcat_text_threadtime";
2049 | const char *adb_logcat_template = "shell:export ANDROID_LOG_TAGS=\"\" ; exec logcat -v threadtime%s%s %s";
2050 | char *serial_number = NULL((void*)0);
2051 | int result;
2052 | char *pos;
2053 | const char *logcat_buffer;
2054 | const char *logcat_log_buffer;
2055 |
2056 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2057 |
2058 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2059 | exported_pdu_header_protocol_normal.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat_text) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat_text ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat_text ) + 2) << 8)))));
2060 |
2061 | serial_number = get_serial_from_interface(interface);
2062 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2063 | if (sock == INVALID_SOCKET(-1))
2064 | return EXIT_CODE_INVALID_SOCKET_8;
2065 |
2066 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_MAIN"android-logcat-main") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"android-logcat-text-main"))
2067 | logcat_buffer = " -b main";
2068 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_SYSTEM"android-logcat-system") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"android-logcat-text-system"))
2069 | logcat_buffer = " -b system";
2070 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_RADIO"android-logcat-radio") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"android-logcat-text-radio"))
2071 | logcat_buffer = " -b radio";
2072 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events") || is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"android-logcat-text-events"))
2073 | logcat_buffer = " -b events";
2074 | else if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"android-logcat-text-crash"))
2075 | logcat_buffer = " -b crash";
2076 | else {
2077 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2077, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2078 | closesocket(sock)close(sock);
2079 | return EXIT_CODE_GENERIC;
2080 | }
2081 |
2082 | if (logcat_ignore_log_buffer)
2083 | logcat_log_buffer = " -T 1";
2084 | else
2085 | logcat_log_buffer = "";
2086 |
2087 | if (!logcat_custom_parameter)
2088 | logcat_custom_parameter = "";
2089 |
2090 | result = snprintf((char *) packet, PACKET_LENGTH65535, adb_logcat_template, logcat_buffer, logcat_log_buffer, logcat_custom_parameter);
2091 | if (result <= 0 || result > PACKET_LENGTH65535) {
2092 | ws_warning("Error while completing adb packet")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2092, __func__, "Error while completing adb packet"); } } while (0);
2093 | closesocket(sock)close(sock);
2094 | return EXIT_CODE_BAD_SIZE_OF_ASSEMBLED_ADB_PACKET_17;
2095 | }
2096 |
2097 | result = adb_send(sock, packet);
2098 | if (result) {
2099 | ws_warning("Error while sending command <%s>", packet)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2099, __func__, "Error while sending command <%s>", packet ); } } while (0);
2100 | closesocket(sock)close(sock);
2101 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_3;
2102 | }
2103 |
2104 | protocol_name = wireshark_protocol_logcat_text;
2105 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2106 |
2107 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2108 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2109 |
2110 | memcpy(packet + exported_pdu_headers_size, protocol_name, GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8)))))) - 2);
2111 | exported_pdu_headers_size += GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8))))));
2112 |
2113 | packet[exported_pdu_headers_size - 1] = 0;
2114 | packet[exported_pdu_headers_size - 2] = 0;
2115 |
2116 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2117 | exported_pdu_headers_size += sizeof(struct exported_pdu_header) + GUINT16_FROM_BE(exported_pdu_header_end.length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_end .length) >> 8) | (guint16) ((guint16) (exported_pdu_header_end .length) << 8))))));
2118 |
2119 | used_buffer_length = 0;
2120 | while (endless_loop) {
2121 | errno(*__errno_location ()) = 0;
2122 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
2123 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2124 | else if (errno(*__errno_location ()) != 0) {
2125 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2125, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2126 | closesocket(sock)close(sock);
2127 | return EXIT_CODE_GENERIC;
2128 | }
2129 |
2130 | if (length <= 0) {
2131 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2131, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2132 | closesocket(sock)close(sock);
2133 | return EXIT_CODE_GENERIC;
2134 | }
2135 |
2136 | used_buffer_length += length;
2137 |
2138 | while (used_buffer_length > 0 && (pos = (char *) memchr(packet + exported_pdu_headers_size, '\n', used_buffer_length))) {
2139 | int ms;
2140 | struct tm* date;
2141 | time_t seconds;
2142 | time_t secs = 0;
2143 | int nsecs = 0;
2144 | time_t t;
2145 |
2146 | length = (ssize_t)(pos - packet) + 1;
2147 |
2148 | t = time(NULL((void*)0));
2149 | date = localtime(&t);
2150 | if (!date)
2151 | continue;
2152 | if (6 == sscanf(packet + exported_pdu_headers_size, "%d-%d %d:%d:%d.%d", &date->tm_mon, &date->tm_mday, &date->tm_hour,
2153 | &date->tm_min, &date->tm_sec, &ms)) {
2154 | date->tm_mon -= 1;
2155 | date->tm_isdst = -1;
2156 | seconds = mktime(date);
2157 | secs = (time_t) seconds;
2158 | nsecs = (int) (ms * 1e6);
2159 | }
2160 |
2161 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2162 | length,
2163 | length,
2164 | secs, nsecs);
2165 |
2166 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length + exported_pdu_headers_size - length);
2167 | used_buffer_length -= length - exported_pdu_headers_size;
2168 | }
2169 | }
2170 |
2171 | closesocket(sock)close(sock);
2172 | return EXIT_CODE_SUCCESS;
2173 | }
2174 |
2175 | /*----------------------------------------------------------------------------*/
2176 | /* Android Logger / Logcat */
2177 | /*----------------------------------------------------------------------------*/
2178 |
2179 | static int capture_android_logcat(char *interface, char *fifo,
2180 | const char *adb_server_ip, unsigned short *adb_server_tcp_port) {
2181 | struct extcap_dumper extcap_dumper;
2182 | static char packet[PACKET_LENGTH65535];
2183 | ssize_t length;
2184 | size_t used_buffer_length = 0;
2185 | socket_handle_tint sock;
2186 | const char *protocol_name;
2187 | size_t exported_pdu_headers_size = 0;
2188 | struct exported_pdu_header exported_pdu_header_protocol_events;
2189 | struct exported_pdu_header exported_pdu_header_protocol_normal;
2190 | struct exported_pdu_header *exported_pdu_header_protocol;
2191 | struct exported_pdu_header exported_pdu_header_end = {0, 0};
2192 | static const char *wireshark_protocol_logcat = "logcat";
2193 | static const char *wireshark_protocol_logcat_events = "logcat_events";
2194 | const char *adb_command;
2195 | uint16_t *payload_length;
2196 | uint16_t *try_header_size;
2197 | uint32_t *timestamp_secs;
2198 | uint32_t *timestamp_nsecs;
2199 | uint16_t header_size;
2200 | int result;
2201 | char *serial_number = NULL((void*)0);
2202 |
2203 | extcap_dumper = extcap_dumper_open(fifo, EXTCAP_ENCAP_WIRESHARK_UPPER_PDU155);
2204 |
2205 | exported_pdu_header_protocol_events.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2206 | exported_pdu_header_protocol_events.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat_events) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat_events ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat_events ) + 2) << 8)))));
2207 |
2208 | exported_pdu_header_protocol_normal.tag = GUINT16_TO_BE(EXP_PDU_TAG_DISSECTOR_NAME)((((guint16) ( (guint16) ((guint16) (12) >> 8) | (guint16 ) ((guint16) (12) << 8)))));
2209 | exported_pdu_header_protocol_normal.length = GUINT16_TO_BE(strlen(wireshark_protocol_logcat) + 2)((((guint16) ( (guint16) ((guint16) (strlen(wireshark_protocol_logcat ) + 2) >> 8) | (guint16) ((guint16) (strlen(wireshark_protocol_logcat ) + 2) << 8)))));
2210 |
2211 | serial_number = get_serial_from_interface(interface);
2212 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2213 | if (sock == INVALID_SOCKET(-1))
2214 | return EXIT_CODE_INVALID_SOCKET_9;
2215 |
2216 | adb_command = interface_to_logbuf(interface);
2217 | if (!adb_command) {
2218 | ws_warning("Unknown interface: <%s>", interface)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2218, __func__, "Unknown interface: <%s>", interface) ; } } while (0);
2219 | closesocket(sock)close(sock);
2220 | return EXIT_CODE_GENERIC;
2221 | }
2222 |
2223 | result = adb_send(sock, adb_command);
2224 | if (result) {
2225 | ws_warning("Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2225, __func__, "Error while sending command <%s>", adb_command ); } } while (0);
2226 | closesocket(sock)close(sock);
2227 | return EXIT_CODE_ERROR_WHILE_SENDING_ADB_PACKET_4;
2228 | }
2229 |
2230 | if (is_specified_interface(interface, INTERFACE_ANDROID_LOGCAT_EVENTS"android-logcat-events"))
2231 | {
2232 | protocol_name = wireshark_protocol_logcat_events;
2233 | exported_pdu_header_protocol = &exported_pdu_header_protocol_events;
2234 | } else {
2235 | protocol_name = wireshark_protocol_logcat;
2236 | exported_pdu_header_protocol = &exported_pdu_header_protocol_normal;
2237 | }
2238 |
2239 | memcpy(packet, exported_pdu_header_protocol, sizeof(struct exported_pdu_header));
2240 | exported_pdu_headers_size += sizeof(struct exported_pdu_header);
2241 |
2242 | memcpy(packet + exported_pdu_headers_size, protocol_name, GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8)))))) - 2);
2243 | exported_pdu_headers_size += GUINT16_FROM_BE(exported_pdu_header_protocol->length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_protocol ->length) >> 8) | (guint16) ((guint16) (exported_pdu_header_protocol ->length) << 8))))));
2244 |
2245 | packet[exported_pdu_headers_size - 1] = 0;
2246 | packet[exported_pdu_headers_size - 2] = 0;
2247 |
2248 | memcpy(packet + exported_pdu_headers_size, &exported_pdu_header_end, sizeof(struct exported_pdu_header));
2249 | exported_pdu_headers_size += sizeof(struct exported_pdu_header) + GUINT16_FROM_BE(exported_pdu_header_end.length)(((((guint16) ( (guint16) ((guint16) (exported_pdu_header_end .length) >> 8) | (guint16) ((guint16) (exported_pdu_header_end .length) << 8))))));
2250 |
2251 | SET_DATA(payload_length, value_u16, packet + exported_pdu_headers_size + 0){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 0; payload_length = data_aligned .value_u16; };
2252 | SET_DATA(try_header_size, value_u16, packet + exported_pdu_headers_size + 2){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 2; try_header_size = data_aligned .value_u16; };
2253 | SET_DATA(timestamp_secs, value_u32, packet + exported_pdu_headers_size + 12){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 12; timestamp_secs = data_aligned .value_u32; };
2254 | SET_DATA(timestamp_nsecs, value_u32, packet + exported_pdu_headers_size + 16){ data_aligned_t data_aligned; data_aligned.value_char = packet + exported_pdu_headers_size + 16; timestamp_nsecs = data_aligned .value_u32; };
2255 |
2256 | while (endless_loop) {
2257 | errno(*__errno_location ()) = 0;
2258 | length = recv(sock, packet + exported_pdu_headers_size + used_buffer_length, (int)(PACKET_LENGTH65535 - exported_pdu_headers_size - used_buffer_length), 0);
2259 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2260 | else if (errno(*__errno_location ()) != 0) {
2261 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2261, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2262 | closesocket(sock)close(sock);
2263 | return EXIT_CODE_GENERIC;
2264 | }
2265 |
2266 | if (length <= 0) {
2267 | while (endless_loop) {
2268 | ws_warning("Broken socket connection. Try reconnect.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2268, __func__, "Broken socket connection. Try reconnect.") ; } } while (0);
2269 | used_buffer_length = 0;
2270 | closesocket(sock)close(sock);
2271 |
2272 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2273 | if (sock == INVALID_SOCKET(-1))
2274 | return EXIT_CODE_INVALID_SOCKET_10;
2275 |
2276 | result = adb_send(sock, adb_command);
2277 | if (result) {
2278 | ws_warning("WARNING: Error while sending command <%s>", adb_command)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2278, __func__, "WARNING: Error while sending command <%s>" , adb_command); } } while (0);
2279 | continue;
2280 | }
2281 |
2282 | break;
2283 | }
2284 | }
2285 |
2286 | used_buffer_length += length + exported_pdu_headers_size;
2287 |
2288 | if (*try_header_size != 24)
2289 | header_size = 20;
2290 | else
2291 | header_size = *try_header_size;
2292 |
2293 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2294 |
2295 | while (used_buffer_length >= exported_pdu_headers_size + header_size && (size_t)length <= used_buffer_length) {
2296 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, packet,
2297 | length,
2298 | length,
2299 | *timestamp_secs, *timestamp_nsecs);
2300 |
2301 | memmove(packet + exported_pdu_headers_size, packet + length, used_buffer_length - length);
2302 | used_buffer_length -= length;
2303 | used_buffer_length += exported_pdu_headers_size;
2304 |
2305 |
2306 | length = (*payload_length) + header_size + (ssize_t)exported_pdu_headers_size;
2307 |
2308 | if (*try_header_size != 24)
2309 | header_size = 20;
2310 | else
2311 | header_size = *try_header_size;
2312 | }
2313 | used_buffer_length -= exported_pdu_headers_size;
2314 | }
2315 |
2316 | closesocket(sock)close(sock);
2317 |
2318 | return EXIT_CODE_SUCCESS;
2319 | }
2320 |
2321 |
2322 | /*----------------------------------------------------------------------------*/
2323 | /* Android Wifi Tcpdump */
2324 | /* The Tcpdump sends data in pcap format. So for using the extcap_dumper we */
2325 | /* need to unpack the pcap and then send the packet data to the dumper. */
2326 | /*----------------------------------------------------------------------------*/
2327 | static int capture_android_tcpdump(char *interface, char *fifo,
2328 | char *capture_filter, const char *adb_server_ip,
2329 | unsigned short *adb_server_tcp_port) {
2330 | static const char *const adb_shell_tcpdump_format = "exec:tcpdump -U -n -s 0 -u -i %s -w - %s 2>/dev/null";
2331 | static const char *const regex_interface = INTERFACE_ANDROID_TCPDUMP"android-tcpdump" "-(?<iface>.*?)-(?<serial>.*)";
2332 | struct extcap_dumper extcap_dumper;
2333 | static char data[PACKET_LENGTH65535];
2334 | ssize_t length;
2335 | ssize_t used_buffer_length = 0;
2336 | ssize_t frame_length=0;
2337 | socket_handle_tint sock;
2338 | int result;
2339 | char *iface = NULL((void*)0);
2340 | char *serial_number = NULL((void*)0);
2341 | bool_Bool nanosecond_timestamps;
2342 | bool_Bool swap_byte_order;
2343 | pcap_hdr_t *global_header;
2344 | pcaprec_hdr_t p_header;
2345 | GRegex *regex = NULL((void*)0);
2346 | GError *err = NULL((void*)0);
2347 | GMatchInfo *match = NULL((void*)0);
2348 | char *tcpdump_cmd = NULL((void*)0);
2349 | char *quoted_filter = NULL((void*)0);
2350 |
2351 | regex = g_regex_new(regex_interface, G_REGEX_RAW, (GRegexMatchFlags)0, &err);
2352 | if (!regex) {
2353 | ws_warning("Failed to compile regex for tcpdump interface")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2353, __func__, "Failed to compile regex for tcpdump interface" ); } } while (0);
2354 | return EXIT_CODE_GENERIC;
2355 | }
2356 |
2357 | g_regex_match(regex, interface, (GRegexMatchFlags)0, &match);
2358 | if (!g_match_info_matches(match)) {
2359 | ws_warning("Failed to determine iface name and serial number")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2359, __func__, "Failed to determine iface name and serial number" ); } } while (0);
2360 | g_regex_unref(regex);
2361 | return EXIT_CODE_GENERIC;
2362 | }
2363 |
2364 | iface = g_match_info_fetch_named(match, "iface");
2365 | serial_number = g_match_info_fetch_named(match, "serial");
2366 | g_match_info_free(match);
2367 | g_regex_unref(regex);
2368 |
2369 | /* First check for the device if it is connected or not */
2370 | sock = adb_connect_transport(adb_server_ip, adb_server_tcp_port, serial_number);
2371 | g_free(serial_number)(__builtin_object_size ((serial_number), 0) != ((size_t) - 1) ) ? g_free_sized (serial_number, __builtin_object_size ((serial_number ), 0)) : (g_free) (serial_number);
2372 | if (sock == INVALID_SOCKET(-1)) {
2373 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2374 | return EXIT_CODE_INVALID_SOCKET_11;
2375 | }
2376 |
2377 | quoted_filter = g_shell_quote(capture_filter ? capture_filter : "");
2378 | tcpdump_cmd = ws_strdup_printf(adb_shell_tcpdump_format, iface, quoted_filter)wmem_strdup_printf(((void*)0), adb_shell_tcpdump_format, iface , quoted_filter);
2379 | g_free(iface)(__builtin_object_size ((iface), 0) != ((size_t) - 1)) ? g_free_sized (iface, __builtin_object_size ((iface), 0)) : (g_free) (iface );
2380 | g_free(quoted_filter)(__builtin_object_size ((quoted_filter), 0) != ((size_t) - 1) ) ? g_free_sized (quoted_filter, __builtin_object_size ((quoted_filter ), 0)) : (g_free) (quoted_filter);
2381 | result = adb_send(sock, tcpdump_cmd);
2382 | g_free(tcpdump_cmd)(__builtin_object_size ((tcpdump_cmd), 0) != ((size_t) - 1)) ? g_free_sized (tcpdump_cmd, __builtin_object_size ((tcpdump_cmd ), 0)) : (g_free) (tcpdump_cmd);
2383 | if (result) {
2384 | ws_warning("Error while setting adb transport")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2384, __func__, "Error while setting adb transport"); } } while (0);
2385 | closesocket(sock)close(sock);
2386 | return EXIT_CODE_GENERIC;
2387 | }
2388 |
2389 | while (used_buffer_length < PCAP_GLOBAL_HEADER_LENGTH24) {
2390 | errno(*__errno_location ()) = 0;
2391 | length = recv(sock, data + used_buffer_length, (int)(PCAP_GLOBAL_HEADER_LENGTH24 - used_buffer_length), 0);
2392 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2393 | else if (errno(*__errno_location ()) != 0) {
2394 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2394, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2395 | closesocket(sock)close(sock);
2396 | return EXIT_CODE_GENERIC;
2397 | }
2398 |
2399 | if (length <= 0) {
2400 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2400, __func__, "Broken socket connection."); } } while (0);
2401 | closesocket(sock)close(sock);
2402 | return EXIT_CODE_GENERIC;
2403 | }
2404 |
2405 | used_buffer_length += length;
2406 | }
2407 |
2408 | global_header = (pcap_hdr_t*) data;
2409 | switch (global_header->magic_number) {
2410 | case 0xa1b2c3d4:
2411 | swap_byte_order = false0;
2412 | nanosecond_timestamps = false0;
2413 | break;
2414 | case 0xd4c3b2a1:
2415 | swap_byte_order = true1;
2416 | nanosecond_timestamps = false0;
2417 | break;
2418 | case 0xa1b23c4d:
2419 | swap_byte_order = false0;
2420 | nanosecond_timestamps = true1;
2421 | break;
2422 | case 0x4d3cb2a1:
2423 | swap_byte_order = true1;
2424 | nanosecond_timestamps = true1;
2425 | break;
2426 | default:
2427 | ws_warning("Received incorrect magic")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2427, __func__, "Received incorrect magic"); } } while (0);
2428 | closesocket(sock)close(sock);
2429 | return EXIT_CODE_GENERIC;
2430 | }
2431 | int encap = (int)(swap_byte_order ? GUINT32_SWAP_LE_BE(global_header->network)(((guint32) ( (((guint32) (global_header->network) & ( guint32) 0x000000ffU) << 24) | (((guint32) (global_header ->network) & (guint32) 0x0000ff00U) << 8) | (((guint32 ) (global_header->network) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (global_header->network) & (guint32) 0xff000000U) >> 24)))) : global_header->network);
2432 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2433 | encap = wtap_pcap_encap_to_wtap_encap(encap);
2434 | #endif
2435 | extcap_dumper = extcap_dumper_open(fifo, encap);
2436 |
2437 | used_buffer_length = 0;
2438 | while (endless_loop) {
2439 | ssize_t offset = 0;
2440 |
2441 | errno(*__errno_location ()) = 0;
2442 | length = recv(sock, data + used_buffer_length, (int)(PACKET_LENGTH65535 - used_buffer_length), 0);
2443 | CONTINUE_ON_TIMEOUT(length)if ((*__errno_location ()) == 11) continue;
2444 | else if (errno(*__errno_location ()) != 0) {
2445 | ws_warning("ERROR capture: %s", strerror(errno))do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2445, __func__, "ERROR capture: %s", strerror((*__errno_location ()))); } } while (0);
2446 | closesocket(sock)close(sock);
2447 | return EXIT_CODE_GENERIC;
2448 | }
2449 |
2450 | if (length <= 0) {
2451 | ws_warning("Broken socket connection.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2451, __func__, "Broken socket connection."); } } while (0);
2452 | closesocket(sock)close(sock);
2453 | return EXIT_CODE_GENERIC;
2454 | }
2455 |
2456 | used_buffer_length += length;
2457 |
2458 | while ((used_buffer_length - offset) > PCAP_RECORD_HEADER_LENGTH16) {
2459 | p_header = *((pcaprec_hdr_t*) (data + offset));
2460 | if (swap_byte_order) {
2461 | p_header.ts_sec = GUINT32_SWAP_LE_BE(p_header.ts_sec)(((guint32) ( (((guint32) (p_header.ts_sec) & (guint32) 0x000000ffU ) << 24) | (((guint32) (p_header.ts_sec) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (p_header.ts_sec) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header.ts_sec ) & (guint32) 0xff000000U) >> 24))));
2462 | p_header.ts_usec = GUINT32_SWAP_LE_BE(p_header.ts_usec)(((guint32) ( (((guint32) (p_header.ts_usec) & (guint32) 0x000000ffU ) << 24) | (((guint32) (p_header.ts_usec) & (guint32 ) 0x0000ff00U) << 8) | (((guint32) (p_header.ts_usec) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header.ts_usec ) & (guint32) 0xff000000U) >> 24))));
2463 | p_header.incl_len = GUINT32_SWAP_LE_BE(p_header.incl_len)(((guint32) ( (((guint32) (p_header.incl_len) & (guint32) 0x000000ffU) << 24) | (((guint32) (p_header.incl_len) & (guint32) 0x0000ff00U) << 8) | (((guint32) (p_header.incl_len ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header .incl_len) & (guint32) 0xff000000U) >> 24))));
2464 | p_header.orig_len = GUINT32_SWAP_LE_BE(p_header.orig_len)(((guint32) ( (((guint32) (p_header.orig_len) & (guint32) 0x000000ffU) << 24) | (((guint32) (p_header.orig_len) & (guint32) 0x0000ff00U) << 8) | (((guint32) (p_header.orig_len ) & (guint32) 0x00ff0000U) >> 8) | (((guint32) (p_header .orig_len) & (guint32) 0xff000000U) >> 24))));
2465 | }
2466 | if (!nanosecond_timestamps) {
2467 | p_header.ts_usec = p_header.ts_usec * 1000;
2468 | }
2469 |
2470 | frame_length = p_header.incl_len + PCAP_RECORD_HEADER_LENGTH16;
2471 | if ((used_buffer_length - offset) < frame_length) {
2472 | break; /* wait for complete packet */
2473 | }
2474 |
2475 | /* It was observed that some times tcpdump reports the length of packet as '0' and that leads to the
2476 | * ( Warn Error "Less data was read than was expected" while reading )
2477 | * So to avoid this error we are checking for length of packet before passing it to dumper.
2478 | */
2479 | if (p_header.incl_len > 0) {
2480 | endless_loop = extcap_dumper_dump(extcap_dumper, fifo, data + offset + PCAP_RECORD_HEADER_LENGTH16,
2481 | p_header.incl_len, p_header.orig_len, p_header.ts_sec, p_header.ts_usec);
2482 | }
2483 |
2484 | offset += frame_length;
2485 | }
2486 |
2487 | if (offset < used_buffer_length) {
2488 | memmove(data, data + offset, used_buffer_length - offset);
2489 | }
2490 | used_buffer_length -= offset;
2491 | }
2492 |
2493 | closesocket(sock)close(sock);
2494 | return EXIT_CODE_SUCCESS;
2495 | }
2496 |
2497 | int main(int argc, char *argv[]) {
2498 | char *err_msg;
2499 | int ret = EXIT_CODE_GENERIC;
2500 | int option_idx = 0;
2501 | int result;
2502 | const char *adb_server_ip = NULL((void*)0);
2503 | unsigned short *adb_server_tcp_port = NULL((void*)0);
2504 | unsigned int logcat_text = 0;
2505 | unsigned int logcat_ignore_log_buffer = 0;
2506 | const char *logcat_custom_parameter = NULL((void*)0);
2507 | const char *default_adb_server_ip = "127.0.0.1";
2508 | unsigned short default_adb_server_tcp_port = 5037;
2509 | unsigned short local_adb_server_tcp_port;
2510 | unsigned short local_bt_server_tcp_port;
2511 | unsigned short local_bt_local_tcp_port;
2512 | unsigned short *bt_server_tcp_port = NULL((void*)0);
2513 | unsigned int bt_forward_socket = 0;
2514 | const char *bt_local_ip = NULL((void*)0);
2515 | unsigned short *bt_local_tcp_port = NULL((void*)0);
2516 | unsigned short default_bt_server_tcp_port = 4330;
2517 | const char *default_bt_local_ip = "127.0.0.1";
2518 | unsigned short default_bt_local_tcp_port = 4330;
2519 | extcap_parameters * extcap_conf = NULL((void*)0);
2520 | char *help_url;
2521 | char *help_header = NULL((void*)0);
2522 |
2523 | /* Set the program name. */
2524 | g_set_prgname("androiddump");
2525 |
2526 | cmdarg_err_init(extcap_log_cmdarg_err, extcap_log_cmdarg_err);
2527 |
2528 | /* Initialize log handler early so we can have proper logging during startup. */
2529 | extcap_log_init(extcap_conf);
2530 |
2531 | /*
2532 | * Get credential information for later use.
2533 | */
2534 | init_process_policies();
2535 |
2536 | /*
2537 | * Attempt to get the pathname of the directory containing the
2538 | * executable file.
2539 | */
2540 | err_msg = configuration_init(argv[0], "wireshark");
2541 | if (err_msg != NULL((void*)0)) {
1 | Assuming 'err_msg' is equal to NULL | →
2 | ← | Taking false branch | →
2542 | ws_warning("Can't get pathname of directory containing the extcap program: %s.",do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2543, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0)
2543 | err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2543, __func__, "Can't get pathname of directory containing the extcap program: %s." , err_msg); } } while (0);
2544 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg);
2545 | }
2546 |
2547 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2548 | init_report_failure_message("androiddump");
2549 | #endif
2550 |
2551 | extcap_conf = g_new0(extcap_parameters, 1)((extcap_parameters *) g_malloc0_n ((1), sizeof (extcap_parameters )));
2552 |
2553 | help_url = data_file_url("androiddump.html", application_configuration_environment_prefix());
2554 | extcap_base_set_util_info(extcap_conf, argv[0], ANDROIDDUMP_VERSION_MAJOR"1", ANDROIDDUMP_VERSION_MINOR"1",
2555 | ANDROIDDUMP_VERSION_RELEASE"0", help_url);
2556 | g_free(help_url)(__builtin_object_size ((help_url), 0) != ((size_t) - 1)) ? g_free_sized (help_url, __builtin_object_size ((help_url), 0)) : (g_free) (help_url);
3 | ← | Assuming the condition is false | →
4 | ← | '?' condition is false | →
2557 |
2558 | help_header = ws_strdup_printf(wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2559 | " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2560 | " %s --extcap-interface=INTERFACE --extcap-dlts\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2561 | " %s --extcap-interface=INTERFACE --extcap-config\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2562 | " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2563 | "\nINTERFACE has the form TYPE-DEVICEID:\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2564 | "\t""For example: "INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"-W3D7N15C29005648""\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2565 | "\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2566 | "\tTYPE is one of:\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2567 | "\t"INTERFACE_ANDROID_LOGCAT_MAIN"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2568 | "\t"INTERFACE_ANDROID_LOGCAT_SYSTEM"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2569 | "\t"INTERFACE_ANDROID_LOGCAT_RADIO"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2570 | "\t"INTERFACE_ANDROID_LOGCAT_EVENTS"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2571 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_MAIN"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2572 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_SYSTEM"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2573 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_RADIO"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2574 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_EVENTS"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2575 | "\t"INTERFACE_ANDROID_LOGCAT_TEXT_CRASH"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2576 | "\t"INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2577 | "\t"INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2578 | "\t"INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2579 | "\t"INTERFACE_ANDROID_TCPDUMP"\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2580 | "\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2581 | "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n"wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2582 | "\t""For example: W3D7N15C29005648""\n",wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0])
2583 |
2584 | argv[0], argv[0], argv[0], argv[0])wmem_strdup_printf(((void*)0), " %s --extcap-interfaces [--adb-server-ip=<arg>] [--adb-server-tcp-port=<arg>]\n" " %s --extcap-interface=INTERFACE --extcap-dlts\n" " %s --extcap-interface=INTERFACE --extcap-config\n" " %s --extcap-interface=INTERFACE --fifo=PATH_FILENAME --capture\n" "\nINTERFACE has the form TYPE-DEVICEID:\n" "\t""For example: " "android-bluetooth-btsnoop-net""-W3D7N15C29005648""\n" "\n" "\tTYPE is one of:\n" "\t""android-logcat-main""\n" "\t""android-logcat-system""\n" "\t""android-logcat-radio""\n" "\t""android-logcat-events""\n" "\t""android-logcat-text-main""\n" "\t""android-logcat-text-system" "\n" "\t""android-logcat-text-radio""\n" "\t""android-logcat-text-events" "\n" "\t""android-logcat-text-crash""\n" "\t""android-bluetooth-hcidump" "\n" "\t""android-bluetooth-external-parser""\n" "\t""android-bluetooth-btsnoop-net" "\n" "\t""android-tcpdump""\n" "\n" "\t""DEVICEID is the identifier of the device provided by Android SDK (see \"adb devices\")\n" "\t""For example: W3D7N15C29005648""\n", argv[0], argv[0], argv [0], argv[0]);
2585 | extcap_help_add_header(extcap_conf, help_header);
2586 | g_free(help_header)(__builtin_object_size ((help_header), 0) != ((size_t) - 1)) ? g_free_sized (help_header, __builtin_object_size ((help_header ), 0)) : (g_free) (help_header);
5 | ← | Assuming the condition is false | →
6 | ← | '?' condition is false | →
2587 |
2588 | extcap_help_add_option(extcap_conf, "--help", "print this help");
2589 | extcap_help_add_option(extcap_conf, "--adb-server-ip <IP>", "the IP address of the ADB server");
2590 | extcap_help_add_option(extcap_conf, "--adb-server-tcp-port <port>", "the TCP port of the ADB server");
2591 | extcap_help_add_option(extcap_conf, "--logcat-text", "use logcat text format");
2592 | extcap_help_add_option(extcap_conf, "--logcat-ignore-log-buffer", "ignore log buffer");
2593 | extcap_help_add_option(extcap_conf, "--logcat-custom-options <text>", "use custom logcat parameters");
2594 | extcap_help_add_option(extcap_conf, "--bt-server-tcp-port <port>", "bluetooth server TCP port");
2595 | extcap_help_add_option(extcap_conf, "--bt-forward-socket <path>", "bluetooth forward socket");
2596 | extcap_help_add_option(extcap_conf, "--bt-local-ip <IP>", "the bluetooth local IP");
2597 | extcap_help_add_option(extcap_conf, "--bt-local-tcp-port <port>", "the bluetooth local TCP port");
2598 |
2599 | ws_opterr = 0;
2600 | ws_optind = 0;
2601 |
2602 | if (argc == 1) {
7 | ← | Assuming 'argc' is not equal to 1 | →
8 | ← | Taking false branch | →
2603 | extcap_help_print(extcap_conf);
2604 | ret = EXIT_CODE_SUCCESS;
2605 | goto end;
2606 | }
2607 |
2608 | while ((result = ws_getopt_long(argc, argv, "", longopts, &option_idx)) != -1) {
9 | ← | Assuming the condition is false | →
10 | ← | Loop condition is false. Execution continues on line 2696 | →
2609 | switch (result) {
2610 |
2611 | case OPT_VERSION:
2612 | extcap_version_print(extcap_conf);
2613 | ret = EXIT_CODE_SUCCESS;
2614 | goto end;
2615 | case OPT_HELP:
2616 | extcap_help_print(extcap_conf);
2617 | ret = EXIT_CODE_SUCCESS;
2618 | goto end;
2619 | case OPT_CONFIG_ADB_SERVER_IP:
2620 | adb_server_ip = ws_optarg;
2621 | break;
2622 | case OPT_CONFIG_ADB_SERVER_TCP_PORT:
2623 | adb_server_tcp_port = &local_adb_server_tcp_port;
2624 | if (!ws_optarg){
2625 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2625, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2626 | goto end;
2627 | }
2628 | if (!ws_strtou16(ws_optarg, NULL((void*)0), adb_server_tcp_port)) {
2629 | ws_warning("Invalid adb server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2629, __func__, "Invalid adb server TCP port: %s", ws_optarg ); } } while (0);
2630 | goto end;
2631 | }
2632 | break;
2633 | case OPT_CONFIG_LOGCAT_TEXT:
2634 | if (ws_optarg && !*ws_optarg)
2635 | logcat_text = true1;
2636 | else
2637 | logcat_text = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2638 | break;
2639 | case OPT_CONFIG_LOGCAT_IGNORE_LOG_BUFFER:
2640 | if (ws_optarg == NULL((void*)0) || (ws_optarg && !*ws_optarg))
2641 | logcat_ignore_log_buffer = true1;
2642 | else
2643 | logcat_ignore_log_buffer = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2644 | break;
2645 | case OPT_CONFIG_LOGCAT_CUSTOM_OPTIONS:
2646 | if (ws_optarg == NULL((void*)0) || (ws_optarg && *ws_optarg == '\0')) {
2647 | logcat_custom_parameter = NULL((void*)0);
2648 | break;
2649 | }
2650 |
2651 | if (g_regex_match_simple("(^|\\s)-[bBcDfgLnpPrv]", ws_optarg, G_REGEX_RAW, (GRegexMatchFlags)0)) {
2652 | ws_error("Found prohibited option in logcat-custom-options")ws_log_fatal_full("androiddump", LOG_LEVEL_ERROR, "extcap/androiddump.c" , 2652, __func__, "Found prohibited option in logcat-custom-options" );
2653 | return EXIT_CODE_GENERIC;
2654 | }
2655 |
2656 | logcat_custom_parameter = ws_optarg;
2657 |
2658 | break;
2659 | case OPT_CONFIG_BT_SERVER_TCP_PORT:
2660 | bt_server_tcp_port = &local_bt_server_tcp_port;
2661 | if (!ws_optarg){
2662 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2662, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2663 | goto end;
2664 | }
2665 | if (!ws_strtou16(ws_optarg, NULL((void*)0), bt_server_tcp_port)) {
2666 | ws_warning("Invalid bluetooth server TCP port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2666, __func__, "Invalid bluetooth server TCP port: %s", ws_optarg ); } } while (0);
2667 | goto end;
2668 | }
2669 | break;
2670 | case OPT_CONFIG_BT_FORWARD_SOCKET:
2671 | bt_forward_socket = (g_ascii_strncasecmp(ws_optarg, "true", 4) == 0);
2672 | break;
2673 | case OPT_CONFIG_BT_LOCAL_IP:
2674 | bt_local_ip = ws_optarg;
2675 | break;
2676 | case OPT_CONFIG_BT_LOCAL_TCP_PORT:
2677 | bt_local_tcp_port = &local_bt_local_tcp_port;
2678 | if (!ws_optarg){
2679 | ws_warning("Impossible exception. Parameter required argument, but there is no it right now.")do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2679, __func__, "Impossible exception. Parameter required argument, but there is no it right now." ); } } while (0);
2680 | goto end;
2681 | }
2682 | if (!ws_strtou16(ws_optarg, NULL((void*)0), bt_local_tcp_port)) {
2683 | ws_warning("Invalid bluetooth local tcp port: %s", ws_optarg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2683, __func__, "Invalid bluetooth local tcp port: %s", ws_optarg ); } } while (0);
2684 | goto end;
2685 | }
2686 | break;
2687 | default:
2688 | if (!extcap_base_parse_options(extcap_conf, result - EXTCAP_OPT_LIST_INTERFACES, ws_optarg))
2689 | {
2690 | ws_warning("Invalid argument <%s>. Try --help.\n", argv[ws_optind - 1])do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2690, __func__, "Invalid argument <%s>. Try --help.\n" , argv[ws_optind - 1]); } } while (0);
2691 | goto end;
2692 | }
2693 | }
2694 | }
2695 |
2696 | if (!adb_server_ip
10.1 | 'adb_server_ip' is null
)
11 | ← | Taking true branch | →
2697 | adb_server_ip = default_adb_server_ip;
2698 |
2699 | if (!adb_server_tcp_port
11.1 | 'adb_server_tcp_port' is null
)
12 | ← | Taking true branch | →
2700 | adb_server_tcp_port = &default_adb_server_tcp_port;
2701 |
2702 | if (!bt_server_tcp_port
12.1 | 'bt_server_tcp_port' is null
)
13 | ← | Taking true branch | →
2703 | bt_server_tcp_port = &default_bt_server_tcp_port;
2704 |
2705 | if (!bt_local_ip
13.1 | 'bt_local_ip' is null
)
14 | ← | Taking true branch | →
2706 | bt_local_ip = default_bt_local_ip;
2707 |
2708 | if (!bt_local_tcp_port
14.1 | 'bt_local_tcp_port' is null
)
15 | ← | Taking true branch | →
2709 | bt_local_tcp_port = &default_bt_local_tcp_port;
2710 |
2711 | err_msg = ws_init_sockets();
2712 | if (err_msg != NULL((void*)0)) {
16 | ← | Assuming 'err_msg' is equal to NULL | →
17 | ← | Taking false branch | →
2713 | ws_warning("ERROR: %s", err_msg)do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2713, __func__, "ERROR: %s", err_msg); } } while (0);
2714 | g_free(err_msg)(__builtin_object_size ((err_msg), 0) != ((size_t) - 1)) ? g_free_sized (err_msg, __builtin_object_size ((err_msg), 0)) : (g_free) ( err_msg);
2715 | ws_warning("%s", please_report_bug())do { if (1) { ws_log_full("androiddump", LOG_LEVEL_WARNING, "extcap/androiddump.c" , 2715, __func__, "%s", please_report_bug()); } } while (0);
2716 | goto end;
2717 | }
2718 |
2719 | extcap_cmdline_debug(argv, argc);
2720 |
2721 | if (extcap_conf->do_list_interfaces)
18 | ← | Assuming field 'do_list_interfaces' is 0 | →
19 | ← | Taking false branch | →
2722 | register_interfaces(extcap_conf, adb_server_ip, adb_server_tcp_port);
2723 |
2724 | /* NOTE:
2725 | * extcap implementation calls androiddump --extcap-dlts for each interface.
2726 | * The only way to know whether an interface exists or not is to go through the
2727 | * whole process of listing all interfaces (i.e. calling register_interfaces
2728 | * function). Since being a system resource heavy operation and repeated for
2729 | * each interface instead register a fake interface to be returned for dlt
2730 | * listing only purpose
2731 | */
2732 | if (extcap_conf->do_list_dlts) {
20 | ← | Assuming field 'do_list_dlts' is 0 | →
21 | ← | Taking false branch | →
2733 | new_fake_interface_for_list_dlts(extcap_conf, extcap_conf->interface);
2734 | }
2735 |
2736 | if (extcap_base_handle_interface(extcap_conf)) {
22 | ← | Assuming the condition is false | →
23 | ← | Taking false branch | →
2737 | ret = EXIT_CODE_SUCCESS;
2738 | goto end;
2739 | }
2740 |
2741 | if (extcap_conf->show_config) {
24 | ← | Assuming field 'show_config' is 0 | →
25 | ← | Taking false branch | →
2742 | ret = list_config(extcap_conf->interface);
2743 | goto end;
2744 | }
2745 |
2746 | if (extcap_conf->capture) {
26 | ← | Assuming field 'capture' is not equal to 0 | →
2747 | if (extcap_conf->interface && is_logcat_interface(extcap_conf->interface))
27 | ← | Assuming field 'interface' is non-null | →
2748 | if (logcat_text)
2749 | ret = capture_android_logcat_text(extcap_conf->interface,
2750 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2751 | logcat_ignore_log_buffer, logcat_custom_parameter);
2752 | else
2753 | ret = capture_android_logcat(extcap_conf->interface,
2754 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2755 | else if (extcap_conf->interface
27.1 | Field 'interface' is non-null
&& is_logcat_text_interface(extcap_conf->interface))
2756 | ret = capture_android_logcat_text(extcap_conf->interface,
2757 | extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2758 | logcat_ignore_log_buffer, logcat_custom_parameter);
2759 | else if (extcap_conf->interface
27.2 | Field 'interface' is non-null
&& is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_HCIDUMP"android-bluetooth-hcidump"))
2760 | ret = capture_android_bluetooth_hcidump(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
2761 | else if (extcap_conf->interface
27.3 | Field 'interface' is non-null
&& is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_EXTERNAL_PARSER"android-bluetooth-external-parser"))
2762 | ret = capture_android_bluetooth_external_parser(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port,
2763 | bt_server_tcp_port, bt_forward_socket, bt_local_ip, bt_local_tcp_port);
2764 | else if (extcap_conf->interface
27.4 | Field 'interface' is non-null
&& (is_specified_interface(extcap_conf->interface, INTERFACE_ANDROID_BLUETOOTH_BTSNOOP_NET"android-bluetooth-btsnoop-net")))
28 | ← | Taking true branch | →
2765 | ret = capture_android_bluetooth_btsnoop_net(extcap_conf->interface, extcap_conf->fifo, adb_server_ip, adb_server_tcp_port);
29 | ← | Calling 'capture_android_bluetooth_btsnoop_net' | →
2766 | else if (extcap_conf->interface && (is_specified_interface(extcap_conf->interface,INTERFACE_ANDROID_TCPDUMP"android-tcpdump")))
2767 | ret = capture_android_tcpdump(extcap_conf->interface, extcap_conf->fifo, extcap_conf->capture_filter, adb_server_ip, adb_server_tcp_port);
2768 |
2769 | goto end;
2770 | }
2771 |
2772 | /* no action was given, assume success */
2773 | ret = EXIT_CODE_SUCCESS;
2774 |
2775 | end:
2776 | /* clean up stuff */
2777 | extcap_base_cleanup(&extcap_conf);
2778 | #ifndef ANDROIDDUMP_USE_LIBPCAP
2779 | wtap_cleanup();
2780 | #endif
2781 |
2782 | return ret;
2783 | }
2784 |
2785 | /*
2786 | * Editor modelines - https://www.wireshark.org/tools/modelines.html
2787 | *
2788 | * Local variables:
2789 | * c-basic-offset: 4
2790 | * tab-width: 8
2791 | * indent-tabs-mode: nil
2792 | * End:
2793 | *
2794 | * vi: set shiftwidth=4 tabstop=8 expandtab:
2795 | * :indentSize=4:tabSize=8:noTabs=true:
2796 | */