Source code of Windows XP (NT5)
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.

158 lines
4.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: dfileext.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to dump the clsid/file extensions
  9. // cache
  10. //
  11. // Functions: fileExtHelp
  12. // displayFileExtTbl
  13. //
  14. //
  15. // History: 06-01-95 BruceMa Created
  16. //
  17. //
  18. //--------------------------------------------------------------------------
  19. #include <ole2int.h>
  20. #include <windows.h>
  21. #include "ole.h"
  22. #include "dshrdmem.h"
  23. BOOL IsEqualCLSID(CLSID *pClsid1, CLSID *pClsid2);
  24. void FormatCLSID(REFGUID rguid, LPSTR lpsz);
  25. //+-------------------------------------------------------------------------
  26. //
  27. // Function: fileExtHelp
  28. //
  29. // Synopsis: Display a menu for the command 'fe'
  30. //
  31. // Arguments: -
  32. //
  33. // Returns: -
  34. //
  35. // History: 07-Mar-95 BruceMa Created
  36. //
  37. //--------------------------------------------------------------------------
  38. void fileExtHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  39. {
  40. Printf("fe - Display entire file extensions table\n");
  41. Printf("fe clsid - Display file extensions for clsid\n");
  42. Printf("fe .ext - Display clsid for file extension ext\n");
  43. }
  44. //+-------------------------------------------------------------------------
  45. //
  46. // Function: displayFileExtTbl
  47. //
  48. // Synopsis: Display some or all of the file extensions table
  49. //
  50. // Arguments: [hProcess] - Handle of this process
  51. // [lpExtensionApis] - Table of extension functions
  52. // [lpFileExtTbl] - Address of file extensions table
  53. //
  54. // Returns: -
  55. //
  56. // History: 01-Jun-95 BruceMa Created
  57. //
  58. //--------------------------------------------------------------------------
  59. void displayFileExtTbl(HANDLE hProcess,
  60. PNTSD_EXTENSION_APIS lpExtensionApis,
  61. SDllShrdTbl *pShrdTbl,
  62. CLSID *pClsid,
  63. WCHAR *wszExt)
  64. {
  65. SDllShrdTbl sDllTbl;
  66. SExtTblHdr *pExtTblHdr;
  67. SExtTblHdr sExtTblHdr;
  68. BYTE *pExtEntry;
  69. LPVOID pEnd;
  70. CLSID oldClsid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  71. // Read the shared table locally
  72. ReadMem(&sDllTbl, pShrdTbl, sizeof(SDllShrdTbl));
  73. // Read the table header locally
  74. pExtTblHdr = sDllTbl._FileExtTbl._pTblHdr;
  75. ReadMem(&sExtTblHdr, pExtTblHdr, sizeof(SExtTblHdr));
  76. // Set up to read the entries
  77. pExtEntry = sDllTbl._FileExtTbl._pStart;
  78. pEnd = pExtEntry + sExtTblHdr.OffsEnd - sizeof(SExtTblHdr);
  79. // Do over the file extension entries
  80. while (pExtEntry < pEnd)
  81. {
  82. ULONG ulLen;
  83. SExtEntry sExtEnt;
  84. WCHAR slop[16];
  85. char szClsid[CLSIDSTR_MAX];
  86. BOOL fNL = FALSE;
  87. // Just in case the loop gets away from us
  88. if (CheckControlC())
  89. {
  90. return;
  91. }
  92. // Read the length of this entry
  93. ReadMem(&ulLen, pExtEntry + sizeof(CLSID), sizeof(ULONG));
  94. // Read the next entry locally
  95. ReadMem(&sExtEnt, pExtEntry, ulLen);
  96. // Print the clsid if dumping the whole table or searching by
  97. // extension
  98. if ((pClsid == NULL && wszExt == NULL) ||
  99. (wszExt && !lstrcmpW(wszExt, sExtEnt.wszExt)))
  100. {
  101. FormatCLSID(sExtEnt.Clsid, szClsid);
  102. Printf("%s ", szClsid);
  103. // Save the clisd
  104. oldClsid = sExtEnt.Clsid;
  105. // Remember to printf a newline
  106. fNL = TRUE;
  107. }
  108. // Print the extension if dumping the whole table or seraching
  109. // by clsid
  110. if ((pClsid == NULL && wszExt == NULL) ||
  111. (pClsid && IsEqualCLSID(&sExtEnt.Clsid, pClsid)))
  112. {
  113. // Print the associated file extension
  114. Printf("%ws ", sExtEnt.wszExt);
  115. // Remember to printf a newline
  116. fNL = TRUE;
  117. }
  118. // Check if we need to print a newline
  119. if (fNL)
  120. {
  121. Printf("\n");
  122. fNL = FALSE;
  123. }
  124. // Go to the next entry
  125. pExtEntry += ulLen;
  126. }
  127. }