Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

615 lines
18 KiB

  1. /****************************** Module Header ******************************\
  2. * Module Name: shlexts.c
  3. *
  4. * Copyright (c) 1997, Microsoft Corporation
  5. *
  6. * This module contains user related debugging extensions.
  7. *
  8. * History:
  9. * 10/28/97 created by cdturner (butchered from the userexts.dll)
  10. \***************************************************************************/
  11. #include <precomp.h>
  12. #pragma hdrstop
  13. #include <winver.h>
  14. #include <shlwapi.h>
  15. char * pszExtName = "SHLEXTS";
  16. #include <stdexts.h>
  17. #include <stdexts.c>
  18. BOOL bShowFlagNames = TRUE;
  19. #define NO_FLAG INVALID_HANDLE_VALUE // use this for non-meaningful entries.
  20. LPSTR apszSFGAOFlags[] =
  21. {
  22. "SFGAO_CANCOPY", // 0x00000001L
  23. "SFGAO_CANMOVE", // 0x00000002L
  24. "SFGAO_CANLINK", // 0x00000004L
  25. NO_FLAG,
  26. "SFGAO_CANRENAME", // 0x00000010L // Objects can be renamed
  27. "SFGAO_CANDELETE", // 0x00000020L // Objects can be deleted
  28. "SFGAO_HASPROPSHEET", // 0x00000040L // Objects have property sheets
  29. NO_FLAG,
  30. "SFGAO_DROPTARGET", // 0x00000100L // Objects are drop target
  31. NO_FLAG,
  32. NO_FLAG,
  33. NO_FLAG,
  34. "SFGAO_LINK", // 0x00010000L // Shortcut (link)
  35. "SFGAO_SHARE", // 0x00020000L // shared
  36. "SFGAO_READONLY", // 0x00040000L // read-only
  37. "SFGAO_GHOSTED", // 0x00080000L // ghosted icon
  38. "SFGAO_NONENUMERATED", // 0x00100000L // is a non-enumerated object
  39. "SFGAO_NEWCONTENT", // 0x00200000L // should show bold in explorer tree
  40. NO_FLAG,
  41. NO_FLAG,
  42. "SFGAO_VALIDATE", // 0x01000000L // invalidate cached information
  43. "SFGAO_REMOVABLE", // 0x02000000L // is this removeable media?
  44. "SFGAO_COMPRESSED", // 0x04000000L // Object is compressed (use alt color)
  45. "SFGAO_BROWSABLE", // 0x08000000L // is in-place browsable
  46. "SFGAO_FILESYSANCESTOR",// 0x10000000L // It contains file system folder
  47. "SFGAO_FOLDER", // 0x20000000L // It's a folder.
  48. "SFGAO_FILESYSTEM", // 0x40000000L // is a file system thing (file/folder/root)
  49. "SFGAO_HASSUBFOLDER", // 0x80000000L // Expandable in the map pane
  50. NULL
  51. };
  52. LPSTR apszSLDFFlags[] =
  53. {
  54. "SLDF_HAS_ID_LIST", // = 0x0001, // Shell link saved with ID list
  55. "SLDF_HAS_LINK_INFO", // = 0x0002, // Shell link saved with LinkInfo
  56. "SLDF_HAS_NAME", // = 0x0004,
  57. "SLDF_HAS_RELPATH", // = 0x0008,
  58. "SLDF_HAS_WORKINGDIR", // = 0x0010,
  59. "SLDF_HAS_ARGS", // = 0x0020,
  60. "SLDF_HAS_ICONLOCATION", // = 0x0040,
  61. "SLDF_UNICODE", // = 0x0080, // the strings are unicode (NT is comming!)
  62. "SLDF_FORCE_NO_LINKINFO",// = 0x0100, // don't create a LINKINFO (make a dumb link)
  63. "SLDF_HAS_EXP_SZ" // = 0x0200, // the link contains expandable env strings
  64. "SLDF_RUN_IN_SEPARATE", // = 0x0400, // Run the 16-bit target exe in a separate VDM/WOW
  65. "SLDF_HAS_LOGO3ID", // = 0x0800, // this link is a special Logo3/MSICD link
  66. "SLDF_HAS_DARWINID", // = 0x1000 // this link is a special Darwin link
  67. NULL
  68. };
  69. LPSTR apszFWFFlags[] =
  70. {
  71. "FWF_AUTOARRANGE", // = 0x0001,
  72. "FWF_ABBREVIATEDNAMES", // = 0x0002,
  73. "FWF_SNAPTOGRID", // = 0x0004,
  74. "FWF_OWNERDATA", // = 0x0008,
  75. "FWF_BESTFITWINDOW", // = 0x0010,
  76. "FWF_DESKTOP", // = 0x0020,
  77. "FWF_SINGLESEL", // = 0x0040,
  78. "FWF_NOSUBFOLDERS", // = 0x0080,
  79. "FWF_TRANSPARENT", // = 0x0100,
  80. "FWF_NOCLIENTEDGE", // = 0x0200,
  81. "FWF_NOSCROLL", // = 0x0400,
  82. "FWF_ALIGNLEFT", // = 0x0800,
  83. "FWF_NOICONS", // = 0x1000,
  84. "FWF_SINGLECLICKACTIVATE", // = 0x8000 // TEMPORARY -- NO UI FOR THIS
  85. NULL
  86. };
  87. LPSTR apszICIFlags[] =
  88. {
  89. "ICIFLAG_LARGE", // 0x0001
  90. "ICIFLAG_SMALL", // 0x0002
  91. "ICIFLAG_BITMAP", // 0x0004
  92. "ICIFLAG_ICON", // 0x0008
  93. "ICIFLAG_INDEX", // 0x0010
  94. "ICIFLAG_NAME", // 0x0020
  95. "ICIFLAG_FLAGS", // 0x0040
  96. "ICIFLAG_NOUSAGE", // 0x0080
  97. NULL
  98. };
  99. LPSTR apszFDFlags[] =
  100. {
  101. "FD_CLSID", // = 0x0001,
  102. "FD_SIZEPOINT", // = 0x0002,
  103. "FD_ATTRIBUTES", // = 0x0004,
  104. "FD_CREATETIME", // = 0x0008,
  105. "FD_ACCESSTIME", // = 0x0010,
  106. "FD_WRITESTIME", // = 0x0020,
  107. "FD_FILESIZE", // = 0x0040,
  108. "FD_LINKUI", // = 0x8000, // 'link' UI is prefered
  109. NULL
  110. };
  111. LPSTR apszSHCNEFlags[] =
  112. {
  113. "SHCNE_RENAMEITEM", // 0x00000001L
  114. "SHCNE_CREATE", // 0x00000002L
  115. "SHCNE_DELETE", // 0x00000004L
  116. "SHCNE_MKDIR", // 0x00000008L
  117. "SHCNE_RMDIR", // 0x00000010L
  118. "SHCNE_MEDIAINSERTED", // 0x00000020L
  119. "SHCNE_MEDIAREMOVED", // 0x00000040L
  120. "SHCNE_DRIVEREMOVED", // 0x00000080L
  121. "SHCNE_DRIVEADD", // 0x00000100L
  122. "SHCNE_NETSHARE", // 0x00000200L
  123. "SHCNE_NETUNSHARE", // 0x00000400L
  124. "SHCNE_ATTRIBUTES", // 0x00000800L
  125. "SHCNE_UPDATEDIR", // 0x00001000L
  126. "SHCNE_UPDATEITEM", // 0x00002000L
  127. "SHCNE_SERVERDISCONNECT", // 0x00004000L
  128. "SHCNE_UPDATEIMAGE", // 0x00008000L
  129. "SHCNE_DRIVEADDGUI", // 0x00010000L
  130. "SHCNE_RENAMEFOLDER", // 0x00020000L
  131. "SHCNE_FREESPACE", // 0x00040000L
  132. NO_FLAG,
  133. NO_FLAG,
  134. NO_FLAG,
  135. "SHCNE_EXTENDED_EVENT", // 0x04000000L
  136. "SHCNE_ASSOCCHANGED", // 0x08000000L
  137. NULL
  138. };
  139. LPSTR apszSSFFlags[] =
  140. {
  141. "SSF_SHOWALLOBJECTS", // 0x0001
  142. "SSF_SHOWEXTENSIONS", // 0x0002
  143. "SSF_WIN95UNUSED", // 0x0004 // ;Internal - corresponding SHELLSTATE fields don't exist in SHELLFLAGSTATE
  144. "SSF_SHOWCOMPCOLOR", // 0x0008
  145. "SSF_SORTCOLUMNS", // 0x0010 // ;Internal - corresponding SHELLSTATE fields don't exist in SHELLFLAGSTATE
  146. "SSF_SHOWSYSFILES", // 0x0020
  147. "SSF_DOUBLECLICKINWEBVIEW", // 0x0080
  148. "SSF_SHOWATTRIBCOL", // 0x0100
  149. "SSF_DESKTOPHTML", // 0x0200
  150. "SSF_WIN95CLASSIC", // 0x0400
  151. "SSF_DONTPRETTYPATH", // 0x0800
  152. "SSF_MAPNETDRVBUTTON", // 0x1000
  153. "SSF_SHOWINFOTIP", // 0x2000
  154. "SSF_HIDEICONS", // 0x4000
  155. "SSF_NOCONFIRMRECYCLE", // 0x8000
  156. "SSF_FILTER", // 0x00010000 // ;Internal - corresponding SHELLSTATE fields don't exist in SHELLFLAGSTATE
  157. "SSF_WEBVIEW", // 0x00020000 // ;Internal
  158. "SSF_SHOWSUPERHIDDEN", // 0x00040000 // ;Internal
  159. "SSF_SEPPROCESS", // 0x00080000 // ;Internal
  160. "SSF_NONETCRAWLING", // 0x00100000 // ;Internal
  161. "SSF_STARTPANELON", // 0x00200000 // ;Internal
  162. NULL
  163. };
  164. enum GF_FLAGS {
  165. GL_SFGAO = 0,
  166. GL_SLDF,
  167. GL_FWF,
  168. GL_ICI,
  169. GL_FD,
  170. GL_SHCNE,
  171. GL_SSF,
  172. GF_MAX,
  173. };
  174. struct _tagFlags
  175. {
  176. LPSTR * apszFlags;
  177. LPSTR pszFlagsname;
  178. } argFlag[GF_MAX] =
  179. {
  180. {apszSFGAOFlags, "SFGAO"},
  181. {apszSLDFFlags, "SLD"},
  182. {apszFWFFlags, "FWF"},
  183. {apszICIFlags, "ICIFLAG"},
  184. {apszFDFlags, "FD"},
  185. {apszSHCNEFlags, "SHCNE"},
  186. {apszSSFFlags, "SSF"}
  187. };
  188. /************************************************************************\
  189. * Procedure: GetFlags
  190. *
  191. * Description:
  192. *
  193. * Converts a 32bit set of flags into an appropriate string.
  194. * pszBuf should be large enough to hold this string, no checks are done.
  195. * pszBuf can be NULL, allowing use of a local static buffer but note that
  196. * this is not reentrant.
  197. * Output string has the form: "FLAG1 | FLAG2 ..." or "0"
  198. *
  199. * Returns: pointer to given or static buffer with string in it.
  200. *
  201. * 6/9/1995 Created SanfordS
  202. * 11/5/1997 cdturner changed the aapszFlag type
  203. *
  204. \************************************************************************/
  205. LPSTR GetFlags(
  206. WORD wType,
  207. DWORD dwFlags,
  208. LPSTR pszBuf,
  209. UINT cchBuf,
  210. BOOL fPrintZero)
  211. {
  212. static char szT[512];
  213. WORD i;
  214. BOOL fFirst = TRUE;
  215. BOOL fNoMoreNames = FALSE;
  216. LPSTR *apszFlags;
  217. if (pszBuf == NULL)
  218. {
  219. pszBuf = szT;
  220. cchBuf = ARRAYSIZE(szT);
  221. }
  222. if (!bShowFlagNames)
  223. {
  224. StringCchPrintfA(pszBuf, cchBuf, "%x", dwFlags);
  225. return pszBuf;
  226. }
  227. *pszBuf = '\0';
  228. if (wType >= GF_MAX)
  229. {
  230. StringCchCopyA(pszBuf, cchBuf, "Invalid flag type.");
  231. return pszBuf;
  232. }
  233. apszFlags = argFlag[wType].apszFlags;
  234. for (i = 0; dwFlags; dwFlags >>= 1, i++)
  235. {
  236. if (!fNoMoreNames && apszFlags[i] == NULL)
  237. {
  238. fNoMoreNames = TRUE;
  239. }
  240. if (dwFlags & 1)
  241. {
  242. if (!fFirst)
  243. {
  244. StringCchCatA(pszBuf, cchBuf, " | ");
  245. }
  246. else
  247. {
  248. fFirst = FALSE;
  249. }
  250. if (fNoMoreNames || apszFlags[i] == NO_FLAG)
  251. {
  252. char ach[16];
  253. StringCchPrintfA(ach, ARRAYSIZE(ach), "0x%lx", 1 << i);
  254. StringCchCatA(pszBuf, cchBuf, ach);
  255. }
  256. else
  257. {
  258. StringCchCatA(pszBuf, cchBuf, apszFlags[i]);
  259. }
  260. }
  261. }
  262. if (fFirst && fPrintZero)
  263. {
  264. StringCchPrintfA(pszBuf, cchBuf, "0");
  265. }
  266. return pszBuf;
  267. }
  268. /************************************************************************\
  269. * Procedure: Iflags
  270. *
  271. * Description:
  272. *
  273. * outputs the list of flags for the given flags type
  274. *
  275. * 11/5/1997 Created cdturner
  276. *
  277. \************************************************************************/
  278. BOOL Iflags( DWORD dwOpts,
  279. LPSTR pszArgs )
  280. {
  281. CHAR szBuffer[100];
  282. int iOffset = 0;
  283. int iFlags;
  284. LPDWORD pAddr;
  285. BOOL bAddr = FALSE;
  286. DWORD dwValue;
  287. LPSTR pszOut;
  288. if ( dwOpts & OFLAG(l))
  289. {
  290. // list all the struct names
  291. Print("Flags types known:\n");
  292. for ( iFlags = 0; iFlags < GF_MAX; iFlags ++ )
  293. {
  294. StringCchPrintfA( szBuffer, ARRAYSIZE(szBuffer), " %s\n", argFlag[iFlags].pszFlagsname);
  295. Print( szBuffer );
  296. }
  297. return TRUE;
  298. }
  299. // skip whitespace
  300. while ( *pszArgs == ' ' )
  301. pszArgs ++;
  302. // now grab the flagsname
  303. while ( pszArgs[iOffset] != ' ' && pszArgs[iOffset] != '\0' )
  304. {
  305. szBuffer[iOffset] = pszArgs[iOffset];
  306. iOffset ++;
  307. };
  308. // terminate the string
  309. szBuffer[iOffset] = 0;
  310. // find the flags value
  311. for ( iFlags = 0; iFlags < GF_MAX; iFlags ++ )
  312. {
  313. if ( lstrcmpA( szBuffer, argFlag[iFlags].pszFlagsname ) == 0 )
  314. break;
  315. }
  316. if ( iFlags >= GF_MAX )
  317. {
  318. Print( "unknown flagsname - ");
  319. Print( szBuffer );
  320. Print( "\n" );
  321. return TRUE;
  322. }
  323. // skip white space
  324. while ( pszArgs[iOffset] == ' ' )
  325. iOffset ++;
  326. if ( pszArgs[iOffset] == '*' )
  327. {
  328. bAddr = TRUE;
  329. iOffset ++;
  330. }
  331. pAddr = (LPDWORD) EvalExp( pszArgs + iOffset );
  332. if ( bAddr )
  333. {
  334. if ( !tryDword( &dwValue, pAddr ) )
  335. {
  336. Print( "unable to access memory at that location\n");
  337. return TRUE;
  338. }
  339. }
  340. else
  341. {
  342. dwValue = PtrToUlong(pAddr);
  343. }
  344. pszOut = GetFlags( (WORD) iFlags, dwValue, NULL, 0, TRUE );
  345. if ( pszOut )
  346. {
  347. StringCchPrintfA( szBuffer, ARRAYSIZE(szBuffer), "Value = %8X, pAddr = %8X\n", dwValue, (DWORD_PTR)pAddr );
  348. Print( szBuffer );
  349. Print( pszOut );
  350. Print( "\n" );
  351. }
  352. return TRUE;
  353. }
  354. /************************************************************************\
  355. * Procedure: Itest
  356. *
  357. * Description: Tests the basic stdexts macros and functions - a good check
  358. * on the debugger extensions in general before you waste time debuging
  359. * entensions.
  360. *
  361. * Returns: fSuccess
  362. *
  363. * 11/4/1997 Created cdturner
  364. *
  365. \************************************************************************/
  366. BOOL Itest()
  367. {
  368. Print("Print test!\n");
  369. SAFEWHILE(TRUE)
  370. {
  371. Print("SAFEWHILE test... Hit Ctrl-C NOW!\n");
  372. }
  373. return TRUE;
  374. }
  375. /************************************************************************\
  376. * Procedure: Iver
  377. *
  378. * Description: Dumps versions of extensions and winsrv/win32k
  379. *
  380. * Returns: fSuccess
  381. *
  382. * 11/4/1997 Created cdturner
  383. *
  384. \************************************************************************/
  385. BOOL Iver()
  386. {
  387. #if DEBUG
  388. Print("SHLEXTS version: Debug.\n");
  389. #else
  390. Print("SHLEXTS version: Retail.\n");
  391. #endif
  392. return TRUE;
  393. }
  394. /************************************************************************\
  395. *
  396. * DumpVerboseFileInfo
  397. *
  398. * Stolen from MSDN.
  399. *
  400. \************************************************************************/
  401. typedef struct LANGANDCODEPAGE {
  402. WORD wLang;
  403. WORD wCP;
  404. } LANGANDCODEPAGE;
  405. void DumpVersionString(LPVOID pBlock, LANGANDCODEPAGE *lpTranslate, LPCSTR pszKey)
  406. {
  407. char szBuf[128];
  408. LPSTR pszValue;
  409. DWORD cb;
  410. StringCchPrintfA(szBuf, ARRAYSIZE(szBuf), "\\StringFileInfo\\%04x%04x\\%s",
  411. lpTranslate->wLang, lpTranslate->wCP, pszKey);
  412. if (VerQueryValueA(pBlock, szBuf, (LPVOID*)&pszValue, &cb) &&
  413. lstrlenA(pszValue)) // lstrlen traps exceptions
  414. {
  415. Print(szBuf+16); // skip over "\\StringFileInfo\\"
  416. Print(" = ");
  417. Print(pszValue);
  418. Print("\n");
  419. }
  420. }
  421. LPCSTR c_rgszVersionKeys[] =
  422. {
  423. "CompanyName",
  424. "FileDescription",
  425. "InternalName",
  426. "OriginalFilename",
  427. "ProductName",
  428. "ProductVersion",
  429. "FileVersion",
  430. "LegalCopyright",
  431. "LegalTrademarks",
  432. "PrivateBuild",
  433. "SpecialBuild",
  434. "Comments",
  435. NULL,
  436. };
  437. void DumpVerboseFileInfo(LPVOID pBlock)
  438. {
  439. LANGANDCODEPAGE *lpTranslate;
  440. DWORD cbTranslate;
  441. // Read the list of languages and code pages
  442. if (VerQueryValueA(pBlock, "\\VarFileInfo\\Translation",
  443. (LPVOID*)&lpTranslate, &cbTranslate))
  444. {
  445. UINT i;
  446. for (i = 0; i < cbTranslate/sizeof(*lpTranslate) && !IsCtrlCHit(); i++)
  447. {
  448. LPCSTR *ppszVK;
  449. for (ppszVK = c_rgszVersionKeys; *ppszVK && !IsCtrlCHit(); ppszVK++)
  450. {
  451. DumpVersionString(pBlock, &lpTranslate[i], *ppszVK);
  452. }
  453. }
  454. }
  455. }
  456. /************************************************************************\
  457. * Procedure: Ifilever
  458. *
  459. * Description: Dumps versions of extensions and winsrv/win32k
  460. *
  461. * Returns: fSuccess
  462. *
  463. * 11/4/1997 Created cdturner
  464. *
  465. \************************************************************************/
  466. BOOL Ifilever( DWORD dwOpts,
  467. LPSTR pszArgs )
  468. {
  469. HINSTANCE hDll = NULL;
  470. DLLGETVERSIONPROC pGetVer = NULL;
  471. DWORD dwHandle;
  472. DWORD dwBlockLen;
  473. LPVOID pBlock = NULL;
  474. char szMessage[200];
  475. BOOL fSkipLoad = FALSE;
  476. if ( pszArgs == NULL || lstrlenA( pszArgs ) == 0 )
  477. {
  478. pszArgs = "Shell32.dll"; // default filename
  479. }
  480. if ( !dwOpts )
  481. {
  482. dwOpts = OFLAG(n); // default flags
  483. }
  484. Print("filever ");
  485. Print(pszArgs);
  486. Print("\n");
  487. if ( dwOpts & OFLAG(d) )
  488. {
  489. hDll = LoadLibraryA(pszArgs);
  490. if ( hDll == NULL )
  491. {
  492. Print("LoadLibrary failed\n");
  493. }
  494. else
  495. {
  496. pGetVer = (DLLGETVERSIONPROC) GetProcAddress( hDll, "DllGetVersion");
  497. if ( pGetVer )
  498. {
  499. DLLVERSIONINFO rgVerInfo;
  500. rgVerInfo.cbSize = sizeof( rgVerInfo );
  501. pGetVer( &rgVerInfo );
  502. StringCchPrintfA( szMessage, ARRAYSIZE(szMessage), "DllGetVersion\n Major = %d\n Minor = %d\n Build = %d\n",
  503. rgVerInfo.dwMajorVersion, rgVerInfo.dwMinorVersion, rgVerInfo.dwBuildNumber );
  504. Print(szMessage );
  505. }
  506. FreeLibrary( hDll );
  507. }
  508. }
  509. if ( dwOpts & (OFLAG(n) | OFLAG(v)) )
  510. {
  511. // now test the normal version details...
  512. dwBlockLen = GetFileVersionInfoSizeA( pszArgs, &dwHandle );
  513. if ( dwBlockLen == 0 )
  514. {
  515. Print("GetFileVersionSize failed\n");
  516. }
  517. else
  518. {
  519. pBlock = LocalAlloc( LPTR, dwBlockLen );
  520. if ( pBlock )
  521. {
  522. if (GetFileVersionInfoA( pszArgs, dwHandle, dwBlockLen, pBlock ))
  523. {
  524. VS_FIXEDFILEINFO * pFileInfo;
  525. UINT uLen;
  526. VerQueryValueA( pBlock, "\\", (LPVOID *) &pFileInfo, &uLen );
  527. Print("GetFileVersionInfo\n");
  528. StringCchPrintfA( szMessage, ARRAYSIZE(szMessage), "Version: %d.%d.%d.%d (0x%08x`%08x)\n",
  529. HIWORD(pFileInfo->dwFileVersionMS),
  530. LOWORD(pFileInfo->dwFileVersionMS),
  531. HIWORD(pFileInfo->dwFileVersionLS),
  532. LOWORD(pFileInfo->dwFileVersionLS),
  533. pFileInfo->dwFileVersionMS,
  534. pFileInfo->dwFileVersionLS);
  535. Print( szMessage );
  536. }
  537. if (dwOpts & OFLAG(v))
  538. {
  539. DumpVerboseFileInfo(pBlock);
  540. }
  541. LocalFree( pBlock );
  542. }
  543. }
  544. }
  545. return TRUE;
  546. }