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.

162 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: dfilepat.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to dump the file type (bit
  9. // patterns) cache
  10. //
  11. // Functions: filePatHelp
  12. // displayFilePatTbl
  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: filePatHelp
  28. //
  29. // Synopsis: Display a menu for the command 'ft'
  30. //
  31. // Arguments: -
  32. //
  33. // Returns: -
  34. //
  35. // History: 07-Mar-95 BruceMa Created
  36. //
  37. //--------------------------------------------------------------------------
  38. void filePatHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  39. {
  40. Printf("ft - Display entire file type patterns table\n");
  41. Printf("ft clsid - Display file type patterns for clsid\n");
  42. }
  43. //+-------------------------------------------------------------------------
  44. //
  45. // Function: displayFilePatTbl
  46. //
  47. // Synopsis: Display some or all of the file type patterns table
  48. //
  49. // Arguments: [hProcess] - Handle of this process
  50. // [lpExtensionApis] - Table of extension functions
  51. // [lpFileExtTbl] - Address of file extensions table
  52. // [pClsid] - Only for this clsid
  53. //
  54. // Returns: -
  55. //
  56. // History: 01-Jun-95 BruceMa Created
  57. //
  58. //--------------------------------------------------------------------------
  59. void displayFilePatTbl(HANDLE hProcess,
  60. PNTSD_EXTENSION_APIS lpExtensionApis,
  61. SDllShrdTbl *pShrdTbl,
  62. CLSID *pClsid)
  63. {
  64. SDllShrdTbl sDllTbl;
  65. STblHdr *pTblHdr;
  66. STblHdr sTblHdr;
  67. BYTE *pStart;
  68. LPVOID pEnd;
  69. CLSID oldClsid = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
  70. UINT ulCnt = 0;
  71. // Read the shared table locally
  72. ReadMem(&sDllTbl, pShrdTbl, sizeof(SDllShrdTbl));
  73. // Read the table header locally
  74. pTblHdr = sDllTbl._PatternTbl._pTblHdr;
  75. ReadMem(&sTblHdr, pTblHdr, sizeof(STblHdr));
  76. // Set up to read the entries
  77. pStart = sDllTbl._PatternTbl._pStart;
  78. pEnd = pStart + sTblHdr.OffsEnd - sizeof(STblHdr);
  79. // Do over the file extension entries
  80. while (pStart < pEnd)
  81. {
  82. ULONG ulLen;
  83. SPatternEntry sPatEnt;
  84. char szClsid[CLSIDSTR_MAX];
  85. // Just in case the loop gets away from us
  86. if (CheckControlC())
  87. {
  88. return;
  89. }
  90. // Read the length of this entry
  91. ReadMem(&ulLen, pStart + sizeof(CLSID), sizeof(ULONG));
  92. // Read the next entry locally
  93. ReadMem(&sPatEnt, pStart, ulLen);
  94. // Print the clsid if we haven't yet
  95. if (pClsid == NULL && !IsEqualCLSID(&sPatEnt.clsid, &oldClsid))
  96. {
  97. FormatCLSID(sPatEnt.clsid, szClsid);
  98. Printf("\n%s\n", szClsid);
  99. // Save the clisd
  100. oldClsid = sPatEnt.clsid;
  101. // Initialize a count per clsid
  102. ulCnt = 0;
  103. }
  104. // Print only if printing the whole table or at our sought clsid
  105. if (pClsid == NULL || IsEqualCLSID(pClsid, &sPatEnt.clsid))
  106. {
  107. // Print the index of this pattern
  108. Printf("%2d ", ulCnt++);
  109. // Print the file offset
  110. Printf("%d\t", sPatEnt.lFileOffset);
  111. // Print the length of the pattern in bytes
  112. Printf("%3d ", sPatEnt.ulCb);
  113. // Print the mask
  114. for (UINT k = 0; k < sPatEnt.ulCb; k++)
  115. {
  116. Printf("%02x", sPatEnt.abData[k]);
  117. }
  118. Printf(" ");
  119. // Print the pattern
  120. for (k = 0; k < sPatEnt.ulCb; k++)
  121. {
  122. Printf("%02x", sPatEnt.abData[sPatEnt.ulCb + k]);
  123. }
  124. Printf("\n");
  125. }
  126. // Go to the next entry
  127. pStart += ulLen;
  128. }
  129. }