summaryrefslogtreecommitdiffstats
path: root/private/ole32/dbgexts/doxid.cxx
blob: 44ef0f63741c84be3ae7c1766db9ad5be65191c1 (plain) (blame)
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
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1995
//
//  File:       doxid.cxx
//
//  Contents:   Ole NTSD extension routines to display COXID table
//
//  Functions:  oxidHelp
//              displayOxid
//
//
//  History:    21-Aug-95 BruceMa    Created
//
//
//--------------------------------------------------------------------------


#include <ole2int.h>
#include <windows.h>
#include "ole.h"
#include "dipid.h"


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



static char *aszProtSeq[] = {/* 0x00 */ 0,
                             /* 0x01 */ "mswmsg",
                             /* 0x02 */ 0,
                             /* 0x03 */ 0,
                             /* 0x04 */ "ncacn_dnet_dsp",
                             /* 0x05 */ 0,
                             /* 0x06 */ 0,
                             /* 0x07 */ "ncacn_ip_tcp",
                             /* 0x08 */ "ncadg_ip_udp",
                             /* 0x09 */ "ncacn_nb_tcp",
                             /* 0x0a */ 0,
                             /* 0x0b */ 0,
                             /* 0x0c */ "ncacn_spx",
                             /* 0x0d */ "ncacn_nb_ipx",
                             /* 0x0e */ "ncadg_ipx",
                             /* 0x0f */ "ncacn_np",
                             /* 0x10 */ "ncalrpc",
                             /* 0x11 */ 0,
                             /* 0x12 */ 0,
                             /* 0x13 */ "ncacn_nb_nb"};





//+-------------------------------------------------------------------------
//
//  Function:   oxidHelp
//
//  Synopsis:   Display a menu for the command 'id'
//
//  Arguments:  -
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void oxidHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
{
    Printf("\nox       - Display entire OXID table:\n");
    Printf("addr oxid\n");
    Printf("...\n\n");
    Printf("ox addr    - Display specific OXID entry:\n");
    Printf("oxid serverPid serverTid flags hRpc IRemUnknown* runDownIPID refs stringBindings\n");
}






//+-------------------------------------------------------------------------
//
//  Function:   displayOxid
//
//  Synopsis:   Display the entire OXID table
//
//  Arguments:  [hProcess]        -       Handle of this process
//              [lpExtensionApis] -       Table of extension functions
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void displayOxid(HANDLE hProcess,
                  PNTSD_EXTENSION_APIS lpExtensionApis)
{
    ULONG        pAdr;
    SOXIDEntry  *pOXIDentry;
    SOXIDEntry  *pFirstOXIDentry;
    SOXIDEntry   sOXIDentry;
    char         szGuid[CLSIDSTR_MAX];
    STRINGARRAY *pBindings;
    ULONG        ulSize;


    // Read the address of the first in use OXID entry
    pAdr = GetExpression("ole32!COXIDTable___InUseHead");
    pFirstOXIDentry = (SOXIDEntry *) pAdr;
    ReadMem(&pOXIDentry, pAdr + sizeof(ULONG), sizeof(SOXIDEntry *));

    // Do over in use OXID entries
    do
    {
        // Read the next OXID entry
        ReadMem(&sOXIDentry, pOXIDentry, sizeof(SOXIDEntry));

        // Print the address
        Printf("%x ", pOXIDentry);

        // Print the OXID
        FormatCLSID((GUID &) sOXIDentry.oxid, szGuid);
        Printf("%s\n", szGuid);
        
        // Go to the next in use OXID entry
        pOXIDentry = sOXIDentry.pNext;

        // Just in case
        if (CheckControlC())
        {
            return;
        }
    } until_(pOXIDentry == pFirstOXIDentry);
}






//+-------------------------------------------------------------------------
//
//  Function:   displayOxidEntry
//
//  Synopsis:   Display an entry in the OXID table
//
//  Arguments:  [hProcess]        -       Handle of this process
//              [lpExtensionApis] -       Table of extension functions
//              [arg]             -       OXID of entry to display
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void displayOxidEntry(HANDLE hProcess,
                      PNTSD_EXTENSION_APIS lpExtensionApis,
                      char *arg)
{
    OXID         oxid;
    ULONG        pAdr;
    SOXIDEntry  *pOXIDentry;
    SOXIDEntry  *pFirstOXIDentry;
    SOXIDEntry   sOXIDentry;
    char         szGuid[CLSIDSTR_MAX];
    STRINGARRAY *pBindings;
    ULONG        ulSize;


    // Check for help
    if (arg[0] == '?')
    {
        Printf("oxid serverPid serverTid flags hRpc IRemUnknown* runDownIPID refs stringBindings\n");
        return;
    }

    // Convert the argument to an OXID
    pAdr = ScanAddr(arg);
    
    // Read the OXID entry
    ReadMem(&sOXIDentry, pAdr, sizeof(SOXIDEntry));

    // OXID
    FormatCLSID((GUID &) sOXIDentry.oxid, szGuid);
    Printf("%s ", szGuid);
        
    // Server PID
    Printf("%3x ", sOXIDentry.dwPid);
            
    // Server TID
    Printf("%3x ", sOXIDentry.dwTid);
    
    // Flags
    if (sOXIDentry.dwFlags & OXIDF_REGISTERED)
    {
        Printf("R");
    }
    if (sOXIDentry.dwFlags & OXIDF_MACHINE_LOCAL)
    {
        Printf("L");
    }
    if (sOXIDentry.dwFlags & OXIDF_STOPPED)
    {
        Printf("S");
    }
    if (sOXIDentry.dwFlags & OXIDF_PENDINGRELEASE)
    {
        Printf("P");
    }
    Printf(" ");
    
    // RPC binding handle
    Printf("%x ", sOXIDentry.hServer);

    // Proxy for RemUnknown
    Printf("%x ", sOXIDentry.pRU);

    // IPID of IRunDown and Remote Unknown
    Printf("[%d.%d %3x %3x %d] ",
           sOXIDentry.ipidRundown.page,
           sOXIDentry.ipidRundown.offset,
           sOXIDentry.ipidRundown.pid,
           sOXIDentry.ipidRundown.tid,
           sOXIDentry.ipidRundown.seq);

    // References
    Printf("%d\n ", sOXIDentry.cRefs);
            
    // Print the string bindings
    ReadMem(&ulSize, sOXIDentry.psa, sizeof(ULONG));
    pBindings = (STRINGARRAY *) OleAlloc(ulSize * sizeof(WCHAR));
    ReadMem(pBindings, sOXIDentry.psa, ulSize * sizeof(WCHAR));
    
    // Do over protocol sequence/network address pairs
    for (UINT k = 0; k < ulSize - 2  ||
         pBindings->awszStringArray[k] == 0; )
    {
        char *pszProtSeq;
        
        // The protocol sequence
        pszProtSeq = aszProtSeq[pBindings->awszStringArray[k]];
        if (pszProtSeq == NULL)
        {
            Printf("%d", pBindings->awszStringArray[k]);
        }
        else
        {
            Printf("%s", pszProtSeq);
        }
        k++;
        
        // The network address
        Printf("%ws ", &pBindings->awszStringArray[k]);
        k += lstrlenW(&pBindings->awszStringArray[k]) + 1;
    }
    Printf("\n");
    OleFree(pBindings);
}