summaryrefslogtreecommitdiffstats
path: root/private/ole32/dbgexts/dipid.cxx
blob: 2ab1eb344d894767fdf4edc4beef8fe4c02b9f25 (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
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
//+-------------------------------------------------------------------------
//
//  Microsoft Windows
//  Copyright (C) Microsoft Corporation, 1995
//
//  File:       dipid.cxx
//
//  Contents:   Ole NTSD extension routines to display CIPID table
//
//  Functions:  ipidHelp
//              displayIpid
//
//
//  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 GetRegistryInterfaceName(REFIID iid, char *szValue, DWORD *pcbValue);
ULONG ScanAddr(char *lpsz);




//+-------------------------------------------------------------------------
//
//  Function:   ipidHelp
//
//  Synopsis:   Display a menu for the command 'id'
//
//  Arguments:  -
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void ipidHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
{
    Printf("\nip       - Display entire IPID table:\n");
    Printf("index  IPID oxidAddr nextIPIDsameObj\n");
    Printf("...\n\n");
    Printf("ip ipid    - Display specific IPID entry:\n");
    Printf("PID TID seq IID ChnlBfr* prxy/stub realPv oxidAddr flags strongRefs weakRefs nextIPIDsameObj\n");
}






//+-------------------------------------------------------------------------
//
//  Function:   displayIpid
//
//  Synopsis:   Display the entire IPID table
//
//  Arguments:  [hProcess]        -       Handle of this process
//              [lpExtensionApis] -       Table of extension functions
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void displayIpid(HANDLE hProcess,
                  PNTSD_EXTENSION_APIS lpExtensionApis)
{
    ULONG        pAdr;
    ULONG        pStart;
    ULONG        pEnd;
    UINT         cPages;
    SIPIDEntry **pIndexTable;
    SIPIDEntry   sIPIDentry[IPIDsPerPage];
    SOXIDEntry   sOXIDentry;
    char         szGuid[CLSIDSTR_MAX];


    // Read the IPID page index table
    pAdr = GetExpression("ole32!CIPIDTable___pTbl");
    ReadMem(&pStart, pAdr, sizeof(SIPIDEntry **));
    pAdr =   GetExpression("ole32!CIPIDTable___pTblEnd");
    ReadMem(&pEnd, pAdr, sizeof(SIPIDEntry **));
    cPages = (pEnd - pStart) / sizeof(SIPIDEntry **);
    pIndexTable = (SIPIDEntry **) OleAlloc(cPages * sizeof(SIPIDEntry *));
    ReadMem(pIndexTable, pStart, cPages * sizeof(SIPIDEntry *));

    // Do over IPID entry pages
    for (UINT k = 0; k < cPages; k++)
    {
        // Read the next page of IPID entries
        ReadMem(sIPIDentry, pIndexTable[k], IPIDTBL_PAGESIZE);

        // Do over entries within this page
        for (UINT j = 0; j < IPIDsPerPage; j++)
        {
            // Only look at non-vacant entries
            if (!(sIPIDentry[j].dwFlags & IPIDF_VACANT))
            {
                // Print the page/offset for this entry
                Printf("%d.%d  ", k, j);
                
                // Print the IPID
                if (sIPIDentry[j].ipid.page > 1000  ||
                    sIPIDentry[j].ipid.page < 0)
                {
                    FormatCLSID((GUID &) sIPIDentry[j].ipid, szGuid);
                    Printf("%s ", szGuid);
                }
                else
                {
                    Printf("[%d.%d %3x %3x %d] ",
                           sIPIDentry[j].ipid.page,
                           sIPIDentry[j].ipid.offset,
                           sIPIDentry[j].ipid.pid,
                           sIPIDentry[j].ipid.tid,
                           sIPIDentry[j].ipid.seq);
                }

                // Print the associated OXID addr
                Printf("%x ", sIPIDentry[j].pOXIDEntry);

                // Next IPID for this object
                if (sIPIDentry[j].iNextOID != -1)
                {
                    Printf("%d.%d\n",
                           sIPIDentry[j].iNextOID >> 16,
                           sIPIDentry[j].iNextOID & 0xffff);
                }
                else
                {
                    Printf("NULL\n");
                }
            }
        }
    }

    // Release resources
    OleFree(pIndexTable);
}






//+-------------------------------------------------------------------------
//
//  Function:   displayIpidEntry
//
//  Synopsis:   Display an entry in the IPID table
//
//  Arguments:  [hProcess]        -       Handle of this process
//              [lpExtensionApis] -       Table of extension functions
//              [arg]             -       IPID of entry to display
//
//  Returns:    -
//
//  History:    21-Aug-95   BruceMa    Created
//
//--------------------------------------------------------------------------
void displayIpidEntry(HANDLE hProcess,
                      PNTSD_EXTENSION_APIS lpExtensionApis,
                      char *arg)
{
    char        *s;
    IPID         ipid;
    ULONG        ppIPIDentry;;
    SIPIDEntry  *pIPIDentry;
    SIPIDEntry   sIPIDentry;
    char         szGuid[CLSIDSTR_MAX];
    SOXIDEntry   sOXID;


    // Check for help
    if (arg[0] == '?')
    {
        Printf("PID TID seq IID ChnlBfr* prxy/stub realPv oxidAddr flags strongRefs weakRefs nextIPIDsameObj\n");
        return;
    }

    // arg may be either page.offset or a hex address
    BOOL fAdr = TRUE;
    for (s = arg; *s; s++)
    {
        if (*s == '.')
        {
            fAdr = FALSE;
        }
    }

    // The argument is a hex address
    if (fAdr)
    {
        pIPIDentry = (SIPIDEntry *) ScanAddr(arg);
    }

    // The argment has the form page.offset
    else
    {
        // Make sure the argument looks like an IPID
        BOOL fOk = TRUE;
        UINT cPoint = 0;
        if (!IsDecimal(arg[0]))
        {
            fOk = FALSE;
        }
        for (s = arg; *s; s++)
        {
            if (*s != '.'  &&  !IsDecimal(*s))
            {
                fOk = FALSE;
            }
            if (*s == '.')
            {
                cPoint++;
            }
        }
        if (!IsDecimal(*(s - 1)))
        {
            fOk = FALSE;
        }
        if (!(fOk  &&  cPoint == 1))
        {
            Printf("...%s is not an IPID\n", arg);
            return;
        }
        
        // Convert the argument to an IPID
        for (ipid.page = 0; *arg  &&  *arg != '.'; arg++)
        {
            ipid.page = 10 * ipid.page + *arg - '0';
        }
        for (arg++, ipid.offset = 0; *arg; arg++)
        {
            ipid.offset = 10 * ipid.offset + *arg - '0';
        }
        
        // Read the address of the page containing the entry we want
        ppIPIDentry = GetExpression("ole32!CIPIDTable___pTbl");
        ReadMem(&ppIPIDentry, ppIPIDentry, sizeof(SIPIDEntry **));
        ppIPIDentry += ipid.page * sizeof(SIPIDEntry **);
        ReadMem(&pIPIDentry, ppIPIDentry, sizeof(SIPIDEntry *));
        
        // Compute the address of the entry we're seeking
        pIPIDentry += ipid.offset;
    }

    // Now read the entry
    ReadMem(&sIPIDentry, pIPIDentry, sizeof(SIPIDEntry));

    // Check whether the entry is vacant
    if (sIPIDentry.dwFlags & IPIDF_VACANT)
    {
        Printf("VACANT\n");
        return;
    }

    // The ipid may just be a GUID; e.g. client side scm interfaces
    if (sIPIDentry.ipid.page >> 1000  ||  sIPIDentry.ipid.page < 0)
    {
        FormatCLSID((GUID &) sIPIDentry.ipid, szGuid);
        Printf("%s ", szGuid);
    }
    else
    {
        // Server PID
        Printf("%3x ", sIPIDentry.ipid.pid);
    
        // Server TID
        Printf("%3x ", sIPIDentry.ipid.tid);

        // Sequence number
        Printf("%d ", sIPIDentry.ipid.seq);
    }

    // IID
    DWORD cbValue;
    if (!GetRegistryInterfaceName(sIPIDentry.iid, szGuid, &cbValue))
    {
        FormatCLSID(sIPIDentry.iid, szGuid);
    }
    Printf("%s ", szGuid);

    // CRpcChannelBuffer *
    Printf("%x ", sIPIDentry.pChnl);

    // Address of proxy/stub
    Printf("%x ", sIPIDentry.pStub);

    // Real interface pinter
    Printf("%x ", sIPIDentry.pv);

    // Associated OXID
    Printf("%x ", sIPIDentry.pOXIDEntry);

    // Flags
    if (sIPIDentry.dwFlags & IPIDF_CONNECTING)
    {
        Printf("C");
    }
    if (sIPIDentry.dwFlags & IPIDF_DISCONNECTED)
    {
        Printf("D");
    }
    if (sIPIDentry.dwFlags & IPIDF_SERVERENTRY)
    {
        Printf("S");
    }
    if (sIPIDentry.dwFlags & IPIDF_NOPING)
    {
        Printf("N");
    }
    Printf(" ole32!CCacheEnum__Skip+0x82");

    // Strong references
    Printf("%d ", sIPIDentry.cStrongRefs);

    // Weak references
    Printf("%d ", sIPIDentry.cWeakRefs);

    // Next IPID for this object (if any)
    if (sIPIDentry.iNextOID != -1)
    {
        Printf("%d.%d\n",
               sIPIDentry.iNextOID >> 16,
               sIPIDentry.iNextOID & 0xffff);
    }
    else
    {
        Printf("NULL\n");
    }
}