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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
31 #include <epan/epan.h>
32 #include <wsutil/unicode-utils.h>
33 #include <epan/emem.h>
34 #include <epan/wmem/wmem.h>
35 #include "guid-utils.h"
42 static wmem_tree_t *guid_to_name_tree = NULL;
46 /* try to resolve an DCE/RPC interface name to its name using the Windows registry entries */
47 /* XXX - might be better to fill all interfaces into our database at startup instead of searching each time */
49 ResolveWin32UUID(e_guid_t if_id, char *uuid_name, int uuid_name_max_len)
53 DWORD uuid_max_size = MAX_PATH;
56 reg_uuid_name=ep_alloc(MAX_PATH*sizeof(TCHAR));
57 reg_uuid_str=ep_alloc(MAX_PATH*sizeof(TCHAR));
59 if(uuid_name_max_len < 2){
62 reg_uuid_name[0] = '\0';
63 _snwprintf(reg_uuid_str, MAX_PATH, _T("SOFTWARE\\Classes\\Interface\\{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}"),
64 if_id.data1, if_id.data2, if_id.data3,
65 if_id.data4[0], if_id.data4[1],
66 if_id.data4[2], if_id.data4[3],
67 if_id.data4[4], if_id.data4[5],
68 if_id.data4[6], if_id.data4[7]);
69 if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, reg_uuid_str, 0, KEY_QUERY_VALUE, &hKey) == ERROR_SUCCESS) {
70 if (RegQueryValueEx(hKey, NULL, NULL, NULL, (LPBYTE)reg_uuid_name, &uuid_max_size) == ERROR_SUCCESS && uuid_max_size <= MAX_PATH) {
71 g_snprintf(uuid_name, uuid_name_max_len, "%s", utf_16to8(reg_uuid_name));
73 return (int) strlen(uuid_name);
77 return 0; /* we didn't find anything anyhow. Please don't use the string! */
83 /* store a guid to name mapping */
85 guids_add_guid(e_guid_t *guid, const gchar *name)
87 wmem_tree_key_t guidkey[2];
100 g[2]|=guid->data4[2];
102 g[2]|=guid->data4[3];
106 g[3]|=guid->data4[5];
108 g[3]|=guid->data4[6];
110 g[3]|=guid->data4[7];
116 wmem_tree_insert32_array(guid_to_name_tree, &guidkey[0], (gchar *) name);
120 /* retrieve the registered name for this GUID */
122 guids_get_guid_name(e_guid_t *guid)
124 wmem_tree_key_t guidkey[2];
128 static char *uuid_name;
139 g[2]|=guid->data4[1];
141 g[2]|=guid->data4[2];
143 g[2]|=guid->data4[3];
147 g[3]|=guid->data4[5];
149 g[3]|=guid->data4[6];
151 g[3]|=guid->data4[7];
157 if((name = (char *)wmem_tree_lookup32_array(guid_to_name_tree, &guidkey[0]))){
162 /* try to resolve the mapping from the Windows registry */
163 /* XXX - prefill the resolving database with all the Windows registry entries once at init only (instead of searching each time)? */
164 uuid_name=ep_alloc(128);
165 if(ResolveWin32UUID(*guid, uuid_name, 128)) {
177 guid_to_name_tree=wmem_tree_new(wmem_epan_scope());
178 /* XXX here is a good place to read a config file with wellknown guids */
182 /* Tries to match a guid against its name.
183 Returns the associated string ptr on a match.
184 Formats uuid number and returns the resulting string, if name is unknown.
185 (derived from val_to_str) */
187 guids_resolve_guid_to_str(e_guid_t *guid)
191 name=guids_get_guid_name(guid);
196 return ep_strdup_printf("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
197 guid->data1, guid->data2, guid->data3,
198 guid->data4[0], guid->data4[1],
199 guid->data4[2], guid->data4[3],
200 guid->data4[4], guid->data4[5],
201 guid->data4[6], guid->data4[7]);