ReactOS  0.4.14-dev-608-gd495a4f
debughlp.cpp
Go to the documentation of this file.
1 /*
2  * Helper functions for debugging
3  *
4  * Copyright 1998, 2002 Juergen Schmied
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * 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 #include "precomp.h"
22 
24 
25 static
27 {
28  WORD len;
29 
30  if(pidl)
31  {
32  len = pidl->mkid.cb;
33  if (len)
34  {
35  return (LPITEMIDLIST) (((LPBYTE)pidl)+len);
36  }
37  }
38  return NULL;
39 }
40 
41 static
43 {
44  return ( !pidl || (pidl && pidl->mkid.cb == 0x00) );
45 }
46 
47 static
49 {
50  if(pidl && pidl->mkid.cb != 0x00)
51  return (LPPIDLDATA) &(pidl->mkid.abID);
52  return NULL;
53 }
54 
55 static
57 {
59 
60  if (pdata)
61  {
62  switch (pdata->type)
63  {
64  case PT_GUID:
65  case PT_SHELLEXT:
66  case PT_YAGUID:
67  return NULL;
68 
69  case PT_DRIVE:
70  case PT_DRIVE1:
71  case PT_DRIVE2:
72  case PT_DRIVE3:
73  return (LPSTR)&(pdata->u.drive.szDriveName);
74 
75  case PT_FOLDER:
76  case PT_FOLDER1:
77  case PT_VALUE:
78  case PT_IESPECIAL1:
79  case PT_IESPECIAL2:
80  return (LPSTR)&(pdata->u.file.szNames);
81 
82  case PT_WORKGRP:
83  case PT_COMP:
84  case PT_NETWORK:
85  case PT_NETPROVIDER:
86  case PT_SHARE:
87  return (LPSTR)&(pdata->u.network.szNames);
88  }
89  }
90  return NULL;
91 }
92 
93 static
95 {
97 
98  if (pdata)
99  {
100  switch (pdata->type)
101  {
102  case PT_GUID:
103  case PT_SHELLEXT:
104  case PT_YAGUID:
105  return NULL;
106 
107  case PT_DRIVE:
108  case PT_DRIVE1:
109  case PT_DRIVE2:
110  case PT_DRIVE3:
111  /* return (LPSTR)&(pdata->u.drive.szDriveName);*/
112  return NULL;
113 
114  case PT_FOLDER:
115  case PT_FOLDER1:
116  case PT_VALUE:
117  case PT_IESPECIAL1:
118  case PT_IESPECIAL2:
119  /* return (LPSTR)&(pdata->u.file.szNames); */
120  return NULL;
121 
122  case PT_WORKGRP:
123  case PT_COMP:
124  case PT_NETWORK:
125  case PT_NETPROVIDER:
126  case PT_SHARE:
127  /* return (LPSTR)&(pdata->u.network.szNames); */
128  return NULL;
129 
130  case PT_VALUEW:
131  return (LPWSTR)&(pdata->u.file.szNames);
132  }
133  }
134  return NULL;
135 }
136 
137 
138 static
140 {
142 
143  if (pdata)
144  {
145  switch (pdata->type)
146  {
147  case PT_FOLDER:
148  case PT_VALUE:
149  case PT_IESPECIAL1:
150  case PT_IESPECIAL2:
151  return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1);
152 
153  case PT_WORKGRP:
154  return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1);
155  }
156  }
157  return NULL;
158 }
159 
160 static
162 {
164 
165  if (pdata)
166  {
167  switch (pdata->type)
168  {
169  case PT_FOLDER:
170  case PT_VALUE:
171  case PT_IESPECIAL1:
172  case PT_IESPECIAL2:
173  /*return (LPSTR)(pdata->u.file.szNames + strlen (pdata->u.file.szNames) + 1); */
174  return NULL;
175 
176  case PT_WORKGRP:
177  /* return (LPSTR)(pdata->u.network.szNames + strlen (pdata->u.network.szNames) + 1); */
178  return NULL;
179 
180  case PT_VALUEW:
181  return (LPWSTR)(pdata->u.file.szNames + wcslen ((LPWSTR)pdata->u.file.szNames) + 1);
182  }
183  }
184  return NULL;
185 }
186 
187 
188 static
190 {
192 
193  if (pdata)
194  {
195  switch (pdata->type)
196  {
197  case PT_SHELLEXT:
198  case PT_GUID:
199  case PT_YAGUID:
200  return &(pdata->u.guid.guid);
201  }
202  }
203  return NULL;
204 }
205 
206 static
207 void _dbg_ILSimpleGetText (LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
208 {
209  LPSTR szSrc;
210  LPWSTR szSrcW;
211  GUID const * riid;
212 
213  if (!pidl) return;
214 
215  if (szOut)
216  *szOut = 0;
217 
218  if (_dbg_ILIsDesktop(pidl))
219  {
220  /* desktop */
221  if (szOut) lstrcpynA(szOut, "Desktop", uOutSize);
222  }
223  else if (( szSrc = _dbg_ILGetTextPointer(pidl) ))
224  {
225  /* filesystem */
226  if (szOut) lstrcpynA(szOut, szSrc, uOutSize);
227  }
228  else if (( szSrcW = _dbg_ILGetTextPointerW(pidl) ))
229  {
230  CHAR tmp[MAX_PATH];
231  /* unicode filesystem */
232  WideCharToMultiByte(CP_ACP,0,szSrcW, -1, tmp, MAX_PATH, NULL, NULL);
233  if (szOut) lstrcpynA(szOut, tmp, uOutSize);
234  }
235  else if (( riid = _dbg_ILGetGUIDPointer(pidl) ))
236  {
237  if (szOut)
238  sprintf( szOut, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
239  riid->Data1, riid->Data2, riid->Data3,
240  riid->Data4[0], riid->Data4[1], riid->Data4[2], riid->Data4[3],
241  riid->Data4[4], riid->Data4[5], riid->Data4[6], riid->Data4[7] );
242  }
243 }
244 
245 
246 
247 
248 void pdump (LPCITEMIDLIST pidl)
249 {
250  LPCITEMIDLIST pidltemp = pidl;
251 
252  if (!TRACE_ON(pidl)) return;
253 
254  if (! pidltemp)
255  {
256  MESSAGE ("-------- pidl=NULL (Desktop)\n");
257  }
258  else
259  {
260  MESSAGE ("-------- pidl=%p\n", pidl);
261  if (pidltemp->mkid.cb)
262  {
263  do
264  {
265  if (_ILIsUnicode(pidltemp))
266  {
267  DWORD dwAttrib = 0;
269  DWORD type = pData ? pData->type : 0;
270  LPWSTR szLongName = _dbg_ILGetTextPointerW(pidltemp);
271  LPWSTR szShortName = _dbg_ILGetSTextPointerW(pidltemp);
272  char szName[MAX_PATH];
273 
275  if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
276  dwAttrib = pData->u.file.uFileAttribs;
277 
278  MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
279  pidltemp, pidltemp->mkid.cb, type, dwAttrib,
280  debugstr_a(szName), debugstr_w(szLongName), debugstr_w(szShortName));
281  }
282  else
283  {
284  DWORD dwAttrib = 0;
286  DWORD type = pData ? pData->type : 0;
287  LPSTR szLongName = _dbg_ILGetTextPointer(pidltemp);
288  LPSTR szShortName = _dbg_ILGetSTextPointer(pidltemp);
289  char szName[MAX_PATH];
290 
292  if ( pData && (PT_FOLDER == type || PT_VALUE == type) )
293  dwAttrib = pData->u.file.uFileAttribs;
294 
295  MESSAGE ("[%p] size=%04u type=%x attr=0x%08x name=%s (%s,%s)\n",
296  pidltemp, pidltemp->mkid.cb, type, dwAttrib,
297  debugstr_a(szName), debugstr_a(szLongName), debugstr_a(szShortName));
298  }
299 
300  pidltemp = _dbg_ILGetNext(pidltemp);
301 
302  } while (pidltemp && pidltemp->mkid.cb);
303  }
304  else
305  {
306  MESSAGE ("empty pidl (Desktop)\n");
307  }
308  pcheck(pidl);
309  }
310 }
311 
312 static void dump_pidl_hex( LPCITEMIDLIST pidl )
313 {
314  const unsigned char *p = (const unsigned char *)pidl;
315  const int max_bytes = 0x80;
316 #define max_line 0x10
317  char szHex[max_line*3+1], szAscii[max_line+1];
318  int i, n;
319 
320  n = pidl->mkid.cb;
321  if( n>max_bytes )
322  n = max_bytes;
323  for( i=0; i<n; i++ )
324  {
325  sprintf( &szHex[ (i%max_line)*3 ], "%02X ", p[i] );
326  szAscii[ (i%max_line) ] = isprint( p[i] ) ? p[i] : '.';
327 
328  /* print out at the end of each line and when we're finished */
329  if( i!=(n-1) && (i%max_line) != (max_line-1) )
330  continue;
331  szAscii[ (i%max_line)+1 ] = 0;
332  ERR("%-*s %s\n", max_line*3, szHex, szAscii );
333  }
334 }
335 
337 {
338  DWORD type;
339  LPCITEMIDLIST pidltemp = pidl;
340 
341  while( pidltemp && pidltemp->mkid.cb )
342  {
343  LPPIDLDATA pidlData = _dbg_ILGetDataPointer(pidltemp);
344 
345  if (pidlData)
346  {
347  type = pidlData->type;
348  switch( type )
349  {
350  case PT_CPLAPPLET:
351  case PT_GUID:
352  case PT_SHELLEXT:
353  case PT_DRIVE:
354  case PT_DRIVE1:
355  case PT_DRIVE2:
356  case PT_DRIVE3:
357  case PT_FOLDER:
358  case PT_VALUE:
359  case PT_VALUEW:
360  case PT_FOLDER1:
361  case PT_WORKGRP:
362  case PT_COMP:
363  case PT_NETPROVIDER:
364  case PT_NETWORK:
365  case PT_IESPECIAL1:
366  case PT_YAGUID:
367  case PT_IESPECIAL2:
368  case PT_SHARE:
369  break;
370  default:
371  ERR("unknown IDLIST %p [%p] size=%u type=%x\n",
372  pidl, pidltemp, pidltemp->mkid.cb,type );
373  dump_pidl_hex( pidltemp );
374  return FALSE;
375  }
376  pidltemp = _dbg_ILGetNext(pidltemp);
377  }
378  else
379  {
380  return FALSE;
381  }
382  }
383  return TRUE;
384 }
385 
386 static const struct {
388  const char *name;
389 } InterfaceDesc[] = {
390  {IID_IUnknown, "IID_IUnknown"},
391  {IID_IClassFactory, "IID_IClassFactory"},
392  {IID_IShellView, "IID_IShellView"},
393  {IID_IOleCommandTarget, "IID_IOleCommandTarget"},
394  {IID_IDropTarget, "IID_IDropTarget"},
395  {IID_IDropSource, "IID_IDropSource"},
396  {IID_IViewObject, "IID_IViewObject"},
397  {IID_IContextMenu, "IID_IContextMenu"},
398  {IID_IShellExtInit, "IID_IShellExtInit"},
399  {IID_IShellFolder, "IID_IShellFolder"},
400  {IID_IShellFolder2, "IID_IShellFolder2"},
401  {IID_IPersist, "IID_IPersist"},
402  {IID_IPersistFolder, "IID_IPersistFolder"},
403  {IID_IPersistFolder2, "IID_IPersistFolder2"},
404  {IID_IPersistFolder3, "IID_IPersistFolder3"},
405  {IID_IExtractIconA, "IID_IExtractIconA"},
406  {IID_IExtractIconW, "IID_IExtractIconW"},
407  {IID_IDataObject, "IID_IDataObject"},
408  {IID_IAutoComplete, "IID_IAutoComplete"},
409  {IID_IAutoComplete2, "IID_IAutoComplete2"},
410  {IID_IShellLinkA, "IID_IShellLinkA"},
411  {IID_IShellLinkW, "IID_IShellLinkW"},
412  };
413 
414 const char * shdebugstr_guid( const struct _GUID *id )
415 {
416  unsigned int i;
417  const char* name = NULL;
418  char clsidbuf[100];
419 
420  if (!id) return "(null)";
421 
422  for (i=0; i < sizeof(InterfaceDesc) / sizeof(InterfaceDesc[0]); i++) {
424  }
425  if (!name) {
426  if (HCR_GetClassNameA(*id, clsidbuf, 100))
427  name = clsidbuf;
428  }
429 
430  return wine_dbg_sprintf( "\n\t{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x} (%s)",
431  id->Data1, id->Data2, id->Data3,
432  id->Data4[0], id->Data4[1], id->Data4[2], id->Data4[3],
433  id->Data4[4], id->Data4[5], id->Data4[6], id->Data4[7], name ? name : "unknown" );
434 }
static BOOL _dbg_ILIsDesktop(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:42
static LPPIDLDATA _dbg_ILGetDataPointer(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:48
#define REFIID
Definition: guiddef.h:118
#define TRUE
Definition: types.h:120
const GUID IID_IViewObject
LPPIDLDATA _ILGetDataPointer(LPCITEMIDLIST pidl)
Definition: pidl.c:2162
#define WideCharToMultiByte
Definition: compat.h:101
#define MESSAGE
Definition: options.h:86
Definition: scsiwmi.h:51
#define PT_DRIVE3
Definition: pidl.h:90
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
REFIID riid
Definition: precomp.h:44
#define CP_ACP
Definition: compat.h:99
const GUID IID_IPersist
Definition: proxy.cpp:14
WINE_DEFAULT_DEBUG_CHANNEL(pidl)
char CHAR
Definition: xmlstorage.h:175
const ITEMIDLIST UNALIGNED * LPCITEMIDLIST
Definition: shtypes.idl:42
GLdouble n
Definition: glext.h:7729
const char * shdebugstr_guid(const struct _GUID *id)
Definition: debughlp.cpp:414
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define PT_WORKGRP
Definition: pidl.h:98
const GUID IID_IDataObject
#define PT_IESPECIAL2
Definition: pidl.h:104
char * LPSTR
Definition: xmlstorage.h:182
#define PT_NETWORK
Definition: pidl.h:101
static LPWSTR _dbg_ILGetTextPointerW(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:94
const char * wine_dbg_sprintf(const char *format,...)
Definition: compat.c:271
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static const struct @537 InterfaceDesc[]
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
#define max_line
#define debugstr_w
Definition: kernel32.h:32
BOOL _ILIsUnicode(LPCITEMIDLIST pidl)
Definition: pidl.c:1868
smooth NULL
Definition: ftsmooth.c:416
#define PT_DRIVE2
Definition: pidl.h:89
static PROTOCOLDATA * pdata
Definition: protocol.c:158
#define PT_DRIVE
Definition: pidl.h:88
static void _dbg_ILSimpleGetText(LPCITEMIDLIST pidl, LPSTR szOut, UINT uOutSize)
Definition: debughlp.cpp:207
#define PT_YAGUID
static IID * _dbg_ILGetGUIDPointer(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:189
#define debugstr_a
Definition: kernel32.h:31
const GUID IID_IUnknown
#define MAX_PATH
Definition: compat.h:26
unsigned short WORD
Definition: ntddk_ex.h:93
BOOL HCR_GetClassNameA(REFIID riid, LPSTR szDest, DWORD len)
Definition: classes.c:423
unsigned long DWORD
Definition: ntddk_ex.h:95
static LPITEMIDLIST _dbg_ILGetNext(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:26
GLenum GLsizei len
Definition: glext.h:6722
static LPSTR _dbg_ILGetTextPointer(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:56
#define PT_FOLDER1
Definition: pidl.h:93
#define PT_IESPECIAL1
Definition: pidl.h:102
#define ERR(fmt,...)
Definition: debug.h:109
#define PT_COMP
Definition: pidl.h:99
void pdump(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:248
#define PT_DRIVE1
Definition: pidl.h:92
unsigned int UINT
Definition: ndis.h:50
BOOL pcheck(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:336
REFIID riid
Definition: debughlp.cpp:387
#define lstrcpynA
Definition: compat.h:416
static LPSTR _dbg_ILGetSTextPointer(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:139
#define isprint(c)
Definition: acclib.h:73
#define PT_VALUE
Definition: pidl.h:95
Definition: name.c:38
static const WCHAR szName[]
Definition: msipriv.h:1194
#define PT_NETPROVIDER
Definition: pidl.h:100
GLenum GLuint id
Definition: glext.h:5579
const char * name
Definition: debughlp.cpp:388
static LPWSTR _dbg_ILGetSTextPointerW(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:161
#define PT_FOLDER
Definition: pidl.h:94
#define PT_SHARE
Definition: pidl.h:105
#define PT_CPLAPPLET
Definition: pidl.h:86
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
const GUID IID_IClassFactory
ITEMIDLIST UNALIGNED * LPITEMIDLIST
Definition: shtypes.idl:41
#define TRACE_ON(x)
Definition: compat.h:65
#define PT_GUID
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define IsEqualIID(riid1, riid2)
Definition: guiddef.h:95
#define PT_VALUEW
Definition: pidl.h:96
#define PT_SHELLEXT
static void dump_pidl_hex(LPCITEMIDLIST pidl)
Definition: debughlp.cpp:312