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.

270 lines
9.6 KiB

  1. #include <nt.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. // ----------------------joejoe-----------found-------------#include "RxProcs.h"
  5. #include "precomp.h"
  6. #pragma hdrstop
  7. UCHAR CompressedBuffer[0x8000];
  8. UCHAR UncompressedBuffer[0x8000];
  9. VOID
  10. DsDumpSyntax (
  11. PCHAR argv0
  12. )
  13. {
  14. printf("Syntax - %s -h <FileName>\n", argv0);
  15. printf(" %s -c <FileName> [0x]<Offset> [0x]<DecompressedLength> [0x]<CompressedLength> [<OutputFile>]\n", argv0);
  16. printf(" %s -d <FileName> [0x]<Offset> [0x]<CompressedLength> [0x]<DecompressedLength> [<OutputFile>]\n", argv0);
  17. return;
  18. }
  19. VOID
  20. DumpHeader (
  21. ULONG argc,
  22. PCHAR argv[],
  23. FILE *pf
  24. )
  25. {
  26. ULONG FileSize;
  27. PACKED_CVF_HEADER PackedCvfHeader;
  28. CVF_HEADER CvfHeader;
  29. CVF_LAYOUT CvfLayout;
  30. //
  31. // Get the file size
  32. //
  33. (VOID)fseek( pf, 0, SEEK_END );
  34. FileSize = ftell( pf );
  35. //
  36. // Read in and decode the cvf header
  37. //
  38. (VOID)fseek( pf, 0, SEEK_SET );
  39. (VOID)fread( &PackedCvfHeader, 1, sizeof(PACKED_CVF_HEADER), pf );
  40. CvfUnpackCvfHeader( &CvfHeader, &PackedCvfHeader );
  41. //
  42. // Now compute the cvf layout
  43. //
  44. CvfLayout( &CvfLayout, &CvfHeader, FileSize );
  45. //
  46. // Print the unpacked CvfHeader and the Layout
  47. //
  48. fprintf(stderr, "\n%s:\n", argv[2]);
  49. printf("\n");
  50. printf("CvfHeader.Bpb.BytesPerSector = %08lx\n", CvfHeader.Bpb.BytesPerSector);
  51. printf("CvfHeader.Bpb.SectorsPerCluster = %08lx\n", CvfHeader.Bpb.SectorsPerCluster);
  52. printf("CvfHeader.Bpb.ReservedSectors = %08lx\n", CvfHeader.Bpb.ReservedSectors);
  53. printf("CvfHeader.Bpb.Rxs = %08lx\n", CvfHeader.Bpb.Rxs);
  54. printf("CvfHeader.Bpb.RootEntries = %08lx\n", CvfHeader.Bpb.RootEntries);
  55. printf("CvfHeader.Bpb.Sectors = %08lx\n", CvfHeader.Bpb.Sectors);
  56. printf("CvfHeader.Bpb.Media = %08lx\n", CvfHeader.Bpb.Media);
  57. printf("CvfHeader.Bpb.SectorsPerRx = %08lx\n", CvfHeader.Bpb.SectorsPerRx);
  58. printf("CvfHeader.Bpb.SectorsPerTrack = %08lx\n", CvfHeader.Bpb.SectorsPerTrack);
  59. printf("CvfHeader.Bpb.Heads = %08lx\n", CvfHeader.Bpb.Heads);
  60. printf("CvfHeader.Bpb.HiddenSectors = %08lx\n", CvfHeader.Bpb.HiddenSectors);
  61. printf("CvfHeader.Bpb.LargeSectors = %08lx\n", CvfHeader.Bpb.LargeSectors);
  62. printf("\n");
  63. printf("CvfHeader.CvfRxExtensionsLbnMinus1 = %08lx\n", CvfHeader.CvfRxExtensionsLbnMinus1);
  64. printf("CvfHeader.LogOfBytesPerSector = %08lx\n", CvfHeader.LogOfBytesPerSector);
  65. printf("CvfHeader.DosBootSectorLbn = %08lx\n", CvfHeader.DosBootSectorLbn);
  66. printf("CvfHeader.DosRootDirectoryOffset = %08lx\n", CvfHeader.DosRootDirectoryOffset);
  67. printf("CvfHeader.CvfHeapOffset = %08lx\n", CvfHeader.CvfHeapOffset);
  68. printf("CvfHeader.CvfRxFirstDataEntry = %08lx\n", CvfHeader.CvfRxFirstDataEntry);
  69. printf("CvfHeader.CvfBitmap2KSize = %08lx\n", CvfHeader.CvfBitmap2KSize);
  70. printf("CvfHeader.LogOfSectorsPerCluster = %08lx\n", CvfHeader.LogOfSectorsPerCluster);
  71. printf("CvfHeader.Is12BitRx = %08lx\n", CvfHeader.Is12BitRx);
  72. printf("CvfHeader.CvfMaximumCapacity = %08lx\n", CvfHeader.CvfMaximumCapacity);
  73. printf("\n");
  74. printf(" Lbo Allocation Size\n");
  75. printf("CvfLayout.CvfHeader = %08lx %08lx %08lx\n",CvfLayout.CvfHeader.Lbo, CvfLayout.CvfHeader.Allocation, CvfLayout.CvfHeader.Size );
  76. printf("CvfLayout.CvfBitmap = %08lx %08lx %08lx\n",CvfLayout.CvfBitmap.Lbo, CvfLayout.CvfBitmap.Allocation, CvfLayout.CvfBitmap.Size );
  77. printf("CvfLayout.CvfReservedArea1 = %08lx %08lx %08lx\n",CvfLayout.CvfReservedArea1.Lbo, CvfLayout.CvfReservedArea1.Allocation, CvfLayout.CvfReservedArea1.Size );
  78. printf("CvfLayout.CvfRxExtensions = %08lx %08lx %08lx\n",CvfLayout.CvfRxExtensions.Lbo, CvfLayout.CvfRxExtensions.Allocation, CvfLayout.CvfRxExtensions.Size );
  79. printf("CvfLayout.CvfReservedArea2 = %08lx %08lx %08lx\n",CvfLayout.CvfReservedArea2.Lbo, CvfLayout.CvfReservedArea2.Allocation, CvfLayout.CvfReservedArea2.Size );
  80. printf("CvfLayout.DosBootSector = %08lx %08lx %08lx\n",CvfLayout.DosBootSector.Lbo, CvfLayout.DosBootSector.Allocation, CvfLayout.DosBootSector.Size );
  81. printf("CvfLayout.CvfReservedArea3 = %08lx %08lx %08lx\n",CvfLayout.CvfReservedArea3.Lbo, CvfLayout.CvfReservedArea3.Allocation, CvfLayout.CvfReservedArea3.Size );
  82. printf("CvfLayout.DosRx = %08lx %08lx %08lx\n",CvfLayout.DosRx.Lbo, CvfLayout.DosRx.Allocation, CvfLayout.DosRx.Size );
  83. printf("CvfLayout.DosRootDirectory = %08lx %08lx %08lx\n",CvfLayout.DosRootDirectory.Lbo, CvfLayout.DosRootDirectory.Allocation, CvfLayout.DosRootDirectory.Size );
  84. printf("CvfLayout.CvfReservedArea4 = %08lx %08lx %08lx\n",CvfLayout.CvfReservedArea4.Lbo, CvfLayout.CvfReservedArea4.Allocation, CvfLayout.CvfReservedArea4.Size );
  85. printf("CvfLayout.CvfHeap = %08lx %08lx %08lx\n",CvfLayout.CvfHeap.Lbo, CvfLayout.CvfHeap.Allocation, CvfLayout.CvfHeap.Size );
  86. printf("CvfLayout.CvfReservedArea5 = %08lx %08lx %08lx\n",CvfLayout.CvfReservedArea5.Lbo, CvfLayout.CvfReservedArea5.Allocation, CvfLayout.CvfReservedArea5.Size );
  87. //
  88. // Read in and print the Cvf Rx Extensions that are in use
  89. //
  90. {
  91. ULONG i;
  92. CVF_RDBSS_EXTENSIONS Entry;
  93. BOOLEAN FirstTime = TRUE;
  94. for (i = 0; i < CvfLayout.CvfRxExtensions.Size; i += sizeof(CVF_RDBSS_EXTENSIONS)) {
  95. (VOID)fseek( pf, CvfLayout.CvfRxExtensions.Lbo + i, SEEK_SET );
  96. (VOID)fread( &Entry, 1, sizeof(CVF_RDBSS_EXTENSIONS), pf );
  97. if (Entry.IsEntryInUse) {
  98. if (FirstTime) {
  99. FirstTime = FALSE;
  100. printf("\n");
  101. printf(" Entry CvfHeap Compressed Uncompressed IsData\n");
  102. printf(" Offset Lbo Length Length Compressed\n");
  103. }
  104. printf("%08lx %08lx %8lx %8lx %8lx\n", i,
  105. (Entry.CvfHeapLbnMinus1+1) * CvfHeader.Bpb.BytesPerSector,
  106. (Entry.CompressedSectorLengthMinus1+1) * CvfHeader.Bpb.BytesPerSector,
  107. (Entry.UncompressedSectorLengthMinus1+1) * CvfHeader.Bpb.BytesPerSector,
  108. Entry.IsDataUncompressed );
  109. }
  110. }
  111. }
  112. }
  113. VOID
  114. Decompress (
  115. ULONG argc,
  116. PCHAR argv[],
  117. FILE *pf
  118. )
  119. {
  120. ULONG Offset;
  121. ULONG CompressedCount;
  122. ULONG UncompressedCount;
  123. if (argc < 6) {
  124. DsDumpSyntax(argv[0]);
  125. return;
  126. }
  127. sscanf( argv[3], strncmp( argv[3], "0x", 2 ) ? "%ld" : "%lx", &Offset );
  128. sscanf( argv[4], strncmp( argv[4], "0x", 2 ) ? "%ld" : "%lx", &CompressedCount );
  129. sscanf( argv[5], strncmp( argv[5], "0x", 2 ) ? "%ld" : "%lx", &UncompressedCount );
  130. if (argc == 7) { freopen( argv[6], "wb", stdout ); }
  131. //
  132. // Print the file name
  133. //
  134. fprintf(stderr, "\n%s:\n", argv[2]);
  135. fseek( pf, Offset, SEEK_SET );
  136. (VOID)fread( CompressedBuffer, 1, CompressedCount, pf );
  137. {
  138. MRCF_DECOMPRESS WorkSpace;
  139. ULONG UncompressedLength;
  140. UncompressedLength = MrcfDecompress( UncompressedBuffer,
  141. UncompressedCount,
  142. CompressedBuffer,
  143. CompressedCount,
  144. &WorkSpace );
  145. fprintf(stderr, "UncompressedLength = %d\n", UncompressedLength);
  146. fwrite( UncompressedBuffer, 1, UncompressedLength, stdout );
  147. }
  148. }
  149. VOID
  150. Compress (
  151. ULONG argc,
  152. PCHAR argv[],
  153. FILE *pf
  154. )
  155. {
  156. ULONG Offset;
  157. ULONG CompressedCount;
  158. ULONG UncompressedCount;
  159. if (argc < 6) {
  160. DsDumpSyntax(argv[0]);
  161. return;
  162. }
  163. sscanf( argv[3], strncmp( argv[3], "0x", 2 ) ? "%ld" : "%lx", &Offset );
  164. sscanf( argv[4], strncmp( argv[4], "0x", 2 ) ? "%ld" : "%lx", &UncompressedCount );
  165. sscanf( argv[4], strncmp( argv[4], "0x", 2 ) ? "%ld" : "%lx", &CompressedCount );
  166. if (argc == 7) { freopen( argv[6], "wb", stdout ); }
  167. //
  168. // Print the file name
  169. //
  170. fprintf(stderr, "\n%s:\n", argv[2]);
  171. fseek( pf, Offset, SEEK_SET );
  172. (VOID)fread( UncompressedBuffer, 1, UncompressedCount, pf );
  173. {
  174. MRCF_STANDARD_COMPRESS WorkSpace;
  175. ULONG CompressedLength;
  176. CompressedLength = MrcfStandardCompress( CompressedBuffer,
  177. CompressedCount,
  178. UncompressedBuffer,
  179. UncompressedCount,
  180. &WorkSpace );
  181. fprintf(stderr, "CompressedLength = %d\n", CompressedLength);
  182. fwrite( CompressedBuffer, 1, CompressedLength, stdout );
  183. }
  184. }
  185. VOID
  186. cdecl
  187. main (argc, argv)
  188. int argc;
  189. char *argv[];
  190. {
  191. FILE *pf;
  192. if (argc < 3) {
  193. DsDumpSyntax(argv[0]);
  194. return;
  195. }
  196. if (!(pf = fopen(argv[2], "rb"))) {
  197. fprintf(stderr, "%s error: invalid file name '%s'\n", argv[0], argv[2]);
  198. return;
  199. }
  200. if (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-H")) {
  201. DumpHeader(argc,argv,pf);
  202. } else if (!strcmp(argv[1],"-c") || !strcmp(argv[1],"-C")) {
  203. Compress(argc,argv,pf);
  204. } else if (!strcmp(argv[1],"-d") || !strcmp(argv[1],"-D")) {
  205. Decompress(argc,argv,pf);
  206. } else {
  207. DsDumpSyntax(argv[0]);
  208. }
  209. }