summaryrefslogblamecommitdiffstats
path: root/private/ole32/dbgexts/dclsinfo.cxx
blob: b3d96c7bd804e74639df5cafcf837232ccc8a0c0 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607






























































































































































































































































































































































































































































































































































































































                                                                             
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1995
//
//  File:       dclassInfo.cxx
//
//  Contents:   Display registry class information
//
//  Functions:  classInfoHelp
//              displayclassInfo
//
//
//  History:    06-01-95 BruceMa    Created
//
//
//--------------------------------------------------------------------------


// BUGBUG: Add threading model flags


#include <ole2int.h>
#include <windows.h>
#include "ole.h"
#include "dinfolvl.h"
#include "debnot.h"



BOOL ScanCLSID(char *szClsid, CLSID *pClsid);
void FormatCLSID(REFGUID rguid, LPSTR lpsz);

static void GetSomeClsidValues(HKEY   hKey,
                               char  *szName,
                               char  *szInprocHandler,
                               char  *szInprocHandler32,
                               char  *szInprocServer,
                               char  *szInprocServer32,
                               char  *szLocalServer,
                               char  *szLocalServer32,
                               char  *szProgid,
                               char  *szTreatAs,
                               char  *szAutoConvertTo,
                               char  *szOle1Class);

static void DisplayValues(PNTSD_EXTENSION_APIS lpExtensionApis,
                          char                *szName,
                          char                *szInprocHandler,
                          char                *szInprocHandler32,
                          char                *szInprocServer,
                          char                *szInprocServer32,
                          char                *szLocalServer,
                          char                *szLocalServer32,
                          char                *szProgid,
                          char                *szTreatAs,
                          char                *szAutoConvertTo,
                          char                *szOle1Class);

static void MungePath(char *szPath);

static DWORD dwRESERVED = 0;




//+-------------------------------------------------------------------------
//
//  Function:   classInfoHelp
//
//  Synopsis:   Display a menu for the command 'id'
//
//  Arguments:  -
//
//  Returns:    -
//
//  History:    07-Mar-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void classInfoHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
{
    Printf("ci            - Display registry class information\n");
    Printf("ci clsid      - Display registry class information for clsid\n");

}








//+-------------------------------------------------------------------------
//
//  Function:   displayclassInfo
//
//  Synopsis:   Display/set debug info levels
//
//  Arguments:  [hProcess]        -       Handle of this process
//              [lpExtensionApis] -       Table of extension functions
//              [CLSID *]         -       Get info for this clsid
//
//  Returns:    -
//
//  History:    07-Mar-95   BruceMa    Created
//
//--------------------------------------------------------------------------
BOOL displayClassInfo(HANDLE hProcess,
                      PNTSD_EXTENSION_APIS lpExtensionApis,
                      CLSID *pClsid)
{
    HKEY   hKey;
    char   szCLSID[CLSIDSTR_MAX];
    char   szClsid[5 + 1 + CLSIDSTR_MAX];
    char   szName[64];
    char   szInprocHandler[64];
    char   szInprocHandler32[64];
    char   szInprocServer[64];
    char   szInprocServer32[64];
    char   szLocalServer[64];
    char   szLocalServer32[64];
    char   szProgid[64];
    char   szTreatAs[64];
    char   szAutoConvertTo[64];
    char   szOle1Class[64];


    // Information for a specific clsid?
    if (pClsid)
    {
        // Prepare to open the "...CLSID\<clsid>" key
        FormatCLSID(*pClsid, szCLSID);
        lstrcpy(szClsid, "CLSID\\");
        lstrcat(szClsid, szCLSID);

        // Open the key for the specified clsid
        if (RegOpenKeyEx(HKEY_CLASSES_ROOT, szClsid, dwRESERVED,
                         KEY_READ, &hKey) != ERROR_SUCCESS)
        {
            return FALSE;
        }

        // Read interesting values for this clsid
        GetSomeClsidValues(hKey,
                           szName,
                           szInprocHandler,
                           szInprocHandler32,
                           szInprocServer,
                           szInprocServer32,
                           szLocalServer,
                           szLocalServer32,
                           szProgid,
                           szTreatAs,
                           szAutoConvertTo,
                           szOle1Class);

            // Only display "interesting" entries
            if ((szInprocHandler[0]  &&
                 _stricmp(szInprocHandler, "ole2.dll") != 0)     ||
                (szInprocHandler32[0]  &&
                 _stricmp(szInprocHandler32, "ole32.dll") != 0)  ||
                (szInprocServer[0]  &&
                 _stricmp(szInprocServer, "ole2.dll") != 0)      ||
                (szInprocServer32[0]  &&
                 _stricmp(szInprocServer32, "ole32.dll") != 0)   ||
                szLocalServer[0]                                ||
                szLocalServer32[0]                              ||
                szTreatAs[0]                                    ||
                szAutoConvertTo[0])
            {
                // Display them
                DisplayValues(lpExtensionApis,
                              szName,
                              szInprocHandler,
                              szInprocHandler32,
                              szInprocServer,
                              szInprocServer32,
                              szLocalServer,
                              szLocalServer32,
                              szProgid,
                              szTreatAs,
                              szAutoConvertTo,
                              szOle1Class);
            }

        // Close registry handle and return success
        CloseHandle(hKey);
        return TRUE;
    }

    // Else display all of them
    else
    {
        HKEY     hKey2;
        DWORD    dwErr;
        DWORD    cbSubKey = 0;
        char     szClsid[64];
        DWORD    cbClsid;
        DWORD    cbClass;
        FILETIME sLastWrite;

        // Open the key for the root "CLSID"
        if (RegOpenKeyEx(HKEY_CLASSES_ROOT, "CLSID", dwRESERVED,
                         KEY_ENUMERATE_SUB_KEYS, &hKey) != ERROR_SUCCESS)
        {
            return FALSE;
        }

        // Enumerate over the keys under "HKEY_CLASSES_ROOT\CLSID"
        do
        {
            // Enumerate the next subkey
            cbClsid = 64;
            dwErr = RegEnumKeyEx(hKey, cbSubKey, szClsid, &cbClsid,
                                 NULL, NULL, NULL, &sLastWrite);

            // Prepare for next subkey
            cbSubKey++;

            // If it does look like a clsid, skip it
            CLSID clsid;

            if (!ScanCLSID(szClsid, &clsid))
            {
                continue;
            }

            // Open this clsid key
            if (RegOpenKeyEx(hKey, szClsid, dwRESERVED,
                             KEY_READ, &hKey2) != ERROR_SUCCESS)
            {
                return FALSE;
            }

            // Get the interesting values
            GetSomeClsidValues(hKey2,
                               szName,
                               szInprocHandler,
                               szInprocHandler32,
                               szInprocServer,
                               szInprocServer32,
                               szLocalServer,
                               szLocalServer32,
                               szProgid,
                               szTreatAs,
                               szAutoConvertTo,
                               szOle1Class);

            // Only display "interesting" entries
            if ((szInprocHandler[0]  &&
                 _stricmp(szInprocHandler, "ole2.dll") != 0)     ||
                (szInprocHandler32[0]  &&
                 _stricmp(szInprocHandler32, "ole32.dll") != 0)  ||
                (szInprocServer[0]  &&
                 _stricmp(szInprocServer, "ole2.dll") != 0)      ||
                (szInprocServer32[0]  &&
                 _stricmp(szInprocServer32, "ole32.dll") != 0)   ||
                szLocalServer[0]                                ||
                szLocalServer32[0]                              ||
                szTreatAs[0]                                    ||
                szAutoConvertTo[0])
            {
                // Display the clsid
                Printf("%s ", szClsid);

                // Display its values
                DisplayValues(lpExtensionApis,
                              szName,
                              szInprocHandler,
                              szInprocHandler32,
                              szInprocServer,
                              szInprocServer32,
                              szLocalServer,
                              szLocalServer32,
                              szProgid,
                              szTreatAs,
                              szAutoConvertTo,
                              szOle1Class);
            }

            // Close registry handle
            CloseHandle(hKey2);

        } until_(dwErr == ERROR_NO_MORE_ITEMS  ||  dwErr != ERROR_SUCCESS);

        // Close clsid registry handle
        CloseHandle(hKey);

        return TRUE;
    }
}









//+-------------------------------------------------------------------------
//
//  Function:   GetSomeClsidValues
//
//  Synopsis:   Given an open registry key to a clsid, read some of
//              the more interesting subkey values
//
//  Arguments:  [hkey]                Open registry key
//              [szName]              Where to store the name
//              [szInprocHandler]     Where to store the InprocHandler
//              [szInprocHandler32]   Where to store the InprocHandler32
//              [szInprocServer]      Where to store the InprocServer
//              [szInprocServer32]    Where to store the InprocServer32
//              [szLocalServer]       Where to store the LocalServer
//              [szLocalServer32]     Where to store the LocalServer32
//              [ProgId]              Where to store the ProgId
//              [TreatAs]             Where to store the TreatAs
//              [AutoConvertTo]       Where to store the AutoConvertTo
//              [Ole1Class]           Where to store the Ole1Class
//
//  Returns:    -
//
//  History:    01-Jun-95   BruceMa    Created
//
//--------------------------------------------------------------------------
static void GetSomeClsidValues(HKEY   hKey,
                               char  *szName,
                               char  *szInprocHandler,
                               char  *szInprocHandler32,
                               char  *szInprocServer,
                               char  *szInprocServer32,
                               char  *szLocalServer,
                               char  *szLocalServer32,
                               char  *szProgId,
                               char  *szTreatAs,
                               char  *szAutoConvertTo,
                               char  *szOle1Class)
{
    DWORD  dwRESERVED = 0;
    HKEY   hKey2;
    DWORD  dwValueType;
    DWORD  cbValue;

    // Initialize
    szName[0]            = '\0';
    szInprocHandler[0]   = '\0';
    szInprocHandler32[0] = '\0';
    szInprocServer[0]    = '\0';
    szInprocServer32[0]  = '\0';
    szLocalServer[0]     = '\0';
    szLocalServer32[0]   = '\0';
    szProgId[0]          = '\0';
    szTreatAs[0]         = '\0';
    szAutoConvertTo[0]   = '\0';
    szOle1Class[0]       = '\0';

    // Name
    cbValue = 64;
    if (RegQueryValueEx(hKey, NULL, NULL, &dwValueType,
                        (LPBYTE) szName, &cbValue) != ERROR_SUCCESS)
    {
        return;
    }

    // InprocHandler
    if (RegOpenKeyEx(hKey, "InprocHandler", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szInprocHandler, &cbValue);
        MungePath(szInprocHandler);
        CloseHandle(hKey2);
    }

    // InprocHandler32
    if (RegOpenKeyEx(hKey, "InprocHandler32", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szInprocHandler32, &cbValue);
        MungePath(szInprocHandler32);
        CloseHandle(hKey2);
    }

    // InprocServer
    if (RegOpenKeyEx(hKey, "InprocServer", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szInprocServer, &cbValue);
        MungePath(szInprocServer);
        CloseHandle(hKey2);
    }

    // InprocServer32
    if (RegOpenKeyEx(hKey, "InprocServer32", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szInprocServer32, &cbValue);
        MungePath(szInprocServer32);
        CloseHandle(hKey2);
    }

    // LocalServer
    if (RegOpenKeyEx(hKey, "LocalServer", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szLocalServer, &cbValue);
        MungePath(szLocalServer);
        CloseHandle(hKey2);
    }

    // LocalServer32
    if (RegOpenKeyEx(hKey, "LocalServer32", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szLocalServer32, &cbValue);
        MungePath(szLocalServer32);
        CloseHandle(hKey2);
    }

    // ProgId
    if (RegOpenKeyEx(hKey, "ProgId", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szProgId, &cbValue);
        CloseHandle(hKey2);
    }

    // TreatAs
    if (RegOpenKeyEx(hKey, "TreatAs", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szTreatAs, &cbValue);
        CloseHandle(hKey2);
    }

    // AutoConvertTo
    if (RegOpenKeyEx(hKey, "AutoConvertTo", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        cbValue = 64;
        RegQueryValueEx(hKey2, NULL, NULL, &dwValueType,
                        (LPBYTE) szAutoConvertTo, &cbValue);
        CloseHandle(hKey2);
    }

    // Ole1Class
    if (RegOpenKeyEx(hKey, "Ole1Class", dwRESERVED,
                     KEY_READ, &hKey2) == ERROR_SUCCESS)
    {
        szOle1Class[0] = '1';
        CloseHandle(hKey2);
    }
}








//+-------------------------------------------------------------------------
//
//  Function:   DisplayValues
//
//  Synopsis:   Display the values read above
//
//  Arguments:  [hkey]                Open registry key
//              [szName]              Where to store the name
//              [szInprocHandler]     Where to store the InprocHandler
//              [szInprocHandler32]   Where to store the InprocHandler32
//              [szInprocServer]      Where to store the InprocServer
//              [szInprocServer32]    Where to store the InprocServer32
//              [szLocalServer]       Where to store the LocalServer
//              [szLocalServer32]     Where to store the LocalServer32
//              [ProgId]              Where to store the ProgId
//              [TreatAs]             Where to store the TreatAs
//              [AutoConvertTo]       Where to store the AutoConvertTo
//              [Ole1Class]           Where to store the Ole1Class
//
//  Returns:    -
//
//  History:    01-Jun-95   BruceMa    Created
//
//--------------------------------------------------------------------------
static void DisplayValues(PNTSD_EXTENSION_APIS lpExtensionApis,
                          char                *szName,
                          char                *szInprocHandler,
                          char                *szInprocHandler32,
                          char                *szInprocServer,
                          char                *szInprocServer32,
                          char                *szLocalServer,
                          char                *szLocalServer32,
                          char                *szProgId,
                          char                *szTreatAs,
                          char                *szAutoConvertTo,
                          char                *szOle1Class)

{
    // Display the name
    Printf("%s ", szName);

    // Display ProgId (if unique)
    if (szProgId[0]  &&  lstrcmp(szProgId, szName) != 0)
    {
        Printf("%s ", szProgId);
    }

    // Display the server executable
    if (szLocalServer[0])
    {
        Printf("%s ", szLocalServer32);
    }
    else if (szInprocServer32[0])
    {
        Printf("%s ", szInprocServer32);
    }
    else if (szLocalServer[0])
    {
        Printf("%s(16) ", szLocalServer);
    }
    else if (szInprocServer[0])
    {
        Printf("%s(16) ", szInprocServer);
    }

    // Display handler information
    if (szInprocHandler32[0]  &&
        _stricmp(szInprocHandler32, "ole32.dll") != 0)
    {
        Printf("Hndlr: %s ", szInprocHandler32);
    }
    else if (szInprocHandler[0]  &&
             _stricmp(szInprocHandler, "ole2.dll") != 0)
    {
        Printf("Hndlr: %s(16) ", szInprocHandler);
    }

    // Display any TreatAs or AutoConvertTo information
    if (szTreatAs[0])
    {
        Printf("TA: %s", szTreatAs);
    }
    if (szAutoConvertTo[0])
    {
        Printf("ACT: %s", szAutoConvertTo);
    }

    // Check if this is an ole1 class
    if (szOle1Class[0])
    {
        Printf("ole1 class");
    }

    // We're done
    Printf("\n");
}








//+-------------------------------------------------------------------------
//
//  Function:   MungePath
//
//  Synopsis:   Remove directory components from a file path
//
//  Arguments:  [szPath]                Path to munge
//
//  Returns:    -
//
//  History:    01-Jun-95   BruceMa    Created
//
//--------------------------------------------------------------------------
static void MungePath(char *szPath)
{
    int   cbLen = lstrlen(szPath);
    DWORD cbPath;

    for (cbPath = cbLen; cbPath > 0  &&  szPath[cbPath] != '\\'; cbPath--)
    {
    }
    if (cbPath > 0)
    {
        lstrcpy(szPath, &szPath[cbPath + 1]);
    }
}