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.

214 lines
5.8 KiB

  1. //-----------------------------------------------------------------------
  2. // @doc
  3. //
  4. // @module convert crash dump to triage dump for crash dump utilities
  5. //
  6. // Copyright 1999 Microsoft Corporation. All Rights Reserved
  7. //
  8. #include <stdlib.h>
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <time.h>
  12. #include <tchar.h>
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. BOOL
  18. DoConversion(
  19. LPSTR szInputDumpFile, // full or kernel dump
  20. HANDLE OutputDumpFile // triage dump file
  21. );
  22. void Usage()
  23. {
  24. fprintf(stderr, "dmpmgr -s symbol_path -i input_dump_file -o output_dump_file\n");
  25. fprintf(stderr, "\tinput dump file is full or kernel crash dump.\n");
  26. fprintf(stderr, "\toutput is triage crash dump.\n");
  27. fprintf(stderr, "\tsymbol path -- must have symbols for ntoskrnl.exe.\n\n");
  28. }
  29. ULONG Extra[11];
  30. ULONG Base[500];
  31. UCHAR Output[4000];
  32. int
  33. WINAPIV
  34. main(
  35. int argc,
  36. PTSTR argv[ ],
  37. PTSTR envp[]
  38. )
  39. {
  40. char *szInputDumpFile = NULL;
  41. char *szOutputTriageDumpFile = NULL;
  42. char *szIniFile = NULL;
  43. BOOL fVerbose = 0;
  44. BOOL fExamine = 0;
  45. BOOL fBuildIniFile = 0;
  46. int iarg;
  47. HANDLE fileHandle;
  48. HANDLE fileHandleIn;
  49. UCHAR Buffer[8192];
  50. PUCHAR ptmp;
  51. ULONG cbRead;
  52. ULONG i;
  53. for(iarg = 1; iarg < argc; iarg++)
  54. {
  55. if (argv[iarg][0] == '/' ||
  56. argv[iarg][0] == '-')
  57. {
  58. if (_tcslen(argv[iarg]) < 2)
  59. {
  60. Usage();
  61. exit(-1);
  62. }
  63. switch(argv[iarg][1])
  64. {
  65. default:
  66. Usage();
  67. exit(-1);
  68. case 'i':
  69. case 'I':
  70. szInputDumpFile = argv[++iarg];
  71. break;
  72. case 'o':
  73. case 'O':
  74. szOutputTriageDumpFile = argv[++iarg];
  75. break;
  76. }
  77. }
  78. else
  79. {
  80. Usage();
  81. exit(-1);
  82. }
  83. }
  84. if (szInputDumpFile == NULL ||
  85. szOutputTriageDumpFile == NULL)
  86. {
  87. Usage();
  88. exit(-1);
  89. }
  90. fileHandleIn = CreateFileA(szInputDumpFile,
  91. GENERIC_READ,
  92. 0,
  93. NULL,
  94. FILE_OPEN_IF,
  95. FILE_ATTRIBUTE_NORMAL,
  96. NULL);
  97. if (fileHandleIn == INVALID_HANDLE_VALUE) {
  98. fprintf(stderr, "can not open input file\n");
  99. exit(-1);
  100. }
  101. if (!ReadFile(fileHandleIn,
  102. Buffer,
  103. sizeof(Buffer),
  104. &cbRead,
  105. NULL))
  106. {
  107. fprintf(stderr, "can not read input file\n");
  108. exit(-1);
  109. }
  110. ptmp = Buffer;
  111. for (i=0; i<11; i++) {
  112. ptmp = strstr(ptmp, "kd> x");
  113. ptmp = strstr(ptmp, "\n");
  114. ptmp++;
  115. sscanf(ptmp, "%08lx", &Extra[i]);
  116. }
  117. ptmp = strstr(ptmp, "kd> dd");
  118. for (i=0; i<40; i++) {
  119. ptmp = strstr(ptmp, "\n");
  120. ptmp++;
  121. sscanf(ptmp, "%08lx %08lx %08lx %08lx %08lx",
  122. &Base[i*10], &Base[i*10 + 1], &Base[i*10 + 2], &Base[i*10 + 3], &Base[i*10 + 4]);
  123. }
  124. sprintf(Output,
  125. "KDDEBUGGER_DATA64 %s = {"
  126. "{0}, 0x%08lx, 0x%08lx, 0, 0, 0, 0, 0, 0x%08lx,\n"
  127. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  128. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  129. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  130. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  131. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  132. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  133. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  134. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  135. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  136. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  137. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  138. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  139. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  140. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  141. "0x%08lx, 0x00000000, 0x00000000,\n"
  142. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  143. "0x%08lx, 0x%08lx, 0x%08lx, 0x%08lx,\n"
  144. "0x%08lx, 0x%08lx, 0x%08lx};\n\n\n",
  145. szInputDumpFile,
  146. Base[13], Base[21], Base[33],
  147. Base[41], Base[43], Base[51], Base[53],
  148. Base[61], Base[63], Base[71], Base[73],
  149. Base[81], Base[83], Base[91], Base[93],
  150. Base[101], Base[103], Base[111], Base[113],
  151. Base[121], Base[123], Base[131], Base[133],
  152. Base[141], Base[143], Base[151], Base[153],
  153. Base[161], Base[163], Base[171], Base[173],
  154. Base[181], Base[183], Base[191], Base[193],
  155. Base[201], Base[203], Base[211], Base[213],
  156. Base[221], Base[223], Base[231], Base[233],
  157. Base[241], Base[243], Base[251], Base[253],
  158. Base[261], Base[263], Base[271], Base[273],
  159. Base[281], Base[283], Base[291], Base[293],
  160. Base[301], Base[303], Base[311], Base[313],
  161. Base[321],
  162. Extra[0], Extra[1], Extra[2], Extra[3], Extra[4], Extra[5], Extra[6], Extra[7],
  163. Extra[8], Extra[9], Extra[10]);
  164. //
  165. // Create the minidump file
  166. //
  167. fileHandle = CreateFileA(szOutputTriageDumpFile,
  168. GENERIC_WRITE,
  169. 0,
  170. NULL,
  171. CREATE_ALWAYS,
  172. FILE_ATTRIBUTE_NORMAL,
  173. NULL);
  174. if (fileHandle == INVALID_HANDLE_VALUE) {
  175. exit(-1);
  176. }
  177. WriteFile(fileHandle,
  178. Output,
  179. strlen(Output),
  180. &cbRead,
  181. NULL);
  182. CloseHandle(fileHandle);
  183. exit(-1);
  184. }