home *** CD-ROM | disk | FTP | other *** search
- {*A program to unscramble the File Allocation Table.
- References: DOS Tech. Manual, Inside the IBM PC
-
- Oct 27, 1984, Chun-sien Lin & Zhiyong Shen
- Metallurgical Engineering,
- The Ohio State University
- 116 W. 19th Ave.
- Columbus, Oh 43210
- Phone: (614) 4221927
-
- *This program is allowed to be freely copied and modified*
- *}
-
- program test_readfat(input,output);
- type
- my = string[4];
- fat_table_type = array [0..315] of integer;
- char_type = string[1];
- sector_as_bytes_type = array [0..511] of byte;
- regpack = record
- ax,bx,cx,dx,bp,di,si,ds,es,flags: integer;
- end;
- const
- title1 : array[0..15] of my=(' 00 ',' 01 ',' 02 ',' 03 ',' 04 ',
- ' 05 ',' 06 ',' 07 ',' 08 ',' 09 ',' 0A ',' 0B ',' 0C ',
- ' 0D ',' 0E ',' 0F ');
- var
- drive : integer;
- side : integer;
- track : integer;
- sector : integer;
- work1 : string[1];
- work2 : string[1];
- temp : integer;
- char_count : integer;
- column_count : integer;
- i,j : integer;
- work_sector : sector_as_bytes_type;
- fat_table : fat_table_type;
- recpack : regpack;
- ah,al,bh,bl,ch,cl,dh,dl:byte;
- { Procedure convert the FAT to hex char for output }
-
- procedure convert(var work1,work2 : char_type;
- work : byte);
- var
- temp : integer;
- begin
- temp:=work mod 16;
- str(temp:1,work2);
- case temp of
- 10 : work2 := 'A';
- 11 : work2 := 'B';
- 12 : work2 := 'C';
- 13 : work2 := 'D';
- 14 : work2 := 'E';
- 15 : work2 := 'F';
- end;
-
- temp:=work div 16;
- str(temp:1,work1);
- case temp of
- 10 : work1 := 'A';
- 11 : work1 := 'B';
- 12 : work1 := 'C';
- 13 : work1 := 'D';
- 14 : work1 := 'E';
- 15 : work1 := 'F';
- end;
- end;
-
- { End of function convert definition }
-
- { Procedure to set up FAT table for tracing the file allocation }
- Procedure fattbl(var fat_table : fat_table_type;
- work_sector : sector_as_bytes_type);
- var
- temp : integer;
- i : integer;
- offset : integer;
- work1 : string[1];
- work2 : string[1];
- begin
- for i:=0 to 317 do
- begin
- offset := (i*3) div 2;
- if odd(i) then
- temp := work_sector[offset+1]*16+work_sector[offset] div 16
- else
- temp := work_sector[offset]+(work_sector[offset+1] mod 16)
- shl 8;
- fat_table[i] := temp;
- end;
- end;
- {End of procedure fattbl }
-
-
-
- begin
-
- with recpack do
- begin
- ah:=$2; { request absolute disk read for interrupt 13h}
- al:=$1; { read one sector at a time}
- ax:=ah shl 8 + al;
- ch:=0; { track #}
- cl:=2; { sector #}
- cx:=ch shl 8 + cl;
- dh:=0; { side #}
- dl:=0; { drive #}
- dx:=dh shl 8 + dl;
- bx:=ofs(work_sector);
- es:=seg(work_sector);
- end;
- intr($13,recpack); {call interrupts}
- char_count := 23;
- column_count := 3;
- writeln('Scrambled File Allocation Table Entry >>>>>');
- writeln;
- for i:=0 to 511 do
- begin
- convert(work1,work2,work_sector[i]);
- if i<char_count then
- begin
- write(work1);
- if i<column_count then
- write(work2)
- else
- begin
- column_count := column_count + 4;
- write(work2,' ');
- end;
- end
- else
- begin
- char_count := char_count + 24;
- column_count := column_count + 4;
- write(work1);
- writeln(work2);
- end
- end;
- writeln;
- write('Hit any key to continue.');
- read;
- clrscr;
- {Print out FAT table entry unscrambled values }
- writeln(' Unscrambled File Allocation Table Entry ');
- writeln;
- for i:=0 to 15 do
- begin
- write(title1[i],' ');
- end;
- writeln;
-
- fattbl(fat_table,work_sector);
- for i:=0 to 317 do
- begin
- convert(work1,work2,fat_table[i] shr 8);
- write(work1,work2);
- convert(work1,work2,fat_table[i]);
- write(work1,work2,' ')
- end;
- write(char(13),char(10),'Hit any key to end...'); read
- end.