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.

131 lines
3.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // File: dvtbl.cxx
  7. //
  8. // Contents: Ole NTSD extension routines to dump a vtbl
  9. //
  10. // Functions: displayVtbl
  11. //
  12. //
  13. // History: 06-01-95 BruceMa Created
  14. //
  15. //
  16. //--------------------------------------------------------------------------
  17. #include <ole2int.h>
  18. #include <windows.h>
  19. #include "ole.h"
  20. //+-------------------------------------------------------------------------
  21. //
  22. // Function: vtblHelp
  23. //
  24. // Synopsis: Display a menu for the command 'vt'
  25. //
  26. // Arguments: -
  27. //
  28. // Returns: -
  29. //
  30. // History: 07-Mar-95 BruceMa Created
  31. //
  32. //--------------------------------------------------------------------------
  33. void vtblHelp(PNTSD_EXTENSION_APIS lpExtensionApis)
  34. {
  35. Printf("vt obj - Interpret vtbl for object obj:\n");
  36. }
  37. //+-------------------------------------------------------------------------
  38. //
  39. // Function: displayVtbl
  40. //
  41. // Synopsis: Given an object interpret its vtbl
  42. //
  43. // Arguments: [hProcess] - Handle of this process
  44. // [lpExtensionApis] - Table of extension functions
  45. //
  46. // Returns: -
  47. //
  48. // History: 01-Jun-95 BruceMa Created
  49. //
  50. //--------------------------------------------------------------------------
  51. void displayVtbl(HANDLE hProcess,
  52. PNTSD_EXTENSION_APIS lpExtensionApis,
  53. void *lpObj)
  54. {
  55. DWORD lpVtbl = 0xdeaddead;
  56. DWORD dwVtblOffset;
  57. char achSymbol[256];
  58. // Get the address of the vtbl
  59. ReadMem(&lpVtbl, lpObj, sizeof(LPVOID));
  60. // Check for some reasonableness
  61. if (lpVtbl == 0 || lpVtbl == 0xdededede || lpVtbl == 0xedededed ||
  62. lpVtbl == 0xdeaddead)
  63. {
  64. if (lpVtbl == 0xdeaddead)
  65. {
  66. Printf("...vtbl pointer could not be read\n");
  67. }
  68. else
  69. {
  70. Printf("...vtbl pointer == 0x%x is unreasonable\n", lpVtbl);
  71. }
  72. return;
  73. }
  74. // vtbl entries should always point at functions. Therefore, we should
  75. // always have a displacement of zero. To check for the end of the table
  76. // we will reevaluate the vtbl pointer. If the offset isn't what we
  77. // expected, then we are done.
  78. DWORD dwIndex;
  79. for (dwIndex = 0 ; dwIndex < 512 ; dwIndex += 4, lpVtbl += 4)
  80. {
  81. DWORD dwVtblEntry;
  82. // Just in case the loop gets away from us
  83. if (CheckControlC())
  84. {
  85. return;
  86. }
  87. // Read the next vtbl entry
  88. ReadMem(&dwVtblEntry, lpVtbl, sizeof(dwVtblEntry));
  89. // If the function is at zero, then must be at end of table
  90. if (dwVtblEntry == 0)
  91. {
  92. return;
  93. }
  94. // Now, determine the symbol for the entry in the vtbl
  95. GetSymbol((LPVOID) dwVtblEntry, (UCHAR *) achSymbol, &dwVtblOffset);
  96. // If it doesn't point to the start of a routine, then it
  97. // probably isn't part of the vtbl
  98. if (dwVtblOffset != 0)
  99. {
  100. return;
  101. }
  102. // Print the vtbl entry symbolically
  103. Printf(" 0x%08x %s\n", dwVtblEntry, achSymbol);
  104. }
  105. }