debughlp.c 10.7 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/*
 * Helper functions for debugging
 *
 * Copyright 1998, 2002 Juergen Schmied
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 20 21 22 23 24
 */

#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
25 26
#include "windef.h"
#include "wingdi.h"
27
#include "pidl.h"
28
#include "shldisp.h"
29 30
#include "wine/debug.h"
#include "debughlp.h"
31 32
#include "docobj.h"
#include "shell32_main.h"
33 34 35 36


WINE_DEFAULT_DEBUG_CHANNEL(pidl);

37
static
38
LPCITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
39 40 41 42 43 44 45 46
{
	WORD len;

	if(pidl)
	{
	  len =  pidl->mkid.cb;
	  if (len)
	  {
47
	    return (LPCITEMIDLIST) (((const BYTE*)pidl)+len);
48 49 50 51 52
	  }
	}
	return NULL;
}

53
static
54 55
BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
{
56
	return ( !pidl || pidl->mkid.cb == 0x00 );
57 58
}

59
static
60
const PIDLDATA* _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
61 62
{
	if(pidl && pidl->mkid.cb != 0x00)
63
	  return (const PIDLDATA*)pidl->mkid.abID;
64 65 66
	return NULL;
}

67
static
68
LPCSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
69
{
70
	const PIDLDATA* pdata =_dbg_ILGetDataPointer(pidl);
71 72 73 74 75

	if (pdata)
	{
	  switch (pdata->type)
	  {
76
	    case PT_GUID:
77
	    case PT_SHELLEXT:
78
	    case PT_YAGUID:
79 80 81 82 83 84
	      return NULL;

	    case PT_DRIVE:
	    case PT_DRIVE1:
	    case PT_DRIVE2:
	    case PT_DRIVE3:
85
              return pdata->u.drive.szDriveName;
86 87 88 89 90 91

	    case PT_FOLDER:
	    case PT_FOLDER1:
	    case PT_VALUE:
	    case PT_IESPECIAL1:
	    case PT_IESPECIAL2:
92
              return pdata->u.file.szNames;
93 94 95 96

	    case PT_WORKGRP:
	    case PT_COMP:
	    case PT_NETWORK:
97
	    case PT_NETPROVIDER:
98
	    case PT_SHARE:
99
              return pdata->u.network.szNames;
100 101 102 103 104
	  }
	}
	return NULL;
}

105
static
106
LPCWSTR _dbg_ILGetTextPointerW(LPCITEMIDLIST pidl)
107
{
108
	const PIDLDATA* pdata =_dbg_ILGetDataPointer(pidl);
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

	if (pdata)
	{
	  switch (pdata->type)
	  {
	    case PT_GUID:
	    case PT_SHELLEXT:
	    case PT_YAGUID:
	      return NULL;

	    case PT_DRIVE:
	    case PT_DRIVE1:
	    case PT_DRIVE2:
	    case PT_DRIVE3:
	      /* return (LPSTR)&(pdata->u.drive.szDriveName);*/
	      return NULL;

	    case PT_FOLDER:
	    case PT_FOLDER1:
	    case PT_VALUE:
	    case PT_IESPECIAL1:
	    case PT_IESPECIAL2:
	      /* return (LPSTR)&(pdata->u.file.szNames); */
	      return NULL;

	    case PT_WORKGRP:
	    case PT_COMP:
	    case PT_NETWORK:
	    case PT_NETPROVIDER:
	    case PT_SHARE:
	      /* return (LPSTR)&(pdata->u.network.szNames); */
	      return NULL;

	    case PT_VALUEW:
143
	      return (LPCWSTR)pdata->u.file.szNames;
144 145 146 147 148 149
	  }
	}
	return NULL;
}


150
static
151
LPCSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
152
{
153
	const PIDLDATA* pdata =_dbg_ILGetDataPointer(pidl);
154 155 156 157 158 159 160 161 162

	if (pdata)
	{
	  switch (pdata->type)
	  {
	    case PT_FOLDER:
	    case PT_VALUE:
	    case PT_IESPECIAL1:
	    case PT_IESPECIAL2:
163
              return pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1;
164 165

	    case PT_WORKGRP:
166
              return pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1;
167 168 169 170 171
	  }
	}
	return NULL;
}

172
static
173
LPCWSTR _dbg_ILGetSTextPointerW(LPCITEMIDLIST pidl)
174
{
175
	const PIDLDATA* pdata =_dbg_ILGetDataPointer(pidl);
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192

	if (pdata)
	{
	  switch (pdata->type)
	  {
	    case PT_FOLDER:
	    case PT_VALUE:
	    case PT_IESPECIAL1:
	    case PT_IESPECIAL2:
	      /*return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1); */
	      return NULL;

	    case PT_WORKGRP:
	      /* return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1); */
	      return NULL;

	    case PT_VALUEW:
193
	      return (LPCWSTR)(pdata->u.file.szNames + lstrlenW ((LPCWSTR)pdata->u.file.szNames) + 1);
194 195 196 197 198 199
	  }
	}
	return NULL;
}


200 201
static
IID* _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
202 203 204 205 206 207 208
{
	LPPIDLDATA pdata =_ILGetDataPointer(pidl);

	if (pdata)
	{
	  switch (pdata->type)
	  {
209
	    case PT_SHELLEXT:
210
	    case PT_GUID:
Huw Davies's avatar
Huw Davies committed
211
            case PT_YAGUID:
212
	      return &(pdata->u.guid.guid);
213 214 215 216 217
	  }
	}
	return NULL;
}

218
static
219
void _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
220
{
221 222
	LPCSTR		szSrc;
	LPCWSTR		szSrcW;
223
	GUID const * 	riid;
224

225
	if (!pidl) return;
226 227 228 229

	if (szOut)
	  *szOut = 0;

230
	if (_dbg_ILIsDesktop(pidl))
231 232
	{
	 /* desktop */
233
	  if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
234 235 236 237
	}
	else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
	{
	  /* filesystem */
238
	  if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
239
	}
240 241 242 243 244 245 246
	else if (( szSrcW = _dbg_ILGetTextPointerW(pidl) ))
	{
	  CHAR tmp[MAX_PATH];
	  /* unicode filesystem */
	  WideCharToMultiByte(CP_ACP,0,szSrcW, -1, tmp, MAX_PATH, NULL, NULL);
	  if (szOut) lstrcpynA(szOut, tmp, uOutSize);
	}
247 248 249
	else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
	{
	  if (szOut)
250
            sprintf( szOut, "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
251 252 253 254 255 256 257 258 259 260 261
                 riid->Data1, riid->Data2, riid->Data3,
                 riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
                 riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
	}
}




void pdump (LPCITEMIDLIST pidl)
{
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276
    LPCITEMIDLIST pidltemp = pidl;

    if (!TRACE_ON(pidl)) return;

    if (! pidltemp)
    {
      MESSAGE ("-------- pidl=NULL (Desktop)\n");
    }
    else
    {
      MESSAGE ("-------- pidl=%p\n", pidl);
      if (pidltemp->mkid.cb)
      {
        do
        {
277 278 279
          if (_ILIsUnicode(pidltemp))
          {
              DWORD dwAttrib = 0;
280
              const PIDLDATA* pData   = _dbg_ILGetDataPointer(pidltemp);
281
              DWORD type = pData ? pData->type : 0;
282 283
              LPCWSTR szLongName   = _dbg_ILGetTextPointerW(pidltemp);
              LPCWSTR szShortName  = _dbg_ILGetSTextPointerW(pidltemp);
284 285 286 287 288 289
              char szName[MAX_PATH];

              _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
              if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
                dwAttrib = pData->u.file.uFileAttribs;

290
              MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
291 292 293 294 295 296
                       pidltemp, pidltemp->mkid.cb, type, dwAttrib,
                           debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName));
          }
          else
          {
              DWORD dwAttrib = 0;
297
              const PIDLDATA* pData   = _dbg_ILGetDataPointer(pidltemp);
298
              DWORD type = pData ? pData->type : 0;
299 300
              LPCSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
              LPCSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
301 302 303 304 305 306
              char szName[MAX_PATH];

              _dbg_ILSimpleGetText(pidltemp, szName, MAX_PATH);
              if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
                dwAttrib = pData->u.file.uFileAttribs;

307
              MESSAGE ("[%p] size=%04u type=%lx attr=0x%08lx name=%s (%s,%s)\n",
308 309 310
                       pidltemp, pidltemp->mkid.cb, type, dwAttrib,
                           debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName));
          }
311

312
          pidltemp = _dbg_ILGetNext(pidltemp);
313

314 315 316 317 318 319 320 321
        } while (pidltemp && pidltemp->mkid.cb);
      }
      else
      {
        MESSAGE ("empty pidl (Desktop)\n");
      }
      pcheck(pidl);
    }
322
}
323 324

static void dump_pidl_hex( LPCITEMIDLIST pidl )
325
{
326
    const unsigned char *p = (const unsigned char *)pidl;
327 328
    const int max_bytes = 0x80;
#define max_line 0x10
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343
    char szHex[max_line*3+1], szAscii[max_line+1];
    int i, n;

    n = pidl->mkid.cb;
    if( n>max_bytes )
        n = max_bytes;
    for( i=0; i<n; i++ )
    {
        sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
        szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';

        /* print out at the end of each line and when we're finished */
        if( i!=(n-1) && (i%max_line) != (max_line-1) )
            continue;
        szAscii[ (i%max_line)+1 ] = 0;
344
        ERR("%-*s   %s\n", max_line*3, szHex, szAscii );
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
    }
}

BOOL pcheck( LPCITEMIDLIST pidl )
{
    DWORD type;
    LPCITEMIDLIST pidltemp = pidl;

    while( pidltemp && pidltemp->mkid.cb )
    {
        type = _dbg_ILGetDataPointer(pidltemp)->type;
        switch( type )
        {
        case PT_CPLAPPLET:
        case PT_GUID:
        case PT_SHELLEXT:
        case PT_DRIVE:
        case PT_DRIVE1:
        case PT_DRIVE2:
        case PT_DRIVE3:
        case PT_FOLDER:
        case PT_VALUE:
Huw Davies's avatar
Huw Davies committed
367
        case PT_VALUEW:
368 369 370 371 372 373 374 375 376 377 378
        case PT_FOLDER1:
        case PT_WORKGRP:
        case PT_COMP:
        case PT_NETPROVIDER:
        case PT_NETWORK:
        case PT_IESPECIAL1:
        case PT_YAGUID:
        case PT_IESPECIAL2:
        case PT_SHARE:
            break;
        default:
379
            ERR("unknown IDLIST %p [%p] size=%u type=%lx\n",
380 381 382 383 384 385 386
                pidl, pidltemp, pidltemp->mkid.cb,type );
            dump_pidl_hex( pidltemp );
            return FALSE;
        }
        pidltemp = _dbg_ILGetNext(pidltemp);
    }
    return TRUE;
387
}
388

389
static const struct {
390 391
	REFIID riid;
	const char *name;
392 393
} InterfaceDesc[] = {
	{&IID_IUnknown,			"IID_IUnknown"},
394
	{&IID_IClassFactory,		"IID_IClassFactory"},
395 396 397 398 399 400 401 402 403 404 405 406 407 408
	{&IID_IShellView,		"IID_IShellView"},
	{&IID_IOleCommandTarget,	"IID_IOleCommandTarget"},
	{&IID_IDropTarget,		"IID_IDropTarget"},
	{&IID_IDropSource,		"IID_IDropSource"},
	{&IID_IViewObject,		"IID_IViewObject"},
	{&IID_IContextMenu,		"IID_IContextMenu"},
	{&IID_IShellExtInit,		"IID_IShellExtInit"},
	{&IID_IShellFolder,		"IID_IShellFolder"},
	{&IID_IShellFolder2,		"IID_IShellFolder2"},
	{&IID_IPersist,			"IID_IPersist"},
	{&IID_IPersistFolder,		"IID_IPersistFolder"},
	{&IID_IPersistFolder2,		"IID_IPersistFolder2"},
	{&IID_IPersistFolder3,		"IID_IPersistFolder3"},
	{&IID_IExtractIconA,		"IID_IExtractIconA"},
409
	{&IID_IExtractIconW,		"IID_IExtractIconW"},
410
	{&IID_IDataObject,		"IID_IDataObject"},
411 412
	{&IID_IAutoComplete,            "IID_IAutoComplete"},
	{&IID_IAutoComplete2,           "IID_IAutoComplete2"},
Huw Davies's avatar
Huw Davies committed
413 414
        {&IID_IShellLinkA,              "IID_IShellLinkA"},
        {&IID_IShellLinkW,              "IID_IShellLinkW"},
415 416 417 418 419
	{NULL,NULL}};

const char * shdebugstr_guid( const struct _GUID *id )
{
	int i;
420
	const char* name = NULL;
421 422
	char clsidbuf[100];

423
	if (!id) return "(null)";
424

425 426 427 428 429 430 431 432 433
	for (i = 0; InterfaceDesc[i].riid && !name; i++) {
	    if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
	}
	if (!name) {
	    if (HCR_GetClassNameA(id, clsidbuf, 100))
		name = clsidbuf;
	}

        return wine_dbg_sprintf( "%s (%s)", debugstr_guid(id), name ? name : "unknown" );
434
}