aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-dcom-dispatch.c
blob: 01b0c27cc87f6eb7e262c6b3c0127c0c8ee54584 (plain)
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
/* packet-dcom-dispatch.c
 * Routines for DCOM IDispatch
 *
 * $Id$
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@ethereal.com>
 * Copyright 1998 Gerald Combs
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

/* see packet-dcom.c for details about DCOM */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif


#include <glib.h>
#include <epan/packet.h>
#include "packet-dcerpc.h"
#include "packet-dcom.h"


static int hf_dispatch_opnum = -1;

static int hf_dispatch_riid = -1;
static int hf_dispatch_name = -1;
static int hf_dispatch_names = -1;
static int hf_dispatch_lcid = -1;
static int hf_dispatch_id = -1;
static int hf_dispatch_flags2 = -1;

static int hf_dispatch_arg = -1;
static int hf_dispatch_args = -1;
static int hf_dispatch_named_args = -1;
static int hf_dispatch_varref = -1;
static int hf_dispatch_varrefidx = -1;
static int hf_dispatch_varrefarg = -1;

static int hf_dispatch_varresult = -1;

static gint ett_dispatch_flags = -1;
static int hf_dispatch_flags = -1;
static int hf_dispatch_flags_method = -1;
static int hf_dispatch_flags_propget = -1;
static int hf_dispatch_flags_propput = -1;
static int hf_dispatch_flags_propputref = -1;

#define DISPATCH_FLAGS_METHOD		1
#define DISPATCH_FLAGS_PROPGET		2
#define DISPATCH_FLAGS_PROPPUT		4
#define DISPATCH_FLAGS_PROPPUTREF	8


static e_uuid_t uuid_dispatch = { 0x00020400, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
static guint16  ver_dispatch = 0;
static gint ett_dispatch = -1;
static int proto_dispatch = -1;



static int
dissect_IDispatch_GetIDsOfNames_rqst(tvbuff_t *tvb, int offset,
	packet_info *pinfo, proto_tree *tree, guint8 *drep)
{
	e_uuid_t riid;
	guint32 u32Lcid;
	gchar 	szName[1000] = { 0 };
	guint32 u32MaxNameLen = sizeof(szName);
	guint32	u32Names;
	guint32	u32ArraySize;
	guint32	u32Pointer;
	guint32	u32Tmp;
	guint32 u32VariableOffset;


    offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);

	offset = dissect_dcom_UUID(tvb, offset, pinfo, tree, drep, 
						hf_dispatch_riid, &riid);

	offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
						&u32ArraySize);

	u32VariableOffset = offset + u32ArraySize * 4;

	u32Tmp = u32ArraySize;
	while(u32Tmp--) {
		offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
					&u32Pointer);
		if (u32Pointer) {
			u32VariableOffset = dissect_dcom_LPWSTR(tvb, u32VariableOffset, pinfo, tree, drep, 
							hf_dispatch_name, szName, u32MaxNameLen);
			if (check_col(pinfo->cinfo, COL_INFO)) {
			  col_append_fstr(pinfo->cinfo, COL_INFO, " \"%s\"", szName);
			}
		}
	}

	offset = u32VariableOffset;

	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                        hf_dispatch_names, &u32Names);

	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
						hf_dispatch_lcid, &u32Lcid);

	return offset;
}



static int
dissect_IDispatch_GetIDsOfNames_resp(tvbuff_t *tvb, int offset,
	packet_info *pinfo, proto_tree *tree, guint8 *drep)
{
	guint32 u32DispId;
	guint32 u32ArraySize;
	guint32 u32Tmp;
	guint32 u32HResult;


    offset = dissect_dcom_that(tvb, offset, pinfo, tree, drep);

	offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
						&u32ArraySize);

	u32Tmp = u32ArraySize;
	while (u32Tmp--) {
		offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                        hf_dispatch_id, &u32DispId);
		if (check_col(pinfo->cinfo, COL_INFO)) {
		  col_append_fstr(pinfo->cinfo, COL_INFO, " ID=0x%08x", u32DispId);
		}
	}

	/* HRESULT of call */
	offset = dissect_dcom_HRESULT(tvb, offset, pinfo, tree, drep, 
                        &u32HResult);

	if (check_col(pinfo->cinfo, COL_INFO)) {
	  col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s", 
	  val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)") );
	}

	return offset;
}



static int
dissect_IDispatch_Invoke_rqst(tvbuff_t *tvb, int offset,
	packet_info *pinfo, proto_tree *tree, guint8 *drep)
{
	guint32 u32DispIdMember;
	e_uuid_t riid;
	guint32 u32Lcid;
	guint16 u16Flags;
	guint16 u16Flags2;
	guint32 u32Args;
	guint32 u32NamedArgs;
	guint32 u32Pointer;
	guint32 u32ArraySize;
	guint32 u32VariableOffset;
	guint32 u32VarRef;
	guint32 u32VarRefIdx;
	guint32 u32TmpOffset;

	proto_item *feature_item;
	proto_tree *feature_tree;


    offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);

	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_id, &u32DispIdMember);
	offset = dissect_dcom_UUID(tvb, offset, pinfo, tree, drep, 
					hf_dispatch_riid, &riid);
	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
					hf_dispatch_lcid, &u32Lcid);
	
	/* dispatch flags */
	u32TmpOffset = dissect_dcom_WORD(tvb, offset, pinfo, NULL, drep, 
                        hf_dispatch_flags, &u16Flags);
    feature_item = proto_tree_add_uint (tree, hf_dispatch_flags, tvb, offset, 2, u16Flags);
    feature_tree = proto_item_add_subtree (feature_item, ett_dispatch_flags);
    if (feature_tree) {
        proto_tree_add_boolean (feature_tree, hf_dispatch_flags_propputref, tvb, offset, 2, u16Flags);
        proto_tree_add_boolean (feature_tree, hf_dispatch_flags_propput, tvb, offset, 2, u16Flags);
        proto_tree_add_boolean (feature_tree, hf_dispatch_flags_propget, tvb, offset, 2, u16Flags);
        proto_tree_add_boolean (feature_tree, hf_dispatch_flags_method, tvb, offset, 2, u16Flags);
    }

	if (u16Flags & DISPATCH_FLAGS_METHOD) {
		proto_item_append_text(feature_item, ", Method");
	}
	if (u16Flags & DISPATCH_FLAGS_PROPGET) {
		proto_item_append_text(feature_item, ", PropertyGet");
	}
	if (u16Flags & DISPATCH_FLAGS_PROPPUT) {
		proto_item_append_text(feature_item, ", PropertyPut");
	}
	if (u16Flags & DISPATCH_FLAGS_PROPPUTREF) {
		proto_item_append_text(feature_item, ", PropertyPutRef");
	}

	offset = u32TmpOffset;

	offset = dissect_dcom_WORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_flags2, &u16Flags2);

	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);

	/* DISPPARAMS */
	/* VARIANT rgvarg[u32Args] */
	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
	if (u32Pointer) {
		offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
								&u32ArraySize);
		u32VariableOffset = offset + u32ArraySize * 4;
		while(u32ArraySize--) {
			offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
								&u32Pointer);
			if (u32Pointer) {
				u32VariableOffset = dissect_dcom_VARIANT(tvb, u32VariableOffset, pinfo, tree, drep, hf_dispatch_arg);
			}
		}
		offset = u32VariableOffset;
	}

	/* DISPID rgdispidNamedArgs[u32NamedArgs] */
	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
	if (u32Pointer) {
		offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
								&u32ArraySize);
		u32VariableOffset = offset + u32ArraySize * 4;
		while(u32ArraySize--) {
			u32VariableOffset = dissect_dcom_dcerpc_pointer(tvb, u32VariableOffset, pinfo, tree, drep, 
									&u32Pointer);
			if (u32Pointer) {
				offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
						hf_dispatch_id, &u32DispIdMember);
			}
		}
		offset = u32VariableOffset;
	}

	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_args, &u32Args);
	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_named_args, &u32NamedArgs);

	/* end of DISPPARAMS */
/*	offset = u32VariableOffset; */



	/* u32VarRef */
	offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_varref, &u32VarRef);

	/* rgVarRefIdx: UINT[u32VarRef] */
	offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
							&u32ArraySize);
	while(u32ArraySize--) {
		offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep, 
                    hf_dispatch_varrefidx, &u32VarRefIdx);
	}

	/* rgVarRef: VARIANT[u32VarRef] */
	offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep, 
							&u32ArraySize);
	u32VariableOffset = offset + u32ArraySize * 4;
	while(u32ArraySize--) {
		offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
							&u32Pointer);
		if (u32Pointer) {
			u32VariableOffset = dissect_dcom_VARIANT(tvb, u32VariableOffset, pinfo, tree, drep, hf_dispatch_varrefarg);
		}
	}

	return u32VariableOffset;
}

#if 0
typedef struct tagEXCEPINFO {
    WORD  wCode;            /* An error code describing the error. */
    WORD  wReserved;
    BSTR  bstrSource;       /* A source of the exception */
    BSTR  bstrDescription;  /* A description of the error */
    BSTR  bstrHelpFile;     /* Fully qualified drive, path, and file name */
    DWORD dwHelpContext;    /* help context of topic within the help file */
    ULONG pvReserved;
    ULONG pfnDeferredFillIn;
    SCODE scode;
} EXCEPINFO;
#endif

static int
dissect_IDispatch_Invoke_resp(tvbuff_t *tvb, int offset,
	packet_info *pinfo, proto_tree *tree, guint8 *drep)
{
	guint32 u32Pointer;
	guint32 u32VariableOffset;


    offset = dissect_dcom_that(tvb, offset, pinfo, tree, drep);

	/* XXX: this is not correct and has to be improved! */
	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
	if (u32Pointer) {
		offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
		u32VariableOffset = offset;
		u32VariableOffset = dissect_dcom_VARIANT(tvb, u32VariableOffset, pinfo, tree, drep, hf_dispatch_varresult);
		offset = u32VariableOffset;
	}

	/* ExcepInfo */
	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
	if (u32Pointer) {
		offset = dissect_dcom_tobedone_data(tvb, offset, pinfo, tree, drep, 
					10000);
	}

	/* ArgErr */
	offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep, 
						&u32Pointer);
	if (u32Pointer) {
		offset = dissect_dcom_tobedone_data(tvb, offset, pinfo, tree, drep, 
					10000);
	}


	return offset;
}



/* sub dissector table of IDispatch interface */
static dcerpc_sub_dissector dispatch_dissectors[] = {
    { 0, "QueryInterface", NULL, NULL },
    { 1, "AddRef", NULL, NULL },
    { 2, "Release", NULL, NULL },

    { 3, "GetTypeInfoCount", NULL, NULL },
    { 4, "GetTypeInfo", NULL, NULL },
    { 5, "GetIDsOfNames", dissect_IDispatch_GetIDsOfNames_rqst, dissect_IDispatch_GetIDsOfNames_resp },
    { 6, "Invoke", dissect_IDispatch_Invoke_rqst, dissect_IDispatch_Invoke_resp },
    { 0, NULL, NULL, NULL },
};


void
proto_register_dcom_dispatch(void)
{

	static hf_register_info hf_dispatch_array[] = {
        { &hf_dispatch_opnum,
	    { "Operation", "dispatch_opnum", FT_UINT16, BASE_DEC, NULL, 0x0, "Operation", HFILL }},

		{ &hf_dispatch_riid,
		{ "RIID", "dispatch_riid", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
        { &hf_dispatch_name,
        { "Name", "hf_dispatch_name", FT_STRING, BASE_NONE, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_names,
		{ "Names", "dispatch_names", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
        { &hf_dispatch_lcid,
        { "LCID", "dispatch_lcid", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
        { &hf_dispatch_id,
        { "ID", "dispatch_id", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
        { &hf_dispatch_flags,
        { "Flags", "dispatch_flags", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},
        { &hf_dispatch_flags2,
        { "Flags2", "dispatch_flags2", FT_UINT16, BASE_HEX, NULL, 0x0, "", HFILL }},

		{ &hf_dispatch_arg,
		{ "Argument", "dispatch_arg", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_args,
		{ "Args", "dispatch_args", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_named_args,
		{ "NamedArgs", "dispatch_named_args", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_varref,
		{ "VarRef", "dispatch_varref", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_varrefidx,
		{ "VarRefIdx", "dispatch_varrefidx", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_varrefarg,
		{ "VarRef", "dispatch_varrefarg", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
		{ &hf_dispatch_varresult,
		{ "VarResult", "dispatch_varresult", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},

        { &hf_dispatch_flags_method,
        { "Method", "dispatch_flags_method", FT_BOOLEAN, 16, TFS (&flags_set_truth), DISPATCH_FLAGS_METHOD, "", HFILL }},
        { &hf_dispatch_flags_propget,
        { "PropertyGet", "dispatch_flags_propget", FT_BOOLEAN, 16, TFS (&flags_set_truth), DISPATCH_FLAGS_PROPGET, "", HFILL }},
        { &hf_dispatch_flags_propput,
        { "PropertyPut", "dispatch_flags_propput", FT_BOOLEAN, 16, TFS (&flags_set_truth), DISPATCH_FLAGS_PROPPUT, "", HFILL }},
        { &hf_dispatch_flags_propputref,
        { "PropertyPutRef", "dispatch_flags_propputref", FT_BOOLEAN, 16, TFS (&flags_set_truth), DISPATCH_FLAGS_PROPPUTREF, "", HFILL }},
	};

	static gint *ett[] = {
		&ett_dispatch,
		&ett_dispatch_flags
	};


	/* IDispatch currently only partially implemented */
	proto_dispatch = proto_register_protocol ("DCOM IDispatch", "IDispatch", "dispatch");
	proto_register_field_array (proto_dispatch, hf_dispatch_array, array_length (hf_dispatch_array));
	proto_register_subtree_array (ett, array_length (ett));
}


void
proto_reg_handoff_dcom_dispatch(void)
{

	dcerpc_init_uuid(proto_dispatch, ett_dispatch,
		&uuid_dispatch, ver_dispatch,
		dispatch_dissectors, hf_dispatch_opnum);
}