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.

219 lines
4.1 KiB

4 years ago
  1. #define _NTAPI_ULIB_
  2. #include "ulib.hxx"
  3. #include "error.hxx"
  4. #include "wstring.hxx"
  5. #include "path.hxx"
  6. #include "smsg.hxx"
  7. #include "system.hxx"
  8. #include "ifssys.hxx"
  9. #include "substrng.hxx"
  10. #include "ulibcl.hxx"
  11. #include "keyboard.hxx"
  12. #include "fatvol.hxx"
  13. #include "fatsa.hxx"
  14. #include "rfatsa.hxx"
  15. #include "fat.hxx"
  16. extern "C" {
  17. #include <stdio.h>
  18. }
  19. ERRSTACK* perrstk;
  20. BOOLEAN HexOutput = FALSE;
  21. BOOLEAN
  22. FatSecList(
  23. PWSTRING NtDriveName,
  24. PPATH TargetPath,
  25. PMESSAGE Message
  26. )
  27. {
  28. LOG_IO_DP_DRIVE Drive;
  29. REAL_FAT_SA FatSa;
  30. PFAT Fat;
  31. ULONG SectorsPerCluster, Sector, i;
  32. USHORT Cluster;
  33. if( !Drive.Initialize( NtDriveName, Message ) ||
  34. !FatSa.Initialize( &Drive, Message ) ||
  35. !FatSa.FAT_SA::Read() ||
  36. !(Fat = FatSa.GetFat()) ) {
  37. return FALSE;
  38. }
  39. SectorsPerCluster = FatSa.QuerySectorsPerCluster();
  40. Cluster = FatSa.QueryFileStartingCluster( TargetPath->GetPathString() );
  41. if( Cluster == 1 || Cluster == 0xFFFF ) {
  42. printf( "File not found.\n" );
  43. return FALSE;
  44. }
  45. if( Cluster == 0 ) {
  46. // Zero-length file.
  47. //
  48. return TRUE;
  49. }
  50. while( TRUE ) {
  51. Sector = (Cluster - FirstDiskCluster) * SectorsPerCluster +
  52. FatSa.QueryStartDataLbn();
  53. for( i = 0; i < SectorsPerCluster; i++ ) {
  54. if( HexOutput ) {
  55. printf( "0x%x\n", Sector + i );
  56. } else {
  57. printf( "%d\n", Sector + i );
  58. }
  59. }
  60. if( Fat->IsEndOfChain( Cluster ) ) {
  61. break;
  62. }
  63. Cluster = Fat->QueryEntry( Cluster );
  64. }
  65. return TRUE;
  66. }
  67. int _CRTAPI1
  68. main(
  69. int argc,
  70. char **argv
  71. )
  72. /*++
  73. --*/
  74. {
  75. WCHAR PathString[512];
  76. STR DisplayBuffer[512];
  77. PATH Path;
  78. DSTRING NtDriveName, FsName, HpfsString, NtfsString, FatString;
  79. STREAM_MESSAGE Message;
  80. PWSTRING DosDriveName;
  81. NTSTATUS Status;
  82. BOOLEAN Result;
  83. ULONG i, Length;
  84. if( argc < 2 ) {
  85. printf( "usage: %s full-path [-x]\n", argv[0] );
  86. exit(1);
  87. }
  88. if( argc >= 3 &&
  89. argv[2][0] == '-' &&
  90. argv[2][1] == 'x' ) {
  91. HexOutput = TRUE;
  92. }
  93. if (!Message.Initialize(Get_Standard_Output_Stream(),
  94. Get_Standard_Input_Stream())) {
  95. printf( "Can't initialize MESSAGE object.\n" );
  96. exit(1);
  97. }
  98. // Convert argv[1] to a WSTR using brute force.
  99. //
  100. Length = strlen( argv[1] );
  101. for( i = 0; i < Length; i++ ) {
  102. PathString[i] = argv[1][i];
  103. }
  104. PathString[Length] = 0;
  105. if( !Path.Initialize( PathString, TRUE ) ) {
  106. printf( "Unable to initialize path object.\n" );
  107. exit(1);
  108. }
  109. // Get the drive from the path and convert it to
  110. // an NTFS name.
  111. //
  112. if( (DosDriveName = Path.QueryDevice()) == NULL ) {
  113. DELETE( DosDriveName );
  114. printf( "Cannot get drive from path.\n" );
  115. exit(1);
  116. }
  117. if (!IFS_SYSTEM::DosDriveNameToNtDriveName(DosDriveName, &NtDriveName)) {
  118. DELETE(DosDriveName);
  119. return 1;
  120. }
  121. DELETE( DosDriveName );
  122. // Determine the file system on the drive.
  123. //
  124. if (!IFS_SYSTEM::QueryFileSystemName(&NtDriveName, &FsName, &Status)) {
  125. printf( "Cannot determine NT Drive name. (Status = 0x%x\n)", Status );
  126. exit(1);
  127. }
  128. if( !FsName.QuerySTR( 0, TO_END, DisplayBuffer, 512 ) ) {
  129. printf( "QuerySTR failed.\n" );
  130. exit(1);
  131. }
  132. if( !FatString.Initialize( "FAT" ) ||
  133. !NtfsString.Initialize( "NTFS" ) ) {
  134. printf( "Can't initialize file-system name strings.\n" );
  135. exit(1);
  136. }
  137. if( FsName.Stricmp( &FatString ) == 0 ) {
  138. Result = FatSecList( &NtDriveName, &Path, &Message );
  139. } else if( FsName.Stricmp( &NtfsString ) == 0 ) {
  140. printf( "NTFS is not supported.\n" );
  141. exit(1);
  142. }
  143. if( Result ) {
  144. exit(0);
  145. } else {
  146. printf( "Seclist failed.\n" );
  147. exit(1);
  148. }
  149. //NOTREACHED
  150. return 0;
  151. }