debughlp.c 10.9 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
LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
39 40 41 42 43 44 45 46
{
	WORD len;

	if(pidl)
	{
	  len =  pidl->mkid.cb;
	  if (len)
	  {
47
	    return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
48 49 50 51 52
	  }
	}
	return NULL;
}

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

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

67
static
68 69 70 71 72 73 74 75
LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
{
	LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);

	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 (LPSTR)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 (LPSTR)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 (LPSTR)pdata->u.network.szNames;
100 101 102 103 104
	  }
	}
	return NULL;
}

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
static
LPWSTR _dbg_ILGetTextPointerW(LPCITEMIDLIST pidl)
{
	LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);

	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 (LPWSTR)pdata->u.file.szNames;
144 145 146 147 148 149
	  }
	}
	return NULL;
}


150
static
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171
LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
{
	LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);

	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);

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

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
static
LPWSTR _dbg_ILGetSTextPointerW(LPCITEMIDLIST pidl)
{
	LPPIDLDATA pdata =_dbg_ILGetDataPointer(pidl);

	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:
	      return (LPWSTR)(pdata->u.file.szNames + lstrlenW ((LPWSTR)pdata->u.file.szNames) + 1);
	  }
	}
	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
{
	LPSTR		szSrc;
222
	LPWSTR		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, "{%08x-%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
	LPCITEMIDLIST pidltemp = pidl;
263 264 265 266 267 268 269 270 271 272 273

	if (!TRACE_ON(pidl)) return;

	if (! pidltemp)
	{
	  MESSAGE ("-------- pidl=NULL (Desktop)\n");
	}
	else
	{
	  MESSAGE ("-------- pidl=%p\n", pidl);
	  if (pidltemp->mkid.cb)
274
	  {
275 276
	    do
	    {
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
          if (_ILIsUnicode(pidltemp))
          {
              DWORD dwAttrib = 0;
              LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
              DWORD type = pData ? pData->type : 0;
              LPWSTR szLongName   = _dbg_ILGetTextPointerW(pidltemp);
              LPWSTR szShortName  = _dbg_ILGetSTextPointerW(pidltemp);
              char szName[MAX_PATH];

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

              MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
                       pidltemp, pidltemp->mkid.cb, type, dwAttrib,
                           debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName));
          }
          else
          {
              DWORD dwAttrib = 0;
              LPPIDLDATA pData   = _dbg_ILGetDataPointer(pidltemp);
              DWORD type = pData ? pData->type : 0;
              LPSTR szLongName   = _dbg_ILGetTextPointer(pidltemp);
              LPSTR szShortName  = _dbg_ILGetSTextPointer(pidltemp);
              char szName[MAX_PATH];

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

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

	      pidltemp = _dbg_ILGetNext(pidltemp);

314
	    } while (pidltemp && pidltemp->mkid.cb);
315 316 317 318 319 320 321 322
	  }
	  else
	  {
	    MESSAGE ("empty pidl (Desktop)\n");
	  }
	  pcheck(pidl);
	}
}
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=%x\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
	    for (i=0;InterfaceDesc[i].riid && !name;i++) {
	        if (IsEqualIID(InterfaceDesc[i].riid, id)) name = InterfaceDesc[i].name;
	    }
	    if (!name) {
429
		if (HCR_GetClassNameA(id, clsidbuf, 100))
430 431 432
		    name = clsidbuf;
	    }

433
            return wine_dbg_sprintf( "\n\t{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
434 435 436 437
                 id->Data1, id->Data2, id->Data3,
                 id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
                 id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
}