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.

231 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. DskDump.c
  5. Abstract:
  6. This is the main module for the Win32 DskDump command.
  7. Author:
  8. Gary Kimura [GaryKi] 26-Aug-91
  9. Revision History:
  10. --*/
  11. #include "DskDump.h"
  12. #include "cvtoem.h"
  13. int
  14. __cdecl main( argc, argv )
  15. int argc;
  16. char *argv[];
  17. {
  18. HANDLE Handle;
  19. NTSTATUS Status;
  20. IO_STATUS_BLOCK Iosb;
  21. LARGE_INTEGER Offset;
  22. LONG FirstSector;
  23. LONG Count;
  24. LONG i;
  25. LONG j;
  26. LONG k;
  27. UCHAR Buffer[512];
  28. UCHAR NewOutput[80];
  29. UCHAR PreviousOutput[80];
  30. LONG LastOut;
  31. //
  32. // Check in the input arguments
  33. //
  34. ConvertAppToOem( argc, argv );
  35. if (argc < 3) {
  36. printf("Syntax - Drive: [0x]Count [[0x]StartSector]\n");
  37. return 0;
  38. }
  39. if (argc == 4) {
  40. if (sscanf( argv[3],
  41. strncmp( argv[3], "0x", 2 ) ? "%ld" : "%lx",
  42. &FirstSector ) != 1)
  43. {
  44. printf("Syntax - Drive: [0x]Count [[0x]StartSector]\n");
  45. return 0;
  46. }
  47. } else {
  48. FirstSector = 0;
  49. }
  50. //
  51. // Convert the input arguments and tell the user what we're going to do
  52. //
  53. if (sscanf( argv[2], strncmp( argv[2], "0x", 2 ) ? "%ld" : "%lx", &Count ) != 1) {
  54. printf("Syntax - Drive: [0x]Count [[0x]StartSector]\n");
  55. return 0;
  56. }
  57. fprintf(stdout, " Dump of \"%s\" for %ld sectors starting at %ld\n", argv[1], Count, FirstSector);
  58. if ((Handle = OpenVolume( argv[1][0] )) == NULL) {
  59. return 0;
  60. }
  61. //
  62. // for each sector we go through our main loop
  63. //
  64. LastOut = -16;
  65. for (i = FirstSector; i < FirstSector + Count; i += 1) {
  66. Offset.HighPart = 0;
  67. Offset.LowPart = i * 512;
  68. //
  69. // Read the file at the indicated Offset
  70. //
  71. if (!NT_SUCCESS(Status = NtReadFile( Handle,
  72. NULL,
  73. NULL,
  74. NULL,
  75. &Iosb,
  76. Buffer,
  77. 512,
  78. &Offset,
  79. NULL ))) {
  80. fprintf(stderr, "Read Error - %08lx\n", Status );
  81. return 0;
  82. }
  83. //
  84. // And write the buffer to standard out
  85. //
  86. for (j = 0; j < 512; j += 16) {
  87. sprintf( NewOutput, " %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x ",
  88. Buffer[j],
  89. Buffer[j+1],
  90. Buffer[j+2],
  91. Buffer[j+3],
  92. Buffer[j+4],
  93. Buffer[j+5],
  94. Buffer[j+6],
  95. Buffer[j+7],
  96. Buffer[j+8],
  97. Buffer[j+9],
  98. Buffer[j+10],
  99. Buffer[j+11],
  100. Buffer[j+12],
  101. Buffer[j+13],
  102. Buffer[j+14],
  103. Buffer[j+15]);
  104. if (strcmp( NewOutput, PreviousOutput ) != 0 ) {
  105. if (LastOut + 16 != (i*512L) + j) {
  106. fprintf(stdout, "*\n");
  107. }
  108. strcpy( PreviousOutput, NewOutput );
  109. LastOut = (i * 512L) + j;
  110. fprintf(stdout, "%06lx ", LastOut);
  111. fprintf(stdout, NewOutput );
  112. for (k = j; k < j + 16; k += 1) {
  113. if (isprint(Buffer[k])) {
  114. fprintf(stdout, "%c", Buffer[k]);
  115. } else {
  116. fprintf(stdout, ".");
  117. }
  118. }
  119. fprintf(stdout, "\n");
  120. }
  121. }
  122. }
  123. CloseHandle(Handle);
  124. return 0;
  125. }
  126. HANDLE
  127. OpenVolume(
  128. CHAR c
  129. )
  130. {
  131. WCHAR VolumeNameW[4];
  132. NTSTATUS Status;
  133. OBJECT_ATTRIBUTES Obja;
  134. HANDLE Handle;
  135. UNICODE_STRING FileName;
  136. IO_STATUS_BLOCK IoStatusBlock;
  137. PVOID FreeBuffer;
  138. LPWSTR FilePart;
  139. VolumeNameW[0] = (WCHAR)c;
  140. VolumeNameW[1] = (WCHAR)':';
  141. VolumeNameW[2] = UNICODE_NULL;
  142. if (!RtlDosPathNameToNtPathName_U( VolumeNameW, &FileName, &FilePart, NULL )) {
  143. fprintf(stderr,"Cannot translate drive letter %c\n", c);
  144. return NULL;
  145. }
  146. FreeBuffer = FileName.Buffer;
  147. InitializeObjectAttributes( &Obja, &FileName, OBJ_CASE_INSENSITIVE, NULL, NULL );
  148. {
  149. ULONG i;
  150. for (i = 0; i < (ULONG)FileName.Length/2; i += 1) {
  151. if (FileName.Buffer[i] == ':') {
  152. FileName.Buffer[i+1] = UNICODE_NULL;
  153. FileName.Length = (USHORT)((i+1)*2);
  154. break;
  155. }
  156. }
  157. }
  158. //
  159. // Open the volume
  160. //
  161. Status = NtOpenFile( &Handle,
  162. FILE_READ_DATA | SYNCHRONIZE,
  163. &Obja,
  164. &IoStatusBlock,
  165. FILE_SHARE_READ | FILE_SHARE_WRITE,
  166. FILE_SYNCHRONOUS_IO_NONALERT );
  167. RtlFreeHeap(RtlProcessHeap(),0,FreeBuffer);
  168. if ( !NT_SUCCESS(Status) ) {
  169. fprintf(stderr,"Cannot open drive letter %c\n", c);
  170. return NULL;
  171. }
  172. return Handle;
  173. }
  174.