1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
|
/* packet-dcerpc-ndr.c
* Routines for DCERPC NDR dissection
* Copyright 2001, Todd Sabin <tas@webspan.net>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <epan/packet.h>
#include "packet-dcerpc.h"
/*
* The NDR routines are for use by dcerpc subdissetors. They're
* primarily for making sure things are aligned properly according
* to the rules of NDR.
*/
int
dissect_ndr_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint8 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
/* no alignment needed */
return dissect_dcerpc_uint8(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
int
PIDL_dissect_uint8_val(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param, guint8 *pval)
{
guint8 val;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
/* no alignment needed */
offset = dissect_dcerpc_uint8(tvb, offset, pinfo,
tree, drep, hfindex, &val);
if (param&PIDL_SET_COL_INFO) {
header_field_info *hf_info;
char *valstr;
hf_info = proto_registrar_get_nth(hfindex);
valstr = (char *)wmem_alloc(pinfo->pool, 64);
valstr[0]=0;
switch (hf_info->display) {
case BASE_DEC:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(%d)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "%d", val);
}
break;
case BASE_HEX:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(0x%02x)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "0x%02x", val);
}
break;
default:
REPORT_DISSECTOR_BUG("Invalid hf->display value");
}
col_append_fstr(pinfo->cinfo, COL_INFO," %s:%s", hf_info->name, valstr);
}
if (pval) {
*pval = val;
}
return offset;
}
int
PIDL_dissect_uint8(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param)
{
return PIDL_dissect_uint8_val(tvb, offset, pinfo, tree, di, drep, hfindex, param, NULL);
}
int
dissect_ndr_uint16(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint16 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 2)) {
offset++;
}
return dissect_dcerpc_uint16(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
int
PIDL_dissect_uint16_val(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param, guint16 *pval)
{
guint16 val;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 2)) {
offset++;
}
offset = dissect_dcerpc_uint16(tvb, offset, pinfo,
tree, drep, hfindex, &val);
if (param&PIDL_SET_COL_INFO) {
header_field_info *hf_info;
char *valstr;
hf_info = proto_registrar_get_nth(hfindex);
valstr = (char *)wmem_alloc(pinfo->pool, 64);
valstr[0]=0;
switch (hf_info->display) {
case BASE_DEC:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(%d)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "%d", val);
}
break;
case BASE_HEX:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(0x%04x)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "0x%04x", val);
}
break;
default:
REPORT_DISSECTOR_BUG("Invalid hf->display value");
}
col_append_fstr(pinfo->cinfo, COL_INFO," %s:%s", hf_info->name, valstr);
}
if (pval) {
*pval = val;
}
return offset;
}
int
PIDL_dissect_uint16(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param)
{
return PIDL_dissect_uint16_val(tvb, offset, pinfo, tree, di, drep, hfindex, param, NULL);
}
int
dissect_ndr_uint32(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if ((di != NULL) && (di->conformant_run)) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if ((di != NULL) && (!di->no_align) && (offset % 4)) {
offset += 4 - (offset % 4);
}
return dissect_dcerpc_uint32(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
/* This is used to dissect the new datatypes, such as pointers and conformance
data, which is 4 bytes in size in NDR but 8 bytes in NDR64.
*/
int
dissect_ndr_uint3264(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint3264 *pdata)
{
if (di->call_data->flags & DCERPC_IS_NDR64) {
return dissect_ndr_uint64(tvb, offset, pinfo, tree, di, drep, hfindex, pdata);
} else {
guint32 val = 0;
offset = dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hfindex, &val);
if (pdata) {
*pdata = val;
}
return offset;
}
}
/* This is used to dissect the new datatypes, such as enums
that are 2 bytes in size in NDR but 4 bytes in NDR64.
*/
int
dissect_ndr_uint1632(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint1632 *pdata)
{
if (di->call_data->flags & DCERPC_IS_NDR64) {
return dissect_ndr_uint32(tvb, offset, pinfo, tree, di, drep, hfindex, pdata);
} else {
guint16 val = 0;
offset = dissect_ndr_uint16(tvb, offset, pinfo, tree, di, drep, hfindex, &val);
if (pdata) {
*pdata = val;
}
return offset;
}
}
int
PIDL_dissect_uint32_val(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param, guint32 *rval)
{
guint32 val;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
offset = dissect_dcerpc_uint32(tvb, offset, pinfo,
tree, drep, hfindex, &val);
if (param&PIDL_SET_COL_INFO) {
header_field_info *hf_info;
char *valstr;
hf_info = proto_registrar_get_nth(hfindex);
valstr = (char *)wmem_alloc(pinfo->pool, 64);
valstr[0]=0;
switch (hf_info->display) {
case BASE_DEC:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(%d)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "%d", val);
}
break;
case BASE_HEX:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(0x%08x)",val_to_str(val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "0x%08x", val);
}
break;
default:
REPORT_DISSECTOR_BUG("Invalid hf->display value");
}
col_append_fstr(pinfo->cinfo, COL_INFO," %s:%s", hf_info->name, valstr);
}
if (rval != NULL) {
*rval = val;
}
return offset;
}
int
PIDL_dissect_uint32(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param)
{
return PIDL_dissect_uint32_val(tvb, offset, pinfo, tree, di, drep, hfindex, param, NULL);
}
/* Double uint32
This function dissects the 64bit datatype that is common for
ms interfaces and which is 32bit aligned.
It is really just 2 uint32's
*/
int
dissect_ndr_duint32(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint64 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
return dissect_dcerpc_uint64(tvb, offset, pinfo,
tree, di, drep, hfindex, pdata);
}
/* uint64 : hyper
a 64 bit integer aligned to proper 8 byte boundaries
*/
int
dissect_ndr_uint64(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint64 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 8)) {
gint padding = 8 - (offset % 8);
proto_tree_add_item(tree, hf_dcerpc_ndr_padding, tvb, offset, padding, ENC_NA);
offset += padding;
}
return dissect_dcerpc_uint64(tvb, offset, pinfo,
tree, di, drep, hfindex, pdata);
}
int
PIDL_dissect_uint64_val(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param, guint64 *pval)
{
guint64 val;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 8)) {
offset += 8 - (offset % 8);
}
offset = dissect_dcerpc_uint64(tvb, offset, pinfo,
tree, di, drep, hfindex, &val);
if (param&PIDL_SET_COL_INFO) {
header_field_info *hf_info;
char *valstr;
hf_info = proto_registrar_get_nth(hfindex);
valstr = (char *)wmem_alloc(pinfo->pool, 64);
valstr[0]=0;
switch (hf_info->display) {
case BASE_DEC:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(%" PRIu64 ")",val_to_str( (guint32) val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "%" PRIu64, val);
}
break;
case BASE_HEX:
if (hf_info->strings) {
snprintf(valstr, 64, "%s(0x%" PRIx64 ")",val_to_str( (guint32) val, (const value_string *)hf_info->strings, "Unknown:%u"), val);
} else {
snprintf(valstr, 64, "0x%" PRIx64, val);
}
break;
default:
REPORT_DISSECTOR_BUG("Invalid hf->display value");
}
col_append_fstr(pinfo->cinfo, COL_INFO," %s:%s", hf_info->name, valstr);
}
if (pval) {
*pval = val;
}
return offset;
}
int
PIDL_dissect_uint64(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 param)
{
return PIDL_dissect_uint64_val(tvb, offset, pinfo, tree, di, drep, hfindex, param, NULL);
}
int
dissect_ndr_float(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, gfloat *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
return dissect_dcerpc_float(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
int
dissect_ndr_double(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, gdouble *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 8)) {
offset += 8 - (offset % 8);
}
return dissect_dcerpc_double(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
/* handles unix 32 bit time_t */
int
dissect_ndr_time_t(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, guint32 *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
*pdata = 0;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
return dissect_dcerpc_time_t(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
int
dissect_ndr_uuid_t(tvbuff_t *tvb, gint offset, packet_info *pinfo,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, e_guid_t *pdata)
{
/* Some callers expect us to initialize pdata, even in error conditions, so
* do it right away in case we forget later */
if (pdata)
memset(pdata, 0, sizeof(*pdata));
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
/* uuid's are aligned to 4 bytes, due to initial uint32 in struct */
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
return dissect_dcerpc_uuid_t(tvb, offset, pinfo,
tree, drep, hfindex, pdata);
}
/*
* XXX - at least according to the DCE RPC 1.1 "nbase.idl", an
* "ndr_context_handle" is an unsigned32 "context_handle_attributes"
* and a uuid_t "context_handle_uuid". The attributes do not appear to
* be used, and always appear to be set to 0, in the DCE RPC 1.1 code.
*
* Should we display an "ndr_context_handle" with a tree holding the
* attributes and the uuid_t?
*/
int
dissect_ndr_ctx_hnd(tvbuff_t *tvb, gint offset, packet_info *pinfo _U_,
proto_tree *tree, dcerpc_info *di, guint8 *drep,
int hfindex, e_ctx_hnd *pdata)
{
static e_ctx_hnd ctx_hnd;
if (di->conformant_run) {
/* just a run to handle conformant arrays, no scalars to dissect */
return offset;
}
if (!di->no_align && (offset % 4)) {
offset += 4 - (offset % 4);
}
ctx_hnd.attributes = dcerpc_tvb_get_ntohl(tvb, offset, drep);
dcerpc_tvb_get_uuid(tvb, offset+4, drep, &ctx_hnd.uuid);
if (tree) {
/* Bytes is bytes - don't worry about the data representation */
proto_tree_add_item(tree, hfindex, tvb, offset, 20, ENC_NA);
}
if (pdata) {
*pdata = ctx_hnd;
}
return offset + 20;
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|