Windows NT 4.0 source code leak
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.

175 lines
3.3 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. pcr.c
  5. Abstract:
  6. This module provides access to the pcr and a bang command to dump the pcr.
  7. Author:
  8. Wesley Witt (wesw) 26-Aug-1993 (ported to WinDbg)
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. DECLARE_API( pcr )
  14. /*++
  15. Routine Description:
  16. Arguments:
  17. args -
  18. Return Value:
  19. None
  20. --*/
  21. {
  22. ULONG Processor = 0;
  23. KPCR Kpcr;
  24. PKPCR Pkpcr;
  25. //
  26. // Get the address of the PCR
  27. //
  28. if ( !ReadTargetPcr( &Kpcr, &Pkpcr, Processor ) ) {
  29. dprintf("Unable to read the PCR\n");
  30. return;
  31. }
  32. //
  33. // Print out some interesting fields
  34. //
  35. dprintf("KPCR for Processor %d at %08lx:\n", Processor, Pkpcr);
  36. dprintf("Major %d Minor %d\n",
  37. Kpcr.MajorVersion,
  38. Kpcr.MinorVersion);
  39. dprintf("Panic Stack %08lx\n", Kpcr.PanicStack);
  40. dprintf("Dpc Stack %08lx\n", Kpcr.DpcStack);
  41. dprintf("Irql addresses:\n");
  42. dprintf(" Mask %08lx\n",
  43. (ULONG)Pkpcr + FIELD_OFFSET(KPCR, IrqlMask));
  44. dprintf(" Table %08lx\n",
  45. (ULONG)Pkpcr + FIELD_OFFSET(KPCR, IrqlTable));
  46. dprintf(" Routine %08lx\n",
  47. (ULONG)Pkpcr + FIELD_OFFSET(KPCR, InterruptRoutine));
  48. return;
  49. }
  50. BOOL
  51. ReadPcr(
  52. USHORT Processor,
  53. PVOID Pcr,
  54. PULONG AddressOfPcr,
  55. HANDLE hThread
  56. )
  57. {
  58. return FALSE;
  59. }
  60. BOOL
  61. ReadTargetPcr (
  62. OUT PKPCR Pcr,
  63. OUT PKPCR * PPcr,
  64. IN ULONG Processor
  65. )
  66. /*++
  67. Routine Description:
  68. This function reads the PCR address and the PCR from the
  69. specified target processor to the caller's buffers.
  70. Arguments:
  71. Pcr - Receives the Pcr from the target processor.
  72. PPcr - Receives the address of the Pcr from the target processor.
  73. Processor - Supplies the number of the target processor.
  74. Return Value:
  75. STATUS_SUCCESS is returned if the read of the PCR is successful.
  76. STATUS_BUFFER_OVERFLOW is returned if the read data size does not
  77. equal the requested data size.
  78. Otherwise, the status returned when the address of the PCR or the PCR
  79. itself is read is returned to the caller.
  80. --*/
  81. {
  82. ULONG Result;
  83. PKPCR Pkpcr;
  84. ULONG SizeToRead;
  85. ULONG SizeRead;
  86. PUCHAR CurrentLocalPcr, CurrentTargetPcr;
  87. #define MAX_VIRTUAL_READ 0x800
  88. //
  89. // Get the address of the PCR
  90. //
  91. ReadControlSpace(
  92. (USHORT)Processor,
  93. DEBUG_CONTROL_SPACE_PCR,
  94. (PVOID)&Pkpcr,
  95. sizeof(PKPCR) );
  96. *PPcr = Pkpcr;
  97. //
  98. // read the PCR in MAX_VIRTUAL_READ chunks
  99. //
  100. SizeRead = 0;
  101. CurrentLocalPcr = (PUCHAR)Pcr;
  102. CurrentTargetPcr = (PUCHAR)Pkpcr;
  103. while( SizeRead < sizeof(KPCR) ){
  104. SizeToRead = min( MAX_VIRTUAL_READ, sizeof(KPCR) - SizeRead );
  105. if ( !ReadMemory((DWORD)CurrentTargetPcr,
  106. CurrentLocalPcr,
  107. SizeToRead,
  108. &Result) ) {
  109. return FALSE;
  110. }
  111. if (Result != SizeToRead) {
  112. dprintf( "size mismatch, Result = %d sizeof = %d\n",
  113. Result, SizeToRead );
  114. return FALSE;
  115. }
  116. SizeRead += SizeToRead;
  117. CurrentLocalPcr += SizeToRead;
  118. CurrentTargetPcr += SizeToRead;
  119. }
  120. return TRUE;
  121. }