home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / FAT.ZIP / FAT.PAS
Encoding:
Pascal/Delphi Source File  |  1986-02-18  |  4.5 KB  |  165 lines

  1. {*A program to unscramble the File Allocation Table.
  2.   References: DOS Tech. Manual, Inside the IBM PC
  3.  
  4.   Oct 27, 1984, Chun-sien Lin & Zhiyong Shen
  5.   Metallurgical Engineering,
  6.   The Ohio State University
  7.   116 W. 19th Ave.
  8.   Columbus, Oh 43210
  9.   Phone: (614) 4221927
  10.  
  11. *This program is allowed to be freely copied and modified*
  12.                                                                *}
  13.  
  14. program test_readfat(input,output);
  15. type
  16.   my                    = string[4];
  17.   fat_table_type        = array [0..315] of integer;
  18.   char_type             = string[1];
  19.   sector_as_bytes_type  = array [0..511] of byte;
  20.   regpack               = record
  21.                           ax,bx,cx,dx,bp,di,si,ds,es,flags: integer;
  22.                         end;
  23. const
  24.   title1       : array[0..15] of my=(' 00 ',' 01 ',' 02 ',' 03 ',' 04 ',
  25.                ' 05 ',' 06 ',' 07 ',' 08 ',' 09 ',' 0A ',' 0B ',' 0C ',
  26.                  ' 0D ',' 0E ',' 0F ');
  27. var
  28.   drive        : integer;
  29.   side         : integer;
  30.   track        : integer;
  31.   sector       : integer;
  32.   work1        : string[1];
  33.   work2        : string[1];
  34.   temp         : integer;
  35.   char_count   : integer;
  36.   column_count : integer;
  37.   i,j          : integer;
  38.   work_sector  : sector_as_bytes_type;
  39.   fat_table    : fat_table_type;
  40.   recpack      : regpack;
  41.   ah,al,bh,bl,ch,cl,dh,dl:byte;
  42. { Procedure convert the FAT to hex char for output }
  43.  
  44. procedure convert(var work1,work2 : char_type;
  45.                        work      : byte);
  46.   var
  47.     temp       : integer;
  48.   begin
  49.           temp:=work mod 16;
  50.           str(temp:1,work2);
  51.           case temp of
  52.             10 : work2 := 'A';
  53.             11 : work2 := 'B';
  54.             12 : work2 := 'C';
  55.             13 : work2 := 'D';
  56.             14 : work2 := 'E';
  57.             15 : work2 := 'F';
  58.           end;
  59.  
  60.           temp:=work div 16;
  61.           str(temp:1,work1);
  62.           case temp of
  63.             10 : work1 := 'A';
  64.             11 : work1 := 'B';
  65.             12 : work1 := 'C';
  66.             13 : work1 := 'D';
  67.             14 : work1 := 'E';
  68.             15 : work1 := 'F';
  69.           end;
  70.   end;
  71.  
  72. { End of function convert definition }
  73.  
  74. { Procedure to set up FAT table for tracing the file allocation }
  75.   Procedure fattbl(var fat_table : fat_table_type;
  76.                        work_sector : sector_as_bytes_type);
  77.     var
  78.       temp     : integer;
  79.       i        : integer;
  80.       offset : integer;
  81.       work1      : string[1];
  82.       work2      : string[1];
  83.     begin
  84.       for i:=0 to 317 do
  85.         begin
  86.           offset := (i*3) div 2;
  87.           if odd(i) then
  88.             temp := work_sector[offset+1]*16+work_sector[offset] div 16
  89.           else
  90.             temp := work_sector[offset]+(work_sector[offset+1] mod 16)
  91.                     shl 8;
  92.             fat_table[i] := temp;
  93.         end;
  94.      end;
  95. {End of procedure fattbl }
  96.  
  97.  
  98.  
  99. begin
  100.  
  101.   with recpack do
  102.     begin
  103.       ah:=$2;     { request absolute disk read for interrupt 13h}
  104.       al:=$1;     { read one sector at a time}
  105.       ax:=ah shl 8 + al;
  106.       ch:=0;     { track #}
  107.       cl:=2;     { sector #}
  108.       cx:=ch shl 8 + cl;
  109.       dh:=0;     { side #}
  110.       dl:=0;     { drive #}
  111.       dx:=dh shl 8 + dl;
  112.       bx:=ofs(work_sector);
  113.       es:=seg(work_sector);
  114.     end;
  115.   intr($13,recpack);      {call interrupts}
  116.   char_count := 23;
  117.   column_count := 3;
  118.   writeln('Scrambled File Allocation Table Entry >>>>>');
  119.   writeln;
  120.   for i:=0 to 511  do
  121.     begin
  122.       convert(work1,work2,work_sector[i]);
  123.       if i<char_count then
  124.         begin
  125.         write(work1);
  126.         if i<column_count then
  127.           write(work2)
  128.         else
  129.           begin
  130.           column_count := column_count + 4;
  131.           write(work2,' ');
  132.           end;
  133.         end
  134.       else
  135.         begin
  136.           char_count := char_count + 24;
  137.           column_count := column_count + 4;
  138.           write(work1);
  139.           writeln(work2);
  140.         end
  141.     end;
  142.     writeln;
  143.     write('Hit any key to continue.');
  144.     read;
  145.     clrscr;
  146. {Print out FAT table entry unscrambled values  }
  147.      writeln(' Unscrambled File Allocation Table Entry ');
  148.      writeln;
  149.      for i:=0 to 15 do
  150.        begin
  151.         write(title1[i],' ');
  152.        end;
  153.       writeln;
  154.  
  155.       fattbl(fat_table,work_sector);
  156.       for i:=0 to 317 do
  157.       begin
  158.         convert(work1,work2,fat_table[i] shr 8);
  159.         write(work1,work2);
  160.         convert(work1,work2,fat_table[i]);
  161.         write(work1,work2,' ')
  162.       end;
  163. write(char(13),char(10),'Hit any key to end...'); read
  164. end.
  165.