1 /* packet-dcom-remunkn.c
2 * Routines for the IRemUnknown interface
3 * Copyright 2004, Jelmer Vernooij <jelmer@samba.org>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 /* see packet-dcom.c for details about DCOM */
35 #include <epan/packet.h>
36 #include <epan/emem.h>
37 #include "packet-dcerpc.h"
38 #include "packet-dcom.h"
39 #include "guid-utils.h"
42 static int hf_remunk_opnum = -1;
45 static int hf_remunk_refs = -1;
46 static int hf_remunk_iids = -1;
48 static int hf_remunk_flags = -1;
49 static int hf_remunk_qiresult = -1;
51 static gint ett_remunk_reminterfaceref = -1;
52 static int hf_remunk_reminterfaceref = -1;
53 static int hf_remunk_interface_refs = -1;
54 static int hf_remunk_public_refs = -1;
55 static int hf_remunk_private_refs = -1;
58 static gint ett_remunk_rqi_result = -1;
61 static gint ett_remunk = -1;
62 static e_uuid_t uuid_remunk = { 0x00000131, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
63 static guint16 ver_remunk = 0;
64 static int proto_remunk = -1;
66 static e_uuid_t ipid_remunk = { 0x00000131, 0x1234, 0x5678, { 0xCA, 0xFE, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
68 /* There is a little bit confusion about the IRemUnknown2 interface UUIDs */
69 /* DCOM documentation tells us: 0x00000142 (7 methods) */
70 /* win2000 registry tells us: 0x00000142 IRemoteQI (4 methods) */
71 /* win2000 registry tells us: 0x00000143 IRemUnknown2 (7 methods) */
72 /* There is some evidence, that the DCOM documentation is wrong, so using 143 for IRemUnknown2 now. */
74 static gint ett_remunk2 = -1;
75 static e_uuid_t uuid_remunk2 = { 0x00000143, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
76 static guint16 ver_remunk2 = 0;
77 static int proto_remunk2 = -1;
80 typedef struct remunk_remqueryinterface_call_s {
83 } remunk_remqueryinterface_call_t;
87 dissect_remunk_remqueryinterface_rqst(tvbuff_t *tvb, int offset,
88 packet_info *pinfo, proto_tree *tree, guint8 *drep)
96 dcerpc_info *info = (dcerpc_info *) pinfo->private_data;
97 remunk_remqueryinterface_call_t *call;
100 offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);
102 offset = dissect_dcom_UUID(tvb, offset, pinfo, tree, drep,
103 hf_dcom_ipid, &ipid);
105 offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep,
106 hf_remunk_refs, &u32Refs);
108 offset = dissect_dcom_WORD(tvb, offset, pinfo, tree, drep,
109 hf_remunk_iids, &u16IIDs);
111 offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep,
114 /* limit the allocation to a reasonable size */
115 if(u32ArraySize < 100) {
116 call = se_alloc(sizeof(remunk_remqueryinterface_call_t) + u32ArraySize * sizeof(e_uuid_t));
117 call->iid_count = u32ArraySize;
118 call->iids = (e_uuid_t *) (call+1);
119 info->call_data->private_data = call;
124 for (u32ItemIdx = 0; u32ArraySize--; u32ItemIdx++) {
125 offset = dissect_dcom_append_UUID(tvb, offset, pinfo, tree, drep,
126 hf_dcom_iid, u32ItemIdx+1, &iid);
128 call->iids[u32ItemIdx] = iid;
137 dissect_remunk_remqueryinterface_resp(tvbuff_t *tvb, int offset,
138 packet_info *pinfo, proto_tree *tree, guint8 *drep)
141 guint32 u32ArraySize;
143 proto_item *sub_item;
144 proto_tree *sub_tree;
148 e_uuid_t iid_null = DCERPC_UUID_NULL;
149 dcerpc_info *info = (dcerpc_info *) pinfo->private_data;
150 remunk_remqueryinterface_call_t *call = info->call_data->private_data;
154 dcom_interface_t *dcom_if;
157 offset = dissect_dcom_that(tvb, offset, pinfo, tree, drep);
159 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep,
161 offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep,
165 while (u32ArraySize--) {
167 sub_item = proto_tree_add_item(tree, hf_remunk_qiresult, tvb, offset, 0, FALSE);
168 sub_tree = proto_item_add_subtree(sub_item, ett_remunk_rqi_result);
171 offset = dissect_dcom_HRESULT(tvb, offset, pinfo, sub_tree, drep,
173 u32SubStart = offset - 4;
174 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, sub_tree, drep,
177 /* try to read the iid from the request */
178 if(call != NULL && u32ItemIdx <= call->iid_count) {
179 iid = call->iids[u32ItemIdx-1];
184 /* XXX - this doesn't seem to be dependent on the pointer above?!? */
185 /*if (u32Pointer) {*/
186 offset = dissect_dcom_STDOBJREF(tvb, offset, pinfo, sub_tree, drep, 0 /* hfindex */,
190 /* add interface instance to database (we currently only handle IPv4) */
191 if(pinfo->net_src.type == AT_IPv4) {
192 dcom_if = dcom_interface_new(pinfo,
194 &iid, oxid, oid, &ipid);
198 proto_item_append_text(sub_item, "[%u]: %s",
200 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)") );
201 proto_item_set_len(sub_item, offset - u32SubStart);
203 /* update column info now */
204 if (check_col(pinfo->cinfo, COL_INFO)) {
205 col_append_fstr(pinfo->cinfo, COL_INFO, " %s[%u]",
206 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"),
213 /* HRESULT of call */
214 offset = dissect_dcom_HRESULT(tvb, offset, pinfo, tree, drep,
217 /* update column info now */
218 if (check_col(pinfo->cinfo, COL_INFO)) {
219 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s",
220 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"));
228 dissect_remunk_remrelease_rqst(tvbuff_t *tvb, int offset,
229 packet_info *pinfo, proto_tree *tree, guint8 *drep)
235 guint32 u32PublicRefs;
236 guint32 u32PrivateRefs;
237 const gchar *pszFormat;
238 proto_item *sub_item;
239 proto_tree *sub_tree;
243 offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);
245 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep,
248 offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep,
249 hf_remunk_interface_refs, &u32IntRefs);
251 /* update column info now */
252 if (check_col(pinfo->cinfo, COL_INFO)) {
254 col_append_fstr(pinfo->cinfo, COL_INFO, " Cnt=%u Refs=", u32IntRefs);
256 col_append_fstr(pinfo->cinfo, COL_INFO, " Cnt=0");
261 while (u32IntRefs--) {
263 sub_item = proto_tree_add_item(tree, hf_remunk_reminterfaceref, tvb, offset, 0, FALSE);
264 sub_tree = proto_item_add_subtree(sub_item, ett_remunk_reminterfaceref);
265 u32SubStart = offset;
267 offset = dissect_dcom_UUID(tvb, offset, pinfo, sub_tree, drep,
268 hf_dcom_ipid, &ipid);
270 offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, drep,
271 hf_remunk_public_refs, &u32PublicRefs);
273 offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, drep,
274 hf_remunk_private_refs, &u32PrivateRefs);
277 proto_item_append_text(sub_item, "[%u]: IPID=%s, PublicRefs=%u, PrivateRefs=%u",
279 guids_resolve_uuid_to_str(&ipid),
280 u32PublicRefs, u32PrivateRefs);
281 proto_item_set_len(sub_item, offset - u32SubStart);
283 /* update column info now */
284 if (check_col(pinfo->cinfo, COL_INFO)) {
286 if (u32ItemIdx == 1) {
288 } else if (u32ItemIdx < 10) {
289 pszFormat = ",%u-%u";
290 } else if (u32ItemIdx == 10) {
293 col_append_fstr(pinfo->cinfo, COL_INFO, pszFormat, u32PublicRefs, u32PrivateRefs);
303 /* sub dissector table of IRemUnknown interface */
304 static dcerpc_sub_dissector remunk_dissectors[] = {
305 { 0, "QueryInterface", NULL, NULL },
306 { 1, "AddRef", NULL, NULL },
307 { 2, "Release", NULL, NULL },
309 { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
310 { 4, "RemAddRef", NULL, NULL },
311 { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
312 { 0, NULL, NULL, NULL }
315 /* sub dissector table of IRemUnknown2 interface */
316 static dcerpc_sub_dissector remunk2_dissectors[] = {
317 { 0, "QueryInterface", NULL, NULL },
318 { 1, "AddRef", NULL, NULL },
319 { 2, "Release", NULL, NULL },
321 { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
322 { 4, "RemAddRef", NULL, NULL },
323 { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
325 { 6, "RemQueryInterface2", NULL, NULL },
326 { 0, NULL, NULL, NULL }
332 proto_register_remunk (void)
334 static hf_register_info hf_remunk_rqi_array[] = {
336 { "Operation", "remunk_opnum", FT_UINT16, BASE_DEC, NULL, 0x0, "Operation", HFILL }},
339 { "Refs", "remunk_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
341 { "IIDs", "remunk_iids", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
342 { &hf_remunk_qiresult,
343 { "QIResult", "remunk_qiresult", FT_NONE, BASE_DEC, NULL, 0x0, "", HFILL }},
345 { "Flags", "remunk_flags", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
346 { &hf_remunk_public_refs,
347 { "PublicRefs", "remunk_public_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
348 { &hf_remunk_reminterfaceref,
349 { "RemInterfaceRef", "remunk_reminterfaceref", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
350 { &hf_remunk_interface_refs,
351 { "InterfaceRefs", "remunk_int_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
352 { &hf_remunk_private_refs,
353 { "PrivateRefs", "remunk_private_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }}
356 static gint *ett_remunk_array[] = {
358 &ett_remunk_rqi_result,
360 &ett_remunk_reminterfaceref
363 proto_remunk = proto_register_protocol ("IRemUnknown", "IRemUnknown", "remunk");
364 proto_register_field_array (proto_remunk, hf_remunk_rqi_array, array_length (hf_remunk_rqi_array));
366 proto_remunk2 = proto_register_protocol ("IRemUnknown2", "IRemUnknown2", "remunk2");
368 proto_register_subtree_array (ett_remunk_array, array_length (ett_remunk_array));
372 proto_reg_handoff_remunk (void)
375 /* Register the IPID */
376 guids_add_uuid(&ipid_remunk, "IPID-IRemUnknown");
378 /* Register the interfaces */
379 dcerpc_init_uuid(proto_remunk, ett_remunk,
380 &uuid_remunk, ver_remunk,
381 remunk_dissectors, hf_remunk_opnum);
383 dcerpc_init_uuid(proto_remunk2, ett_remunk2,
384 &uuid_remunk2, ver_remunk2,
385 remunk2_dissectors, hf_remunk_opnum);