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.

167 lines
4.2 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. hivehdr.c
  5. Abstract:
  6. Dump the header of a hive primary, alternate, or log file.
  7. hivehdr filename filename filename ...
  8. Author:
  9. Bryan Willman (bryanwi) 6-april-92
  10. Revision History:
  11. --*/
  12. #define _ARCCODES_
  13. #include "regutil.h"
  14. #include "edithive.h"
  15. void
  16. DoDump(
  17. PUCHAR Filename
  18. );
  19. void
  20. __cdecl main(
  21. int argc,
  22. char *argv[]
  23. )
  24. {
  25. int i;
  26. if (argc == 1) {
  27. fprintf(stderr, "Usage: hivehdr filename filename...\n", argv[0]);
  28. exit(1);
  29. }
  30. for (i = 1; i < argc; i++) {
  31. DoDump(argv[i]);
  32. }
  33. exit(0);
  34. }
  35. void
  36. DoDump(
  37. PUCHAR Filename
  38. )
  39. {
  40. HANDLE infile;
  41. static char buffer[HSECTOR_SIZE];
  42. PHBASE_BLOCK bbp;
  43. char *validstring[] = { "BAD", "OK" };
  44. int valid;
  45. char *typename[] = { "primary", "alternate", "log", "external", "unknown" };
  46. int typeselect;
  47. int readcount;
  48. unsigned long checksum;
  49. unsigned long i;
  50. infile = (HANDLE)CreateFile(
  51. Filename, // file name
  52. GENERIC_READ, // desired access
  53. FILE_SHARE_READ | FILE_SHARE_WRITE, // share mode
  54. NULL, // security attributes
  55. OPEN_EXISTING, // creation disposition
  56. FILE_FLAG_SEQUENTIAL_SCAN, // flags and attributes
  57. NULL // template file
  58. );
  59. if (infile == INVALID_HANDLE_VALUE) {
  60. fprintf(stderr, "hivehdr: Could not open '%s'\n", Filename);
  61. return;
  62. }
  63. if (!ReadFile(infile, buffer, HSECTOR_SIZE, &readcount, NULL)) {
  64. fprintf(
  65. stderr, "hivehdr: '%s' - cannot read full base block\n", Filename);
  66. return;
  67. }
  68. if (readcount != HSECTOR_SIZE) {
  69. fprintf(
  70. stderr, "hivehdr: '%s' - cannot read full base block\n", Filename);
  71. return;
  72. }
  73. bbp = (PHBASE_BLOCK)&(buffer[0]);
  74. if ((bbp->Major != 1) || (bbp->Minor != 1)) {
  75. printf("WARNING: Hive file is newer than hivehdr, or is invalid\n");
  76. }
  77. printf(" File: '%s'\n", Filename);
  78. printf(" BaseBlock:\n");
  79. valid = (bbp->Signature == HBASE_BLOCK_SIGNATURE);
  80. printf(" Signature: %08lx '%4.4s'\t\t%s\n",
  81. bbp->Signature, (PUCHAR)&(bbp->Signature), validstring[valid]);
  82. valid = (bbp->Sequence1 == bbp->Sequence2);
  83. printf(" Sequence1//2: %08lx//%08lx\t%s\n",
  84. bbp->Sequence1, bbp->Sequence2, validstring[valid]);
  85. printf(" TimeStamp: %08lx:%08lx\n",
  86. bbp->TimeStamp.HighPart, bbp->TimeStamp.LowPart,
  87. (PUCHAR)&(bbp->Signature), validstring[valid]);
  88. valid = (bbp->Major == HSYS_MAJOR);
  89. printf("Major Version: %08lx\t\t\t%s\n",
  90. bbp->Major, validstring[valid]);
  91. valid = (bbp->Minor == HSYS_MINOR);
  92. printf("Minor Version: %08lx\t\t\t%s\n",
  93. bbp->Minor, validstring[valid]);
  94. valid = ( (bbp->Type == HFILE_TYPE_PRIMARY) ||
  95. (bbp->Type == HFILE_TYPE_ALTERNATE) ||
  96. (bbp->Type == HFILE_TYPE_LOG) );
  97. if (valid) {
  98. typeselect = bbp->Type;
  99. } else {
  100. typeselect = HFILE_TYPE_MAX;
  101. }
  102. printf(" Type: %08lx %s\t\t%s\n",
  103. bbp->Type, typename[typeselect], validstring[valid]);
  104. valid = (bbp->Format == HBASE_FORMAT_MEMORY);
  105. printf(" Format: %08lx\t\t\t%s\n",
  106. bbp->Format, validstring[valid]);
  107. printf(" RootCell: %08lx\n", bbp->RootCell);
  108. printf(" Length: %08lx\n", bbp->Length);
  109. printf(" Cluster: %08lx\n", bbp->Cluster);
  110. checksum = HvpHeaderCheckSum(bbp);
  111. valid = (checksum == bbp->CheckSum);
  112. if (checksum == bbp->CheckSum) {
  113. printf(" CheckSum: %08lx\t\t\t%s\n",
  114. bbp->CheckSum, validstring[TRUE]);
  115. } else {
  116. printf(" CheckSum: %08lx\t\t\t%s\tCorrect: %08lx\n",
  117. bbp->CheckSum, validstring[FALSE], checksum);
  118. }
  119. //
  120. // print last part of file name, aid to identification
  121. //
  122. printf("Hive/FileName: ");
  123. for (i = 0; i < HBASE_NAME_ALLOC;i+=sizeof(WCHAR)) {
  124. printf("%wc", bbp->FileName[i]);
  125. }
  126. return;
  127. }