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"
41 static int hf_remunk_opnum = -1;
44 static int hf_remunk_refs = -1;
45 static int hf_remunk_iids = -1;
47 static int hf_remunk_flags = -1;
48 static int hf_remunk_qiresult = -1;
50 static gint ett_remunk_reminterfaceref = -1;
51 static int hf_remunk_reminterfaceref = -1;
52 static int hf_remunk_interface_refs = -1;
53 static int hf_remunk_public_refs = -1;
54 static int hf_remunk_private_refs = -1;
57 static gint ett_remunk_rqi_result = -1;
60 static gint ett_remunk = -1;
61 static e_uuid_t uuid_remunk = { 0x00000131, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
62 static guint16 ver_remunk = 0;
63 static int proto_remunk = -1;
65 /* There is a little bit confusion about the IRemUnknown2 interface UUIDs */
66 /* DCOM documentation tells us: 0x00000142 (7 methods) */
67 /* win2000 registry tells us: 0x00000142 IRemoteQI (4 methods) */
68 /* win2000 registry tells us: 0x00000143 IRemUnknown2 (7 methods) */
69 /* There is some evidence, that the DCOM documentation is wrong, so using 143 for IRemUnknown2 now. */
71 static gint ett_remunk2 = -1;
72 static e_uuid_t uuid_remunk2 = { 0x00000143, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
73 static guint16 ver_remunk2 = 0;
74 static int proto_remunk2 = -1;
77 typedef struct remunk_remqueryinterface_call_s {
80 } remunk_remqueryinterface_call_t;
84 dissect_remunk_remqueryinterface_rqst(tvbuff_t *tvb, int offset,
85 packet_info *pinfo, proto_tree *tree, guint8 *drep)
93 dcerpc_info *info = (dcerpc_info *) pinfo->private_data;
94 remunk_remqueryinterface_call_t *call;
97 offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);
99 offset = dissect_dcom_UUID(tvb, offset, pinfo, tree, drep,
100 hf_dcom_ipid, &ipid);
102 offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep,
103 hf_remunk_refs, &u32Refs);
105 offset = dissect_dcom_WORD(tvb, offset, pinfo, tree, drep,
106 hf_remunk_iids, &u16IIDs);
108 offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep,
111 /* limit the allocation to a reasonable size */
112 if(u32ArraySize < 100) {
113 call = se_alloc(sizeof(remunk_remqueryinterface_call_t) + u32ArraySize * sizeof(e_uuid_t));
114 call->iid_count = u32ArraySize;
115 call->iids = (e_uuid_t *) (call+1);
116 info->call_data->private_data = call;
121 for (u32ItemIdx = 0; u32ArraySize--; u32ItemIdx++) {
122 offset = dissect_dcom_append_UUID(tvb, offset, pinfo, tree, drep,
123 hf_dcom_iid, u32ItemIdx+1, &iid);
125 call->iids[u32ItemIdx] = iid;
134 dissect_remunk_remqueryinterface_resp(tvbuff_t *tvb, int offset,
135 packet_info *pinfo, proto_tree *tree, guint8 *drep)
138 guint32 u32ArraySize;
140 proto_item *sub_item;
141 proto_tree *sub_tree;
145 e_uuid_t iid_null = DCERPC_UUID_NULL;
146 dcerpc_info *info = (dcerpc_info *) pinfo->private_data;
147 remunk_remqueryinterface_call_t *call = info->call_data->private_data;
151 dcom_interface_t *dcom_if;
154 offset = dissect_dcom_that(tvb, offset, pinfo, tree, drep);
156 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep,
158 offset = dissect_dcom_dcerpc_array_size(tvb, offset, pinfo, tree, drep,
162 while (u32ArraySize--) {
164 sub_item = proto_tree_add_item(tree, hf_remunk_qiresult, tvb, offset, 0, FALSE);
165 sub_tree = proto_item_add_subtree(sub_item, ett_remunk_rqi_result);
168 offset = dissect_dcom_HRESULT(tvb, offset, pinfo, sub_tree, drep,
170 u32SubStart = offset - 4;
171 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, sub_tree, drep,
174 /* try to read the iid from the request */
175 if(call != NULL && u32ItemIdx <= call->iid_count) {
176 iid = call->iids[u32ItemIdx-1];
181 /* XXX - this doesn't seem to be dependent on the pointer above?!? */
182 /*if (u32Pointer) {*/
183 offset = dissect_dcom_STDOBJREF(tvb, offset, pinfo, sub_tree, drep, 0 /* hfindex */,
187 /* add interface instance to database (we currently only handle IPv4) */
188 if(pinfo->net_src.type == AT_IPv4) {
189 dcom_if = dcom_interface_new(pinfo,
191 &iid, oxid, oid, &ipid);
195 proto_item_append_text(sub_item, "[%u]: %s",
197 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)") );
198 proto_item_set_len(sub_item, offset - u32SubStart);
200 /* update column info now */
201 if (check_col(pinfo->cinfo, COL_INFO)) {
202 col_append_fstr(pinfo->cinfo, COL_INFO, " %s[%u]",
203 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"),
210 /* HRESULT of call */
211 offset = dissect_dcom_HRESULT(tvb, offset, pinfo, tree, drep,
214 /* update column info now */
215 if (check_col(pinfo->cinfo, COL_INFO)) {
216 col_append_fstr(pinfo->cinfo, COL_INFO, " -> %s",
217 val_to_str(u32HResult, dcom_hresult_vals, "Unknown (0x%08x)"));
225 dissect_remunk_remrelease_rqst(tvbuff_t *tvb, int offset,
226 packet_info *pinfo, proto_tree *tree, guint8 *drep)
232 guint32 u32PublicRefs;
233 guint32 u32PrivateRefs;
234 const gchar *pszFormat;
235 proto_item *sub_item;
236 proto_tree *sub_tree;
240 offset = dissect_dcom_this(tvb, offset, pinfo, tree, drep);
242 offset = dissect_dcom_dcerpc_pointer(tvb, offset, pinfo, tree, drep,
245 offset = dissect_dcom_DWORD(tvb, offset, pinfo, tree, drep,
246 hf_remunk_interface_refs, &u32IntRefs);
248 /* update column info now */
249 if (check_col(pinfo->cinfo, COL_INFO)) {
251 col_append_fstr(pinfo->cinfo, COL_INFO, " Cnt=%u Refs=", u32IntRefs);
253 col_append_fstr(pinfo->cinfo, COL_INFO, " Cnt=0");
258 while (u32IntRefs--) {
260 sub_item = proto_tree_add_item(tree, hf_remunk_reminterfaceref, tvb, offset, 0, FALSE);
261 sub_tree = proto_item_add_subtree(sub_item, ett_remunk_reminterfaceref);
262 u32SubStart = offset;
264 offset = dissect_dcom_UUID(tvb, offset, pinfo, sub_tree, drep,
265 hf_dcom_ipid, &ipid);
267 offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, drep,
268 hf_remunk_public_refs, &u32PublicRefs);
270 offset = dissect_dcom_DWORD(tvb, offset, pinfo, sub_tree, drep,
271 hf_remunk_private_refs, &u32PrivateRefs);
274 proto_item_append_text(sub_item, "[%u]: IPID=%s, PublicRefs=%u, PrivateRefs=%u",
276 dcom_uuid_to_str(&ipid),
277 u32PublicRefs, u32PrivateRefs);
278 proto_item_set_len(sub_item, offset - u32SubStart);
280 /* update column info now */
281 if (check_col(pinfo->cinfo, COL_INFO)) {
283 if (u32ItemIdx == 1) {
285 } else if (u32ItemIdx < 10) {
286 pszFormat = ",%u-%u";
287 } else if (u32ItemIdx == 10) {
290 col_append_fstr(pinfo->cinfo, COL_INFO, pszFormat, u32PublicRefs, u32PrivateRefs);
300 /* sub dissector table of IRemUnknown interface */
301 static dcerpc_sub_dissector remunk_dissectors[] = {
302 { 0, "QueryInterface", NULL, NULL },
303 { 1, "AddRef", NULL, NULL },
304 { 2, "Release", NULL, NULL },
306 { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
307 { 4, "RemAddRef", NULL, NULL },
308 { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
309 { 0, NULL, NULL, NULL }
312 /* sub dissector table of IRemUnknown2 interface */
313 static dcerpc_sub_dissector remunk2_dissectors[] = {
314 { 0, "QueryInterface", NULL, NULL },
315 { 1, "AddRef", NULL, NULL },
316 { 2, "Release", NULL, NULL },
318 { 3, "RemQueryInterface", dissect_remunk_remqueryinterface_rqst, dissect_remunk_remqueryinterface_resp },
319 { 4, "RemAddRef", NULL, NULL },
320 { 5, "RemRelease", dissect_remunk_remrelease_rqst, dissect_dcom_simple_resp },
322 { 6, "RemQueryInterface2", NULL, NULL },
323 { 0, NULL, NULL, NULL }
329 proto_register_remunk (void)
331 static hf_register_info hf_remunk_rqi_array[] = {
333 { "Operation", "remunk_opnum", FT_UINT16, BASE_DEC, NULL, 0x0, "Operation", HFILL }},
336 { "Refs", "remunk_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
338 { "IIDs", "remunk_iids", FT_UINT16, BASE_DEC, NULL, 0x0, "", HFILL }},
339 { &hf_remunk_qiresult,
340 { "QIResult", "remunk_qiresult", FT_NONE, BASE_DEC, NULL, 0x0, "", HFILL }},
342 { "Flags", "remunk_flags", FT_UINT32, BASE_HEX, NULL, 0x0, "", HFILL }},
343 { &hf_remunk_public_refs,
344 { "PublicRefs", "remunk_public_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
345 { &hf_remunk_reminterfaceref,
346 { "RemInterfaceRef", "remunk_reminterfaceref", FT_NONE, BASE_NONE, NULL, 0x0, "", HFILL }},
347 { &hf_remunk_interface_refs,
348 { "InterfaceRefs", "remunk_int_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }},
349 { &hf_remunk_private_refs,
350 { "PrivateRefs", "remunk_private_refs", FT_UINT32, BASE_DEC, NULL, 0x0, "", HFILL }}
353 static gint *ett_remunk_array[] = {
355 &ett_remunk_rqi_result,
357 &ett_remunk_reminterfaceref
360 proto_remunk = proto_register_protocol ("IRemUnknown", "IRemUnknown", "remunk");
361 proto_register_field_array (proto_remunk, hf_remunk_rqi_array, array_length (hf_remunk_rqi_array));
363 proto_remunk2 = proto_register_protocol ("IRemUnknown2", "IRemUnknown2", "remunk2");
365 proto_register_subtree_array (ett_remunk_array, array_length (ett_remunk_array));
369 proto_reg_handoff_remunk (void)
371 /* Register the interfaces */
372 dcerpc_init_uuid(proto_remunk, ett_remunk,
373 &uuid_remunk, ver_remunk,
374 remunk_dissectors, hf_remunk_opnum);
376 dcerpc_init_uuid(proto_remunk2, ett_remunk2,
377 &uuid_remunk2, ver_remunk2,
378 remunk2_dissectors, hf_remunk_opnum);