6 * Wireshark - Network traffic analyzer
7 * 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.
33 #include <epan/epan.h>
34 #include <epan/unicode-utils.h>
35 #include <epan/emem.h>
36 #include "guid-utils.h"
43 static emem_tree_t *guid_to_name_tree = NULL;
47 /* try to resolve an DCE/RPC interface name to it's name using the Windows registry entries */
48 /* XXX - might be better to fill all interfaces into our database at startup instead of searching each time */
50 ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
54 DWORD uuid_max_size = MAX_PATH;
57 reg_uuid_name=ep_alloc(MAX_PATH*sizeof(TCHAR));
58 reg_uuid_str=ep_alloc(MAX_PATH*sizeof(TCHAR));
60 if(uuid_name_max_len < 2){
63 reg_uuid_name[0] = '\0';
64 _snwprintf(reg_uuid_str, MAX_PATH, _T("SOFTWARE\\Classes\\Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
65 if_id.data1, if_id.data2, if_id.data3,
66 if_id.data4[0], if_id.data4[1],
67 if_id.data4[2], if_id.data4[3],
68 if_id.data4[4], if_id.data4[5],
69 if_id.data4[6], if_id.data4[7]);
70 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_uuid_str, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
71 if (RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)reg_uuid_name, &uuid_max_size) == ERROR_SUCCESS && uuid_max_size <= MAX_PATH) {
72 g_snprintf(uuid_name, uuid_name_max_len, "%s", utf_16to8(reg_uuid_name));
74 return strlen(uuid_name);
78 return 0; /* we didn't find anything anyhow. Please don't use the string! */
84 /* store a guid to name mapping */
86 guids_add_guid(e_guid_t *guid, const gchar *name)
88 emem_tree_key_t guidkey[2];
101 g[2]|=guid->data4[2];
103 g[2]|=guid->data4[3];
107 g[3]|=guid->data4[5];
109 g[3]|=guid->data4[6];
111 g[3]|=guid->data4[7];
117 pe_tree_insert32_array(guid_to_name_tree, &guidkey[0], (gchar *) name);
121 /* retreive the registered name for this GUID */
123 guids_get_guid_name(e_guid_t *guid)
125 emem_tree_key_t guidkey[2];
129 static char *uuid_name;
140 g[2]|=guid->data4[1];
142 g[2]|=guid->data4[2];
144 g[2]|=guid->data4[3];
148 g[3]|=guid->data4[5];
150 g[3]|=guid->data4[6];
152 g[3]|=guid->data4[7];
158 if((name = pe_tree_lookup32_array(guid_to_name_tree, &guidkey[0]))){
163 /* try to resolve the mapping from the Windows registry */
164 /* XXX - prefill the resolving database with all the Windows registry entries once at init only (instead of searching each time)? */
165 uuid_name=ep_alloc(128);
166 if(ResolveWin32UUID(*guid, uuid_name, 128)) {
178 guid_to_name_tree=pe_tree_create(EMEM_TREE_TYPE_RED_BLACK, "guid_to_name");
179 /* XXX here is a good place to read a config file with wellknown guids */
183 /* Tries to match a guid against its name.
184 Returns the associated string ptr on a match.
185 Formats uuid number and returns the resulting string, if name is unknown.
186 (derived from val_to_str) */
188 guids_resolve_guid_to_str(e_guid_t *guid)
193 name=guids_get_guid_name(guid);
199 namebuf=ep_alloc(64);
200 g_snprintf(namebuf, 64, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
201 guid->data1, guid->data2, guid->data3,
202 guid->data4[0], guid->data4[1],
203 guid->data4[2], guid->data4[3],
204 guid->data4[4], guid->data4[5],
205 guid->data4[6], guid->data4[7]);