4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/epan.h>
30 #include <wsutil/unicode-utils.h>
31 #include <epan/emem.h>
32 #include <epan/wmem/wmem.h>
33 #include "guid-utils.h"
40 static wmem_tree_t *guid_to_name_tree = NULL;
44 /* try to resolve an DCE/RPC interface name to its name using the Windows registry entries */
45 /* XXX - might be better to fill all interfaces into our database at startup instead of searching each time */
47 ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
51 DWORD uuid_max_size = MAX_PATH;
54 reg_uuid_name=ep_alloc(MAX_PATH*sizeof(TCHAR));
55 reg_uuid_str=ep_alloc(MAX_PATH*sizeof(TCHAR));
57 if(uuid_name_max_len < 2){
60 reg_uuid_name[0] = '\0';
61 _snwprintf(reg_uuid_str, MAX_PATH, _T("SOFTWARE\\Classes\\Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
62 if_id.data1, if_id.data2, if_id.data3,
63 if_id.data4[0], if_id.data4[1],
64 if_id.data4[2], if_id.data4[3],
65 if_id.data4[4], if_id.data4[5],
66 if_id.data4[6], if_id.data4[7]);
67 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_uuid_str, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
68 if (RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)reg_uuid_name, &uuid_max_size) == ERROR_SUCCESS && uuid_max_size <= MAX_PATH) {
69 g_snprintf(uuid_name, uuid_name_max_len, "%s", utf_16to8(reg_uuid_name));
71 return (int) strlen(uuid_name);
75 return 0; /* we didn't find anything anyhow. Please don't use the string! */
81 /* store a guid to name mapping */
83 guids_add_guid(const e_guid_t *guid, const gchar *name)
85 wmem_tree_key_t guidkey[2];
100 g[2]|=guid->data4[3];
104 g[3]|=guid->data4[5];
106 g[3]|=guid->data4[6];
108 g[3]|=guid->data4[7];
114 wmem_tree_insert32_array(guid_to_name_tree, &guidkey[0], (gchar *) name);
118 /* retrieve the registered name for this GUID */
120 guids_get_guid_name(const e_guid_t *guid)
122 wmem_tree_key_t guidkey[2];
126 static char *uuid_name;
137 g[2]|=guid->data4[1];
139 g[2]|=guid->data4[2];
141 g[2]|=guid->data4[3];
145 g[3]|=guid->data4[5];
147 g[3]|=guid->data4[6];
149 g[3]|=guid->data4[7];
155 if((name = (char *)wmem_tree_lookup32_array(guid_to_name_tree, &guidkey[0]))){
160 /* try to resolve the mapping from the Windows registry */
161 /* XXX - prefill the resolving database with all the Windows registry entries once at init only (instead of searching each time)? */
162 uuid_name=ep_alloc(128);
163 if(ResolveWin32UUID(*guid, uuid_name, 128)) {
175 guid_to_name_tree=wmem_tree_new(wmem_epan_scope());
176 /* XXX here is a good place to read a config file with wellknown guids */
180 /* Tries to match a guid against its name.
181 Returns the associated string ptr on a match.
182 Formats uuid number and returns the resulting string, if name is unknown.
183 (derived from val_to_str) */
185 guids_resolve_guid_to_str(const e_guid_t *guid)
189 name=guids_get_guid_name(guid);
194 return ep_strdup_printf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
195 guid->data1, guid->data2, guid->data3,
196 guid->data4[0], guid->data4[1],
197 guid->data4[2], guid->data4[3],
198 guid->data4[4], guid->data4[5],
199 guid->data4[6], guid->data4[7]);