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.

161 lines
4.1 KiB

  1. /*++
  2. Copyright (c) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. main.cxx
  5. Abstract:
  6. Misc utilities
  7. Author:
  8. Murali R. Krishnan ( MuraliK ) 24-Aug-1997
  9. Revision History:
  10. --*/
  11. #include "precomp.hxx"
  12. NTSD_EXTENSION_APIS ExtensionApis;
  13. HANDLE ExtensionCurrentProcess;
  14. # define minSize(a, b) (((a) < (b)) ? (a) : (b))
  15. /************************************************************
  16. * Utility Functions
  17. ************************************************************/
  18. VOID
  19. dstring( CHAR * pszName, PVOID pvString, DWORD cbLen)
  20. /*++
  21. Description:
  22. This function reads the data from the debuggee process at
  23. address [pvString] for specified length [cbLen] and echoes
  24. the string back on the debugger window.
  25. Arguments:
  26. pszName - pointer to string containing the name of the string read
  27. pvString - pointer to VOID specifying the location of the string
  28. in the debugee process
  29. cbLen - count of bytes to be read at [pvString]
  30. Returns:
  31. None
  32. --*/
  33. {
  34. CHAR rgchString[10240];
  35. DWORD cLength = minSize( cbLen, sizeof(rgchString) -1);
  36. //
  37. // Read the data block from the debuggee process into local buffer
  38. //
  39. moveBlock( rgchString, pvString, cLength);
  40. rgchString[cLength] = '\0'; // terminate the string buffer
  41. dprintf( "%s = %s\n", pszName, rgchString);
  42. return;
  43. } // dstring()
  44. VOID
  45. Print2Dwords( CHAR * pszN1, DWORD d1,
  46. CHAR * pszN2, DWORD d2
  47. )
  48. {
  49. dprintf(" %25s =%8d %25s =%8d\n",
  50. pszN1, d1,
  51. pszN2, d2
  52. );
  53. return;
  54. } // Print2Dwords()
  55. BOOL
  56. EnumLinkedList(
  57. IN LIST_ENTRY * pListHead,
  58. IN PFN_LIST_ENUMERATOR pfnListEnumerator,
  59. IN CHAR chVerbosity,
  60. IN DWORD cbSizeOfStructure,
  61. IN DWORD cbListEntryOffset
  62. )
  63. /*++
  64. Description:
  65. This function iterates over the NT's standard LIST_ENTRY structure
  66. (doubly linked circular list with header) and makes callbacks for
  67. objects found on the list.
  68. Arguments:
  69. pListHead - pointer to List head in the debugee process
  70. pfnListEnumerator - pointer to callback function for the object on the list
  71. chVerbosity - character indicating the verbosity level desired
  72. cbSizeOfStructure - count of bytes of object's size
  73. cbListEntryOffset - count of bytes of offset of the List entry structure
  74. inside the containing object
  75. Returns:
  76. TRUE on successful enumeration
  77. FALSE on failure
  78. --*/
  79. {
  80. # define MAX_STRUCTURE_SIZE (10240)
  81. CHAR rgch[MAX_STRUCTURE_SIZE];
  82. PVOID pvDebuggee = NULL;
  83. PVOID pvDebugger = (PVOID ) rgch;
  84. LIST_ENTRY leListHead;
  85. LIST_ENTRY * pListEntry;
  86. DWORD cItems = 0;
  87. if ( NULL == pListHead) {
  88. dprintf( "Invalid List given \n");
  89. return (FALSE);
  90. }
  91. if ( MAX_STRUCTURE_SIZE < cbSizeOfStructure) {
  92. dprintf( "Given size for structure %d exceeds default max %d bytes\n",
  93. cbSizeOfStructure, MAX_STRUCTURE_SIZE);
  94. return (FALSE);
  95. }
  96. // make a local copy of the list head for navigation purposes
  97. MoveWithRet( leListHead, pListHead, FALSE);
  98. for ( pListEntry = leListHead.Flink;
  99. pListEntry != pListHead;
  100. )
  101. {
  102. if ( CheckControlC() )
  103. {
  104. return (FALSE);
  105. }
  106. pvDebuggee = (PVOID ) ((PCHAR ) pListEntry - cbListEntryOffset);
  107. // make a local copy of the debuggee structure
  108. MoveBlockWithRet( rgch, pvDebuggee, cbSizeOfStructure, FALSE);
  109. cItems++;
  110. if( pfnListEnumerator ) {
  111. (*pfnListEnumerator)( pvDebuggee, pvDebugger, chVerbosity, cItems);
  112. dprintf( "\n");
  113. }
  114. MoveWithRet( pListEntry, &pListEntry->Flink, FALSE );
  115. } // for all linked list entries
  116. dprintf( "%d entries traversed\n", cItems );
  117. return (TRUE);
  118. } // EnumLinkedList()