torture: Use ZERO_STRUCTPN instead of explicit deref
[Samba/gebeck_regimport.git] / examples / pcap2nbench / main.cpp
blobe07b4735bd2a709418699f8d2a5c3ef593c665c7
1 /*\
2 * pcap2nbench - Converts libpcap network traces to nbench input
3 * Copyright (C) 2004 Jim McDonough <jmcd@us.ibm.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
18 * Written by Anthony Liguori <aliguori@us.ibm.com>
19 \*/
21 #include <iostream>
22 #include <pcap.h>
23 #include <getopt.h>
24 #include <stdint.h>
25 #include <netinet/in.h>
27 #include "ethernet.hpp"
28 #include "ip.hpp"
29 #include "tcp.hpp"
30 #include "smb.hpp"
31 #include "ntcreateandxrequest.hpp"
32 #include "ntcreateandxresponse.hpp"
33 #include "readandxrequest.hpp"
34 #include "writeandxrequest.hpp"
35 #include "closerequest.hpp"
37 #include <vector>
38 #include <set>
41 /* derived from source/include/nterr.h */
42 const char *nt_status_to_string[] = {
43 "NT_STATUS_OK", /* 0x0000 */
44 "NT_STATUS_UNSUCCESSFUL", /* 0x0001 */
45 "NT_STATUS_NOT_IMPLEMENTED", /* 0x0002 */
46 "NT_STATUS_INVALID_INFO_CLASS", /* 0x0003 */
47 "NT_STATUS_INFO_LENGTH_MISMATCH", /* 0x0004 */
48 "NT_STATUS_ACCESS_VIOLATION", /* 0x0005 */
49 "NT_STATUS_IN_PAGE_ERROR", /* 0x0006 */
50 "NT_STATUS_PAGEFILE_QUOTA", /* 0x0007 */
51 "NT_STATUS_INVALID_HANDLE", /* 0x0008 */
52 "NT_STATUS_BAD_INITIAL_STACK", /* 0x0009 */
53 "NT_STATUS_BAD_INITIAL_PC", /* 0x000a */
54 "NT_STATUS_INVALID_CID", /* 0x000b */
55 "NT_STATUS_TIMER_NOT_CANCELED", /* 0x000c */
56 "NT_STATUS_INVALID_PARAMETER", /* 0x000d */
57 "NT_STATUS_NO_SUCH_DEVICE", /* 0x000e */
58 "NT_STATUS_NO_SUCH_FILE", /* 0x000f */
59 "NT_STATUS_INVALID_DEVICE_REQUEST", /* 0x0010 */
60 "NT_STATUS_END_OF_FILE", /* 0x0011 */
61 "NT_STATUS_WRONG_VOLUME", /* 0x0012 */
62 "NT_STATUS_NO_MEDIA_IN_DEVICE", /* 0x0013 */
63 "NT_STATUS_UNRECOGNIZED_MEDIA", /* 0x0014 */
64 "NT_STATUS_NONEXISTENT_SECTOR", /* 0x0015 */
65 "NT_STATUS_MORE_PROCESSING_REQUIRED", /* 0x0016 */
66 "NT_STATUS_NO_MEMORY", /* 0x0017 */
67 "NT_STATUS_CONFLICTING_ADDRESSES", /* 0x0018 */
68 "NT_STATUS_NOT_MAPPED_VIEW", /* 0x0019 */
69 "NT_STATUS_UNABLE_TO_FREE_VM", /* 0x001a */
70 "NT_STATUS_UNABLE_TO_DELETE_SECTION", /* 0x001b */
71 "NT_STATUS_INVALID_SYSTEM_SERVICE", /* 0x001c */
72 "NT_STATUS_ILLEGAL_INSTRUCTION", /* 0x001d */
73 "NT_STATUS_INVALID_LOCK_SEQUENCE", /* 0x001e */
74 "NT_STATUS_INVALID_VIEW_SIZE", /* 0x001f */
75 "NT_STATUS_INVALID_FILE_FOR_SECTION", /* 0x0020 */
76 "NT_STATUS_ALREADY_COMMITTED", /* 0x0021 */
77 "NT_STATUS_ACCESS_DENIED", /* 0x0022 */
78 "NT_STATUS_BUFFER_TOO_SMALL", /* 0x0023 */
79 "NT_STATUS_OBJECT_TYPE_MISMATCH", /* 0x0024 */
80 "NT_STATUS_NONCONTINUABLE_EXCEPTION", /* 0x0025 */
81 "NT_STATUS_INVALID_DISPOSITION", /* 0x0026 */
82 "NT_STATUS_UNWIND", /* 0x0027 */
83 "NT_STATUS_BAD_STACK", /* 0x0028 */
84 "NT_STATUS_INVALID_UNWIND_TARGET", /* 0x0029 */
85 "NT_STATUS_NOT_LOCKED", /* 0x002a */
86 "NT_STATUS_PARITY_ERROR", /* 0x002b */
87 "NT_STATUS_UNABLE_TO_DECOMMIT_VM", /* 0x002c */
88 "NT_STATUS_NOT_COMMITTED", /* 0x002d */
89 "NT_STATUS_INVALID_PORT_ATTRIBUTES", /* 0x002e */
90 "NT_STATUS_PORT_MESSAGE_TOO_LONG", /* 0x002f */
91 "NT_STATUS_INVALID_PARAMETER_MIX", /* 0x0030 */
92 "NT_STATUS_INVALID_QUOTA_LOWER", /* 0x0031 */
93 "NT_STATUS_DISK_CORRUPT_ERROR", /* 0x0032 */
94 "NT_STATUS_OBJECT_NAME_INVALID", /* 0x0033 */
95 "NT_STATUS_OBJECT_NAME_NOT_FOUND", /* 0x0034 */
96 "NT_STATUS_OBJECT_NAME_COLLISION", /* 0x0035 */
97 "NT_STATUS_HANDLE_NOT_WAITABLE", /* 0x0036 */
98 "NT_STATUS_PORT_DISCONNECTED", /* 0x0037 */
99 "NT_STATUS_DEVICE_ALREADY_ATTACHED", /* 0x0038 */
100 "NT_STATUS_OBJECT_PATH_INVALID", /* 0x0039 */
101 "NT_STATUS_OBJECT_PATH_NOT_FOUND", /* 0x003a */
102 "NT_STATUS_OBJECT_PATH_SYNTAX_BAD", /* 0x003b */
103 "NT_STATUS_DATA_OVERRUN", /* 0x003c */
104 "NT_STATUS_DATA_LATE_ERROR", /* 0x003d */
105 "NT_STATUS_DATA_ERROR", /* 0x003e */
106 "NT_STATUS_CRC_ERROR", /* 0x003f */
107 "NT_STATUS_SECTION_TOO_BIG", /* 0x0040 */
108 "NT_STATUS_PORT_CONNECTION_REFUSED", /* 0x0041 */
109 "NT_STATUS_INVALID_PORT_HANDLE", /* 0x0042 */
110 "NT_STATUS_SHARING_VIOLATION", /* 0x0043 */
111 "NT_STATUS_QUOTA_EXCEEDED", /* 0x0044 */
112 "NT_STATUS_INVALID_PAGE_PROTECTION", /* 0x0045 */
113 "NT_STATUS_MUTANT_NOT_OWNED", /* 0x0046 */
114 "NT_STATUS_SEMAPHORE_LIMIT_EXCEEDED", /* 0x0047 */
115 "NT_STATUS_PORT_ALREADY_SET", /* 0x0048 */
116 "NT_STATUS_SECTION_NOT_IMAGE", /* 0x0049 */
117 "NT_STATUS_SUSPEND_COUNT_EXCEEDED", /* 0x004a */
118 "NT_STATUS_THREAD_IS_TERMINATING", /* 0x004b */
119 "NT_STATUS_BAD_WORKING_SET_LIMIT", /* 0x004c */
120 "NT_STATUS_INCOMPATIBLE_FILE_MAP", /* 0x004d */
121 "NT_STATUS_SECTION_PROTECTION", /* 0x004e */
122 "NT_STATUS_EAS_NOT_SUPPORTED", /* 0x004f */
123 "NT_STATUS_EA_TOO_LARGE", /* 0x0050 */
124 "NT_STATUS_NONEXISTENT_EA_ENTRY", /* 0x0051 */
125 "NT_STATUS_NO_EAS_ON_FILE", /* 0x0052 */
126 "NT_STATUS_EA_CORRUPT_ERROR", /* 0x0053 */
127 "NT_STATUS_FILE_LOCK_CONFLICT", /* 0x0054 */
128 "NT_STATUS_LOCK_NOT_GRANTED", /* 0x0055 */
129 "NT_STATUS_DELETE_PENDING", /* 0x0056 */
130 "NT_STATUS_CTL_FILE_NOT_SUPPORTED", /* 0x0057 */
131 "NT_STATUS_UNKNOWN_REVISION", /* 0x0058 */
132 "NT_STATUS_REVISION_MISMATCH", /* 0x0059 */
133 "NT_STATUS_INVALID_OWNER", /* 0x005a */
134 "NT_STATUS_INVALID_PRIMARY_GROUP", /* 0x005b */
135 "NT_STATUS_NO_IMPERSONATION_TOKEN", /* 0x005c */
136 "NT_STATUS_CANT_DISABLE_MANDATORY", /* 0x005d */
137 "NT_STATUS_NO_LOGON_SERVERS", /* 0x005e */
138 "NT_STATUS_NO_SUCH_LOGON_SESSION", /* 0x005f */
139 "NT_STATUS_NO_SUCH_PRIVILEGE", /* 0x0060 */
140 "NT_STATUS_PRIVILEGE_NOT_HELD", /* 0x0061 */
141 "NT_STATUS_INVALID_ACCOUNT_NAME", /* 0x0062 */
142 "NT_STATUS_USER_EXISTS", /* 0x0063 */
143 "NT_STATUS_NO_SUCH_USER", /* 0x0064 */
144 "NT_STATUS_GROUP_EXISTS", /* 0x0065 */
145 "NT_STATUS_NO_SUCH_GROUP", /* 0x0066 */
146 "NT_STATUS_MEMBER_IN_GROUP", /* 0x0067 */
147 "NT_STATUS_MEMBER_NOT_IN_GROUP", /* 0x0068 */
148 "NT_STATUS_LAST_ADMIN", /* 0x0069 */
149 "NT_STATUS_WRONG_PASSWORD", /* 0x006a */
150 "NT_STATUS_ILL_FORMED_PASSWORD", /* 0x006b */
151 "NT_STATUS_PASSWORD_RESTRICTION", /* 0x006c */
152 "NT_STATUS_LOGON_FAILURE", /* 0x006d */
153 "NT_STATUS_ACCOUNT_RESTRICTION", /* 0x006e */
154 "NT_STATUS_INVALID_LOGON_HOURS", /* 0x006f */
155 "NT_STATUS_INVALID_WORKSTATION", /* 0x0070 */
156 "NT_STATUS_PASSWORD_EXPIRED", /* 0x0071 */
157 "NT_STATUS_ACCOUNT_DISABLED", /* 0x0072 */
158 "NT_STATUS_NONE_MAPPED", /* 0x0073 */
159 "NT_STATUS_TOO_MANY_LUIDS_REQUESTED", /* 0x0074 */
160 "NT_STATUS_LUIDS_EXHAUSTED", /* 0x0075 */
161 "NT_STATUS_INVALID_SUB_AUTHORITY", /* 0x0076 */
162 "NT_STATUS_INVALID_ACL", /* 0x0077 */
163 "NT_STATUS_INVALID_SID", /* 0x0078 */
164 "NT_STATUS_INVALID_SECURITY_DESCR", /* 0x0079 */
165 "NT_STATUS_PROCEDURE_NOT_FOUND", /* 0x007a */
166 "NT_STATUS_INVALID_IMAGE_FORMAT", /* 0x007b */
167 "NT_STATUS_NO_TOKEN", /* 0x007c */
168 "NT_STATUS_BAD_INHERITANCE_ACL", /* 0x007d */
169 "NT_STATUS_RANGE_NOT_LOCKED", /* 0x007e */
170 "NT_STATUS_DISK_FULL", /* 0x007f */
171 "NT_STATUS_SERVER_DISABLED", /* 0x0080 */
172 "NT_STATUS_SERVER_NOT_DISABLED", /* 0x0081 */
173 "NT_STATUS_TOO_MANY_GUIDS_REQUESTED", /* 0x0082 */
174 "NT_STATUS_GUIDS_EXHAUSTED", /* 0x0083 */
175 "NT_STATUS_INVALID_ID_AUTHORITY", /* 0x0084 */
176 "NT_STATUS_AGENTS_EXHAUSTED", /* 0x0085 */
177 "NT_STATUS_INVALID_VOLUME_LABEL", /* 0x0086 */
178 "NT_STATUS_SECTION_NOT_EXTENDED", /* 0x0087 */
179 "NT_STATUS_NOT_MAPPED_DATA", /* 0x0088 */
180 "NT_STATUS_RESOURCE_DATA_NOT_FOUND", /* 0x0089 */
181 "NT_STATUS_RESOURCE_TYPE_NOT_FOUND", /* 0x008a */
182 "NT_STATUS_RESOURCE_NAME_NOT_FOUND", /* 0x008b */
183 "NT_STATUS_ARRAY_BOUNDS_EXCEEDED", /* 0x008c */
184 "NT_STATUS_FLOAT_DENORMAL_OPERAND", /* 0x008d */
185 "NT_STATUS_FLOAT_DIVIDE_BY_ZERO", /* 0x008e */
186 "NT_STATUS_FLOAT_INEXACT_RESULT", /* 0x008f */
187 "NT_STATUS_FLOAT_INVALID_OPERATION", /* 0x0090 */
188 "NT_STATUS_FLOAT_OVERFLOW", /* 0x0091 */
189 "NT_STATUS_FLOAT_STACK_CHECK", /* 0x0092 */
190 "NT_STATUS_FLOAT_UNDERFLOW", /* 0x0093 */
191 "NT_STATUS_INTEGER_DIVIDE_BY_ZERO", /* 0x0094 */
192 "NT_STATUS_INTEGER_OVERFLOW", /* 0x0095 */
193 "NT_STATUS_PRIVILEGED_INSTRUCTION", /* 0x0096 */
194 "NT_STATUS_TOO_MANY_PAGING_FILES", /* 0x0097 */
195 "NT_STATUS_FILE_INVALID", /* 0x0098 */
196 "NT_STATUS_ALLOTTED_SPACE_EXCEEDED", /* 0x0099 */
197 "NT_STATUS_INSUFFICIENT_RESOURCES", /* 0x009a */
198 "NT_STATUS_DFS_EXIT_PATH_FOUND", /* 0x009b */
199 "NT_STATUS_DEVICE_DATA_ERROR", /* 0x009c */
200 "NT_STATUS_DEVICE_NOT_CONNECTED", /* 0x009d */
201 "NT_STATUS_DEVICE_POWER_FAILURE", /* 0x009e */
202 "NT_STATUS_FREE_VM_NOT_AT_BASE", /* 0x009f */
203 "NT_STATUS_MEMORY_NOT_ALLOCATED", /* 0x00a0 */
204 "NT_STATUS_WORKING_SET_QUOTA", /* 0x00a1 */
205 "NT_STATUS_MEDIA_WRITE_PROTECTED", /* 0x00a2 */
206 "NT_STATUS_DEVICE_NOT_READY", /* 0x00a3 */
207 "NT_STATUS_INVALID_GROUP_ATTRIBUTES", /* 0x00a4 */
208 "NT_STATUS_BAD_IMPERSONATION_LEVEL", /* 0x00a5 */
209 "NT_STATUS_CANT_OPEN_ANONYMOUS", /* 0x00a6 */
210 "NT_STATUS_BAD_VALIDATION_CLASS", /* 0x00a7 */
211 "NT_STATUS_BAD_TOKEN_TYPE", /* 0x00a8 */
212 "NT_STATUS_BAD_MASTER_BOOT_RECORD", /* 0x00a9 */
213 "NT_STATUS_INSTRUCTION_MISALIGNMENT", /* 0x00aa */
214 "NT_STATUS_INSTANCE_NOT_AVAILABLE", /* 0x00ab */
215 "NT_STATUS_PIPE_NOT_AVAILABLE", /* 0x00ac */
216 "NT_STATUS_INVALID_PIPE_STATE", /* 0x00ad */
217 "NT_STATUS_PIPE_BUSY", /* 0x00ae */
218 "NT_STATUS_ILLEGAL_FUNCTION", /* 0x00af */
219 "NT_STATUS_PIPE_DISCONNECTED", /* 0x00b0 */
220 "NT_STATUS_PIPE_CLOSING", /* 0x00b1 */
221 "NT_STATUS_PIPE_CONNECTED", /* 0x00b2 */
222 "NT_STATUS_PIPE_LISTENING", /* 0x00b3 */
223 "NT_STATUS_INVALID_READ_MODE", /* 0x00b4 */
224 "NT_STATUS_IO_TIMEOUT", /* 0x00b5 */
225 "NT_STATUS_FILE_FORCED_CLOSED", /* 0x00b6 */
226 "NT_STATUS_PROFILING_NOT_STARTED", /* 0x00b7 */
227 "NT_STATUS_PROFILING_NOT_STOPPED", /* 0x00b8 */
228 "NT_STATUS_COULD_NOT_INTERPRET", /* 0x00b9 */
229 "NT_STATUS_FILE_IS_A_DIRECTORY", /* 0x00ba */
230 "NT_STATUS_NOT_SUPPORTED", /* 0x00bb */
231 "NT_STATUS_REMOTE_NOT_LISTENING", /* 0x00bc */
232 "NT_STATUS_DUPLICATE_NAME", /* 0x00bd */
233 "NT_STATUS_BAD_NETWORK_PATH", /* 0x00be */
234 "NT_STATUS_NETWORK_BUSY", /* 0x00bf */
235 "NT_STATUS_DEVICE_DOES_NOT_EXIST", /* 0x00c0 */
236 "NT_STATUS_TOO_MANY_COMMANDS", /* 0x00c1 */
237 "NT_STATUS_ADAPTER_HARDWARE_ERROR", /* 0x00c2 */
238 "NT_STATUS_INVALID_NETWORK_RESPONSE", /* 0x00c3 */
239 "NT_STATUS_UNEXPECTED_NETWORK_ERROR", /* 0x00c4 */
240 "NT_STATUS_BAD_REMOTE_ADAPTER", /* 0x00c5 */
241 "NT_STATUS_PRINT_QUEUE_FULL", /* 0x00c6 */
242 "NT_STATUS_NO_SPOOL_SPACE", /* 0x00c7 */
243 "NT_STATUS_PRINT_CANCELLED", /* 0x00c8 */
244 "NT_STATUS_NETWORK_NAME_DELETED", /* 0x00c9 */
245 "NT_STATUS_NETWORK_ACCESS_DENIED", /* 0x00ca */
246 "NT_STATUS_BAD_DEVICE_TYPE", /* 0x00cb */
247 "NT_STATUS_BAD_NETWORK_NAME", /* 0x00cc */
248 "NT_STATUS_TOO_MANY_NAMES", /* 0x00cd */
249 "NT_STATUS_TOO_MANY_SESSIONS", /* 0x00ce */
250 "NT_STATUS_SHARING_PAUSED", /* 0x00cf */
251 "NT_STATUS_REQUEST_NOT_ACCEPTED", /* 0x00d0 */
252 "NT_STATUS_REDIRECTOR_PAUSED", /* 0x00d1 */
253 "NT_STATUS_NET_WRITE_FAULT", /* 0x00d2 */
254 "NT_STATUS_PROFILING_AT_LIMIT", /* 0x00d3 */
255 "NT_STATUS_NOT_SAME_DEVICE", /* 0x00d4 */
256 "NT_STATUS_FILE_RENAMED", /* 0x00d5 */
257 "NT_STATUS_VIRTUAL_CIRCUIT_CLOSED", /* 0x00d6 */
258 "NT_STATUS_NO_SECURITY_ON_OBJECT", /* 0x00d7 */
259 "NT_STATUS_CANT_WAIT", /* 0x00d8 */
260 "NT_STATUS_PIPE_EMPTY", /* 0x00d9 */
261 "NT_STATUS_CANT_ACCESS_DOMAIN_INFO", /* 0x00da */
262 "NT_STATUS_CANT_TERMINATE_SELF", /* 0x00db */
263 "NT_STATUS_INVALID_SERVER_STATE", /* 0x00dc */
264 "NT_STATUS_INVALID_DOMAIN_STATE", /* 0x00dd */
265 "NT_STATUS_INVALID_DOMAIN_ROLE", /* 0x00de */
266 "NT_STATUS_NO_SUCH_DOMAIN", /* 0x00df */
267 "NT_STATUS_DOMAIN_EXISTS", /* 0x00e0 */
268 "NT_STATUS_DOMAIN_LIMIT_EXCEEDED", /* 0x00e1 */
269 "NT_STATUS_OPLOCK_NOT_GRANTED", /* 0x00e2 */
270 "NT_STATUS_INVALID_OPLOCK_PROTOCOL", /* 0x00e3 */
271 "NT_STATUS_INTERNAL_DB_CORRUPTION", /* 0x00e4 */
272 "NT_STATUS_INTERNAL_ERROR", /* 0x00e5 */
273 "NT_STATUS_GENERIC_NOT_MAPPED", /* 0x00e6 */
274 "NT_STATUS_BAD_DESCRIPTOR_FORMAT", /* 0x00e7 */
275 "NT_STATUS_INVALID_USER_BUFFER", /* 0x00e8 */
276 "NT_STATUS_UNEXPECTED_IO_ERROR", /* 0x00e9 */
277 "NT_STATUS_UNEXPECTED_MM_CREATE_ERR", /* 0x00ea */
278 "NT_STATUS_UNEXPECTED_MM_MAP_ERROR", /* 0x00eb */
279 "NT_STATUS_UNEXPECTED_MM_EXTEND_ERR", /* 0x00ec */
280 "NT_STATUS_NOT_LOGON_PROCESS", /* 0x00ed */
281 "NT_STATUS_LOGON_SESSION_EXISTS", /* 0x00ee */
282 "NT_STATUS_INVALID_PARAMETER_1", /* 0x00ef */
283 "NT_STATUS_INVALID_PARAMETER_2", /* 0x00f0 */
284 "NT_STATUS_INVALID_PARAMETER_3", /* 0x00f1 */
285 "NT_STATUS_INVALID_PARAMETER_4", /* 0x00f2 */
286 "NT_STATUS_INVALID_PARAMETER_5", /* 0x00f3 */
287 "NT_STATUS_INVALID_PARAMETER_6", /* 0x00f4 */
288 "NT_STATUS_INVALID_PARAMETER_7", /* 0x00f5 */
289 "NT_STATUS_INVALID_PARAMETER_8", /* 0x00f6 */
290 "NT_STATUS_INVALID_PARAMETER_9", /* 0x00f7 */
291 "NT_STATUS_INVALID_PARAMETER_10", /* 0x00f8 */
292 "NT_STATUS_INVALID_PARAMETER_11", /* 0x00f9 */
293 "NT_STATUS_INVALID_PARAMETER_12", /* 0x00fa */
294 "NT_STATUS_REDIRECTOR_NOT_STARTED", /* 0x00fb */
295 "NT_STATUS_REDIRECTOR_STARTED", /* 0x00fc */
296 "NT_STATUS_STACK_OVERFLOW", /* 0x00fd */
297 "NT_STATUS_NO_SUCH_PACKAGE", /* 0x00fe */
298 "NT_STATUS_BAD_FUNCTION_TABLE", /* 0x00ff */
299 "NT_STATUS_DIRECTORY_NOT_EMPTY", /* 0x0101 */
300 "NT_STATUS_FILE_CORRUPT_ERROR", /* 0x0102 */
301 "NT_STATUS_NOT_A_DIRECTORY", /* 0x0103 */
302 "NT_STATUS_BAD_LOGON_SESSION_STATE", /* 0x0104 */
303 "NT_STATUS_LOGON_SESSION_COLLISION", /* 0x0105 */
304 "NT_STATUS_NAME_TOO_LONG", /* 0x0106 */
305 "NT_STATUS_FILES_OPEN", /* 0x0107 */
306 "NT_STATUS_CONNECTION_IN_USE", /* 0x0108 */
307 "NT_STATUS_MESSAGE_NOT_FOUND", /* 0x0109 */
308 "NT_STATUS_PROCESS_IS_TERMINATING", /* 0x010a */
309 "NT_STATUS_INVALID_LOGON_TYPE", /* 0x010b */
310 "NT_STATUS_NO_GUID_TRANSLATION", /* 0x010c */
311 "NT_STATUS_CANNOT_IMPERSONATE", /* 0x010d */
312 "NT_STATUS_IMAGE_ALREADY_LOADED", /* 0x010e */
313 "NT_STATUS_ABIOS_NOT_PRESENT", /* 0x010f */
314 "NT_STATUS_ABIOS_LID_NOT_EXIST", /* 0x0110 */
315 "NT_STATUS_ABIOS_LID_ALREADY_OWNED", /* 0x0111 */
316 "NT_STATUS_ABIOS_NOT_LID_OWNER", /* 0x0112 */
317 "NT_STATUS_ABIOS_INVALID_COMMAND", /* 0x0113 */
318 "NT_STATUS_ABIOS_INVALID_LID", /* 0x0114 */
319 "NT_STATUS_ABIOS_SELECTOR_NOT_AVAILABLE", /* 0x0115 */
320 "NT_STATUS_ABIOS_INVALID_SELECTOR", /* 0x0116 */
321 "NT_STATUS_NO_LDT", /* 0x0117 */
322 "NT_STATUS_INVALID_LDT_SIZE", /* 0x0118 */
323 "NT_STATUS_INVALID_LDT_OFFSET", /* 0x0119 */
324 "NT_STATUS_INVALID_LDT_DESCRIPTOR", /* 0x011a */
325 "NT_STATUS_INVALID_IMAGE_NE_FORMAT", /* 0x011b */
326 "NT_STATUS_RXACT_INVALID_STATE", /* 0x011c */
327 "NT_STATUS_RXACT_COMMIT_FAILURE", /* 0x011d */
328 "NT_STATUS_MAPPED_FILE_SIZE_ZERO", /* 0x011e */
329 "NT_STATUS_TOO_MANY_OPENED_FILES", /* 0x011f */
330 "NT_STATUS_CANCELLED", /* 0x0120 */
331 "NT_STATUS_CANNOT_DELETE", /* 0x0121 */
332 "NT_STATUS_INVALID_COMPUTER_NAME", /* 0x0122 */
333 "NT_STATUS_FILE_DELETED", /* 0x0123 */
334 "NT_STATUS_SPECIAL_ACCOUNT", /* 0x0124 */
335 "NT_STATUS_SPECIAL_GROUP", /* 0x0125 */
336 "NT_STATUS_SPECIAL_USER", /* 0x0126 */
337 "NT_STATUS_MEMBERS_PRIMARY_GROUP", /* 0x0127 */
338 "NT_STATUS_FILE_CLOSED", /* 0x0128 */
339 "NT_STATUS_TOO_MANY_THREADS", /* 0x0129 */
340 "NT_STATUS_THREAD_NOT_IN_PROCESS", /* 0x012a */
341 "NT_STATUS_TOKEN_ALREADY_IN_USE", /* 0x012b */
342 "NT_STATUS_PAGEFILE_QUOTA_EXCEEDED", /* 0x012c */
343 "NT_STATUS_COMMITMENT_LIMIT", /* 0x012d */
344 "NT_STATUS_INVALID_IMAGE_LE_FORMAT", /* 0x012e */
345 "NT_STATUS_INVALID_IMAGE_NOT_MZ", /* 0x012f */
346 "NT_STATUS_INVALID_IMAGE_PROTECT", /* 0x0130 */
347 "NT_STATUS_INVALID_IMAGE_WIN_16", /* 0x0131 */
348 "NT_STATUS_LOGON_SERVER_CONFLICT", /* 0x0132 */
349 "NT_STATUS_TIME_DIFFERENCE_AT_DC", /* 0x0133 */
350 "NT_STATUS_SYNCHRONIZATION_REQUIRED", /* 0x0134 */
351 "NT_STATUS_DLL_NOT_FOUND", /* 0x0135 */
352 "NT_STATUS_OPEN_FAILED", /* 0x0136 */
353 "NT_STATUS_IO_PRIVILEGE_FAILED", /* 0x0137 */
354 "NT_STATUS_ORDINAL_NOT_FOUND", /* 0x0138 */
355 "NT_STATUS_ENTRYPOINT_NOT_FOUND", /* 0x0139 */
356 "NT_STATUS_CONTROL_C_EXIT", /* 0x013a */
357 "NT_STATUS_LOCAL_DISCONNECT", /* 0x013b */
358 "NT_STATUS_REMOTE_DISCONNECT", /* 0x013c */
359 "NT_STATUS_REMOTE_RESOURCES", /* 0x013d */
360 "NT_STATUS_LINK_FAILED", /* 0x013e */
361 "NT_STATUS_LINK_TIMEOUT", /* 0x013f */
362 "NT_STATUS_INVALID_CONNECTION", /* 0x0140 */
363 "NT_STATUS_INVALID_ADDRESS", /* 0x0141 */
364 "NT_STATUS_DLL_INIT_FAILED", /* 0x0142 */
365 "NT_STATUS_MISSING_SYSTEMFILE", /* 0x0143 */
366 "NT_STATUS_UNHANDLED_EXCEPTION", /* 0x0144 */
367 "NT_STATUS_APP_INIT_FAILURE", /* 0x0145 */
368 "NT_STATUS_PAGEFILE_CREATE_FAILED", /* 0x0146 */
369 "NT_STATUS_NO_PAGEFILE", /* 0x0147 */
370 "NT_STATUS_INVALID_LEVEL", /* 0x0148 */
371 "NT_STATUS_WRONG_PASSWORD_CORE", /* 0x0149 */
372 "NT_STATUS_ILLEGAL_FLOAT_CONTEXT", /* 0x014a */
373 "NT_STATUS_PIPE_BROKEN", /* 0x014b */
374 "NT_STATUS_REGISTRY_CORRUPT", /* 0x014c */
375 "NT_STATUS_REGISTRY_IO_FAILED", /* 0x014d */
376 "NT_STATUS_NO_EVENT_PAIR", /* 0x014e */
377 "NT_STATUS_UNRECOGNIZED_VOLUME", /* 0x014f */
378 "NT_STATUS_SERIAL_NO_DEVICE_INITED", /* 0x0150 */
379 "NT_STATUS_NO_SUCH_ALIAS", /* 0x0151 */
380 "NT_STATUS_MEMBER_NOT_IN_ALIAS", /* 0x0152 */
381 "NT_STATUS_MEMBER_IN_ALIAS", /* 0x0153 */
382 "NT_STATUS_ALIAS_EXISTS", /* 0x0154 */
383 "NT_STATUS_LOGON_NOT_GRANTED", /* 0x0155 */
384 "NT_STATUS_TOO_MANY_SECRETS", /* 0x0156 */
385 "NT_STATUS_SECRET_TOO_LONG", /* 0x0157 */
386 "NT_STATUS_INTERNAL_DB_ERROR", /* 0x0158 */
387 "NT_STATUS_FULLSCREEN_MODE", /* 0x0159 */
388 "NT_STATUS_TOO_MANY_CONTEXT_IDS", /* 0x015a */
389 "NT_STATUS_LOGON_TYPE_NOT_GRANTED", /* 0x015b */
390 "NT_STATUS_NOT_REGISTRY_FILE", /* 0x015c */
391 "NT_STATUS_NT_CROSS_ENCRYPTION_REQUIRED", /* 0x015d */
392 "NT_STATUS_DOMAIN_CTRLR_CONFIG_ERROR", /* 0x015e */
393 "NT_STATUS_FT_MISSING_MEMBER", /* 0x015f */
394 "NT_STATUS_ILL_FORMED_SERVICE_ENTRY", /* 0x0160 */
395 "NT_STATUS_ILLEGAL_CHARACTER", /* 0x0161 */
396 "NT_STATUS_UNMAPPABLE_CHARACTER", /* 0x0162 */
397 "NT_STATUS_UNDEFINED_CHARACTER", /* 0x0163 */
398 "NT_STATUS_FLOPPY_VOLUME", /* 0x0164 */
399 "NT_STATUS_FLOPPY_ID_MARK_NOT_FOUND", /* 0x0165 */
400 "NT_STATUS_FLOPPY_WRONG_CYLINDER", /* 0x0166 */
401 "NT_STATUS_FLOPPY_UNKNOWN_ERROR", /* 0x0167 */
402 "NT_STATUS_FLOPPY_BAD_REGISTERS", /* 0x0168 */
403 "NT_STATUS_DISK_RECALIBRATE_FAILED", /* 0x0169 */
404 "NT_STATUS_DISK_OPERATION_FAILED", /* 0x016a */
405 "NT_STATUS_DISK_RESET_FAILED", /* 0x016b */
406 "NT_STATUS_SHARED_IRQ_BUSY", /* 0x016c */
407 "NT_STATUS_FT_ORPHANING", /* 0x016d */
408 "NT_STATUS_PARTITION_FAILURE", /* 0x0172 */
409 "NT_STATUS_INVALID_BLOCK_LENGTH", /* 0x0173 */
410 "NT_STATUS_DEVICE_NOT_PARTITIONED", /* 0x0174 */
411 "NT_STATUS_UNABLE_TO_LOCK_MEDIA", /* 0x0175 */
412 "NT_STATUS_UNABLE_TO_UNLOAD_MEDIA", /* 0x0176 */
413 "NT_STATUS_EOM_OVERFLOW", /* 0x0177 */
414 "NT_STATUS_NO_MEDIA", /* 0x0178 */
415 "NT_STATUS_NO_SUCH_MEMBER", /* 0x017a */
416 "NT_STATUS_INVALID_MEMBER", /* 0x017b */
417 "NT_STATUS_KEY_DELETED", /* 0x017c */
418 "NT_STATUS_NO_LOG_SPACE", /* 0x017d */
419 "NT_STATUS_TOO_MANY_SIDS", /* 0x017e */
420 "NT_STATUS_LM_CROSS_ENCRYPTION_REQUIRED", /* 0x017f */
421 "NT_STATUS_KEY_HAS_CHILDREN", /* 0x0180 */
422 "NT_STATUS_CHILD_MUST_BE_VOLATILE", /* 0x0181 */
423 "NT_STATUS_DEVICE_CONFIGURATION_ERROR", /* 0x0182 */
424 "NT_STATUS_DRIVER_INTERNAL_ERROR", /* 0x0183 */
425 "NT_STATUS_INVALID_DEVICE_STATE", /* 0x0184 */
426 "NT_STATUS_IO_DEVICE_ERROR", /* 0x0185 */
427 "NT_STATUS_DEVICE_PROTOCOL_ERROR", /* 0x0186 */
428 "NT_STATUS_BACKUP_CONTROLLER", /* 0x0187 */
429 "NT_STATUS_LOG_FILE_FULL", /* 0x0188 */
430 "NT_STATUS_TOO_LATE", /* 0x0189 */
431 "NT_STATUS_NO_TRUST_LSA_SECRET", /* 0x018a */
432 "NT_STATUS_NO_TRUST_SAM_ACCOUNT", /* 0x018b */
433 "NT_STATUS_TRUSTED_DOMAIN_FAILURE", /* 0x018c */
434 "NT_STATUS_TRUSTED_RELATIONSHIP_FAILURE", /* 0x018d */
435 "NT_STATUS_EVENTLOG_FILE_CORRUPT", /* 0x018e */
436 "NT_STATUS_EVENTLOG_CANT_START", /* 0x018f */
437 "NT_STATUS_TRUST_FAILURE", /* 0x0190 */
438 "NT_STATUS_MUTANT_LIMIT_EXCEEDED", /* 0x0191 */
439 "NT_STATUS_NETLOGON_NOT_STARTED", /* 0x0192 */
440 "NT_STATUS_ACCOUNT_EXPIRED", /* 0x0193 */
441 "NT_STATUS_POSSIBLE_DEADLOCK", /* 0x0194 */
442 "NT_STATUS_NETWORK_CREDENTIAL_CONFLICT", /* 0x0195 */
443 "NT_STATUS_REMOTE_SESSION_LIMIT", /* 0x0196 */
444 "NT_STATUS_EVENTLOG_FILE_CHANGED", /* 0x0197 */
445 "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT", /* 0x0198 */
446 "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT", /* 0x0199 */
447 "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT", /* 0x019a */
448 "NT_STATUS_DOMAIN_TRUST_INCONSISTENT", /* 0x019b */
449 "NT_STATUS_FS_DRIVER_REQUIRED", /* 0x019c */
450 "NT_STATUS_NO_USER_SESSION_KEY", /* 0x0202 */
451 "NT_STATUS_USER_SESSION_DELETED", /* 0x0203 */
452 "NT_STATUS_RESOURCE_LANG_NOT_FOUND", /* 0x0204 */
453 "NT_STATUS_INSUFF_SERVER_RESOURCES", /* 0x0205 */
454 "NT_STATUS_INVALID_BUFFER_SIZE", /* 0x0206 */
455 "NT_STATUS_INVALID_ADDRESS_COMPONENT", /* 0x0207 */
456 "NT_STATUS_INVALID_ADDRESS_WILDCARD", /* 0x0208 */
457 "NT_STATUS_TOO_MANY_ADDRESSES", /* 0x0209 */
458 "NT_STATUS_ADDRESS_ALREADY_EXISTS", /* 0x020a */
459 "NT_STATUS_ADDRESS_CLOSED", /* 0x020b */
460 "NT_STATUS_CONNECTION_DISCONNECTED", /* 0x020c */
461 "NT_STATUS_CONNECTION_RESET", /* 0x020d */
462 "NT_STATUS_TOO_MANY_NODES", /* 0x020e */
463 "NT_STATUS_TRANSACTION_ABORTED", /* 0x020f */
464 "NT_STATUS_TRANSACTION_TIMED_OUT", /* 0x0210 */
465 "NT_STATUS_TRANSACTION_NO_RELEASE", /* 0x0211 */
466 "NT_STATUS_TRANSACTION_NO_MATCH", /* 0x0212 */
467 "NT_STATUS_TRANSACTION_RESPONDED", /* 0x0213 */
468 "NT_STATUS_TRANSACTION_INVALID_ID", /* 0x0214 */
469 "NT_STATUS_TRANSACTION_INVALID_TYPE", /* 0x0215 */
470 "NT_STATUS_NOT_SERVER_SESSION", /* 0x0216 */
471 "NT_STATUS_NOT_CLIENT_SESSION", /* 0x0217 */
472 "NT_STATUS_CANNOT_LOAD_REGISTRY_FILE", /* 0x0218 */
473 "NT_STATUS_DEBUG_ATTACH_FAILED", /* 0x0219 */
474 "NT_STATUS_SYSTEM_PROCESS_TERMINATED", /* 0x021a */
475 "NT_STATUS_DATA_NOT_ACCEPTED", /* 0x021b */
476 "NT_STATUS_NO_BROWSER_SERVERS_FOUND", /* 0x021c */
477 "NT_STATUS_VDM_HARD_ERROR", /* 0x021d */
478 "NT_STATUS_DRIVER_CANCEL_TIMEOUT", /* 0x021e */
479 "NT_STATUS_REPLY_MESSAGE_MISMATCH", /* 0x021f */
480 "NT_STATUS_MAPPED_ALIGNMENT", /* 0x0220 */
481 "NT_STATUS_IMAGE_CHECKSUM_MISMATCH", /* 0x0221 */
482 "NT_STATUS_LOST_WRITEBEHIND_DATA", /* 0x0222 */
483 "NT_STATUS_CLIENT_SERVER_PARAMETERS_INVALID", /* 0x0223 */
484 "NT_STATUS_PASSWORD_MUST_CHANGE", /* 0x0224 */
485 "NT_STATUS_NOT_FOUND", /* 0x0225 */
486 "NT_STATUS_NOT_TINY_STREAM", /* 0x0226 */
487 "NT_STATUS_RECOVERY_FAILURE", /* 0x0227 */
488 "NT_STATUS_STACK_OVERFLOW_READ", /* 0x0228 */
489 "NT_STATUS_FAIL_CHECK", /* 0x0229 */
490 "NT_STATUS_DUPLICATE_OBJECTID", /* 0x022a */
491 "NT_STATUS_OBJECTID_EXISTS", /* 0x022b */
492 "NT_STATUS_CONVERT_TO_LARGE", /* 0x022c */
493 "NT_STATUS_RETRY", /* 0x022d */
494 "NT_STATUS_FOUND_OUT_OF_SCOPE", /* 0x022e */
495 "NT_STATUS_ALLOCATE_BUCKET", /* 0x022f */
496 "NT_STATUS_PROPSET_NOT_FOUND", /* 0x0230 */
497 "NT_STATUS_MARSHALL_OVERFLOW", /* 0x0231 */
498 "NT_STATUS_INVALID_VARIANT", /* 0x0232 */
499 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND", /* 0x0233 */
500 "NT_STATUS_ACCOUNT_LOCKED_OUT", /* 0x0234 */
501 "NT_STATUS_HANDLE_NOT_CLOSABLE", /* 0x0235 */
502 "NT_STATUS_CONNECTION_REFUSED", /* 0x0236 */
503 "NT_STATUS_GRACEFUL_DISCONNECT", /* 0x0237 */
504 "NT_STATUS_ADDRESS_ALREADY_ASSOCIATED", /* 0x0238 */
505 "NT_STATUS_ADDRESS_NOT_ASSOCIATED", /* 0x0239 */
506 "NT_STATUS_CONNECTION_INVALID", /* 0x023a */
507 "NT_STATUS_CONNECTION_ACTIVE", /* 0x023b */
508 "NT_STATUS_NETWORK_UNREACHABLE", /* 0x023c */
509 "NT_STATUS_HOST_UNREACHABLE", /* 0x023d */
510 "NT_STATUS_PROTOCOL_UNREACHABLE", /* 0x023e */
511 "NT_STATUS_PORT_UNREACHABLE", /* 0x023f */
512 "NT_STATUS_REQUEST_ABORTED", /* 0x0240 */
513 "NT_STATUS_CONNECTION_ABORTED", /* 0x0241 */
514 "NT_STATUS_BAD_COMPRESSION_BUFFER", /* 0x0242 */
515 "NT_STATUS_USER_MAPPED_FILE", /* 0x0243 */
516 "NT_STATUS_AUDIT_FAILED", /* 0x0244 */
517 "NT_STATUS_TIMER_RESOLUTION_NOT_SET", /* 0x0245 */
518 "NT_STATUS_CONNECTION_COUNT_LIMIT", /* 0x0246 */
519 "NT_STATUS_LOGIN_TIME_RESTRICTION", /* 0x0247 */
520 "NT_STATUS_LOGIN_WKSTA_RESTRICTION", /* 0x0248 */
521 "NT_STATUS_IMAGE_MP_UP_MISMATCH", /* 0x0249 */
522 "NT_STATUS_INSUFFICIENT_LOGON_INFO", /* 0x0250 */
523 "NT_STATUS_BAD_DLL_ENTRYPOINT", /* 0x0251 */
524 "NT_STATUS_BAD_SERVICE_ENTRYPOINT", /* 0x0252 */
525 "NT_STATUS_LPC_REPLY_LOST", /* 0x0253 */
526 "NT_STATUS_IP_ADDRESS_CONFLICT1", /* 0x0254 */
527 "NT_STATUS_IP_ADDRESS_CONFLICT2", /* 0x0255 */
528 "NT_STATUS_REGISTRY_QUOTA_LIMIT", /* 0x0256 */
529 "NT_STATUS_PATH_NOT_COVERED", /* 0x0257 */
530 "NT_STATUS_NO_CALLBACK_ACTIVE", /* 0x0258 */
531 "NT_STATUS_LICENSE_QUOTA_EXCEEDED", /* 0x0259 */
532 "NT_STATUS_PWD_TOO_SHORT", /* 0x025a */
533 "NT_STATUS_PWD_TOO_RECENT", /* 0x025b */
534 "NT_STATUS_PWD_HISTORY_CONFLICT", /* 0x025c */
535 "NT_STATUS_PLUGPLAY_NO_DEVICE", /* 0x025e */
536 "NT_STATUS_UNSUPPORTED_COMPRESSION", /* 0x025f */
537 "NT_STATUS_INVALID_HW_PROFILE", /* 0x0260 */
538 "NT_STATUS_INVALID_PLUGPLAY_DEVICE_PATH", /* 0x0261 */
539 "NT_STATUS_DRIVER_ORDINAL_NOT_FOUND", /* 0x0262 */
540 "NT_STATUS_DRIVER_ENTRYPOINT_NOT_FOUND", /* 0x0263 */
541 "NT_STATUS_RESOURCE_NOT_OWNED", /* 0x0264 */
542 "NT_STATUS_TOO_MANY_LINKS", /* 0x0265 */
543 "NT_STATUS_QUOTA_LIST_INCONSISTENT", /* 0x0266 */
544 "NT_STATUS_FILE_IS_OFFLINE" /* 0x0267 */
547 #define NT_STATUS(a) nt_status_to_string[a & 0x3FFFFFFF]
549 struct Packet
551 size_t frame;
553 uint8_t magic[4];
555 bool valid_smb() {
556 return !memcmp(smb_hdr.magic, magic, 4);
559 Packet(const uint8_t *data, size_t size) :
560 ip_hdr(data + 14, size - 14),
561 tcp_hdr(data + 14 + ip_hdr.header_length,
562 size - 14 - ip_hdr.header_length),
563 smb_hdr(data + 14 + ip_hdr.header_length + tcp_hdr.length,
564 size - 14 - ip_hdr.header_length - tcp_hdr.length)
566 const uint8_t da[] = { 0xFF, 'S', 'M', 'B' };
568 memcpy(magic, da, sizeof(da));
570 if (valid_smb()) {
571 size_t len = 14 + ip_hdr.header_length + tcp_hdr.length + 36;
573 switch (smb_hdr.command) {
574 case NtCreateAndXRequest::COMMAND:
575 if (smb_hdr.flags & 0x80) {
576 ntcreate_resp = NtCreateAndXResponse(data+len, size - len);
577 } else {
578 ntcreate_req = NtCreateAndXRequest(data + len, size - len);
580 break;
581 case ReadAndXRequest::COMMAND:
582 if (!(smb_hdr.flags & 0x80)) {
583 read_req = ReadAndXRequest(data + len, size - len);
585 break;
586 case WriteAndXRequest::COMMAND:
587 if (!(smb_hdr.flags & 0x80)) {
588 write_req = WriteAndXRequest(data + len, size - len);
590 break;
591 case CloseRequest::COMMAND:
592 if (!(smb_hdr.flags & 0x80)) {
593 close_req = CloseRequest(data + len, size - len);
595 break;
600 ip ip_hdr;
601 tcp tcp_hdr;
602 smb smb_hdr;
604 NtCreateAndXRequest ntcreate_req;
605 NtCreateAndXResponse ntcreate_resp;
606 ReadAndXRequest read_req;
607 WriteAndXRequest write_req;
608 CloseRequest close_req;
611 int main(int argc, char **argv)
613 char errbuf[PCAP_ERRBUF_SIZE];
614 pcap_t *cap;
615 struct pcap_pkthdr *pkt_hdr;
616 const uint8_t *data;
618 static struct option long_opts[] = {
619 { "show-files", 0, 0, 's' },
620 { "drop-incomplete-sessions", 0, 0, 'i' },
621 { 0, 0, 0, 0 }
623 const char *short_opts = "si";
624 int opt_ind;
625 char ch;
626 int show_files = 0;
627 int drop_incomplete_sessions = 0;
629 while ((ch = getopt_long(argc,argv,short_opts,long_opts,&opt_ind)) != -1) {
630 switch (ch) {
631 case 's':
632 show_files = 1;
633 break;
634 case 'i':
635 drop_incomplete_sessions = 1;
636 break;
637 default:
638 break;
642 if ((argc - optind) != 1) {
643 std::cout << "Usage: " << argv[0] << " [OPTIONS] FILE" << std::endl;
644 exit(1);
647 cap = pcap_open_offline(argv[optind], errbuf);
649 if (!cap) {
650 std::cout << "pcap_open_offline(" << argv[optind] << "): " << errbuf
651 << std::endl;
652 exit(1);
655 std::vector<Packet> packets;
656 size_t frame = 0;
657 std::set<uint16_t> current_fids;
659 while (1 == pcap_next_ex(cap, &pkt_hdr, &data)) {
660 Packet packet(data, pkt_hdr->len);
662 ++frame;
664 if (packet.valid_smb()) {
665 packet.frame = frame;
666 packets.push_back(packet);
670 pcap_close(cap);
672 for (std::vector<Packet>::iterator i = packets.begin();
673 i != packets.end(); ++i) {
674 if (!(i->smb_hdr.flags & 0x80)) {
675 /* we have a request */
676 std::vector<Packet>::iterator j;
678 /* look ahead for the response */
679 for (j = i; j != packets.end(); ++j) {
680 if (j->smb_hdr.flags & 0x80 && // response
681 j->smb_hdr.command == i->smb_hdr.command &&
682 j->smb_hdr.tid == i->smb_hdr.tid &&
683 j->smb_hdr.pid == i->smb_hdr.pid &&
684 j->smb_hdr.uid == i->smb_hdr.uid &&
685 j->smb_hdr.mid == i->smb_hdr.mid) {
686 break;
690 /* no response? guess we can't display this command */
691 if (j == packets.end()) continue;
693 size_t len;
695 switch (i->smb_hdr.command) {
696 case NtCreateAndXRequest::COMMAND:
697 std::cout << "NTCreateX \"" << i->ntcreate_req.file_name << "\" "
698 << i->ntcreate_req.create_options << " "
699 << i->ntcreate_req.disposition << " "
700 << j->ntcreate_resp.fid << " "
701 << NT_STATUS(j->smb_hdr.nt_status) << std::endl;
702 current_fids.insert(j->ntcreate_resp.fid);
703 break;
704 case ReadAndXRequest::COMMAND:
705 len = i->read_req.max_count_high * 64 * 1024 +
706 i->read_req.max_count_low;
708 if (!drop_incomplete_sessions || current_fids.count(i->read_req.fid)) {
709 std::cout << "ReadX " << i->read_req.fid << " "
710 << i->read_req.offset << " "
711 << len << " " << len << " "
712 << NT_STATUS(j->smb_hdr.nt_status) << std::endl;
714 break;
715 case WriteAndXRequest::COMMAND:
716 len = i->write_req.data_length_hi * 64 * 1024 +
717 i->write_req.data_length_lo;
719 if (!drop_incomplete_sessions||current_fids.count(i->write_req.fid)) {
720 std::cout << "WriteX " << i->write_req.fid << " "
721 << i->write_req.offset << " "
722 << len << " " << len << " "
723 << NT_STATUS(j->smb_hdr.nt_status) << std::endl;
725 break;
726 case CloseRequest::COMMAND:
727 if (!drop_incomplete_sessions||current_fids.count(i->close_req.fid)) {
728 std::cout << "Close " << i->close_req.fid << " "
729 << NT_STATUS(j->smb_hdr.nt_status) << std::endl;
731 current_fids.erase(i->close_req.fid);
732 break;
737 return 0;