home *** CD-ROM | disk | FTP | other *** search
-
- { PROGRAM TO COMPARE THE CRC'S OF THE FILE LISTS IN }
- { CHECK$$$.NEW AND CHECK$$$.CRC }
- { To be used with program Filecrc }
- { More extensive notes are included in FILECRC.PAS }
-
- {Version 1.00: 13 August 1986. First Production Version.
- 1.01: 1 September 1986. Allowed CRC of hidden system files.
- First Version to Usenet.
- 1.02: 12 September 1986. Fixed bug in handling of hidden files.
- 1.10: 30 May 1988. Eliminated chaining. Added sensitive list.
- 1.11: 15 June 1988. Fixed some minor printing bugs.
- }
-
- { The following compiler directives allow for I/O redirection (G,P & D),
- suppresses interrupts except when writing (U), and allows range
- checking (R) }
-
- {$G1,P1,D-,U-,R+ }
-
- Program Compare;
-
- TYPE
- string255 = string[255];
- string64 = string[64];
- string12 = string[12];
- string77 = string[77];
-
- Changed_Type = (deleted,updated,created,modified);
-
- Registers = record
- ax, bx, cx, dx, bp, si, di, ds, es, flags : integer;
- end;
- Months = array [1..12] of string[3];
-
- Directory_record = record
- directory : string64;
- FileNum : integer;
- end;
-
- File_Rec = record
- name : string12;
- time_of_day, date : integer;
- low_size,high_size : integer;
- attribute : byte;
- crc : integer;
- found : boolean;
- end;
-
-
- CONST
- month : Months = ('JAN','FEB','MAR','APR','MAY','JUN',
- 'JUL','AUG','SEP','OCT','NOV','DEC');
- Version = 1.11;
- Version_Date = '15 June 1988';
-
- { The next three variables may need to be changed to fit your
- specific situation. Unfortunately, Turbo-Pascal is limited in the
- amount of data space allowed. In order for you to keep within
- the limitations, you must have
- MAX_FILE * 24 + MAX_DIR * 66 + MAX_SENS * 77 < 57000
- }
- MAX_FILE = 1750; { Maximum number of files }
- MAX_DIR = 200; { Maximum number of directories }
- MAX_SENS = 30; { Maximum number of sensitive files }
-
- VAR
-
- { File Creation time and date }
- TimeOfDay, FileDate : integer;
- directory_number, file_number : integer;
- sensitive_end : integer;
-
- { Number of files in each category }
- Old_file, New_file, Del_file, OK_file,
- Update_file, Mod_file, S_file : integer;
-
- old_filename, new_filename : string64;
- infile : TEXT[$0800]; { file for reading file lists }
- outfile : TEXT; { copy of screen text }
- sens_file : TEXT; { file for reading sensitive file }
- newfile : TEXT; { file for writing names of new files created }
- delfile : TEXT; { file for writing names of deleted files }
- modfile : TEXT; { file for writing names of modified files }
- updatefile : TEXT; { file for writing names of updated files }
- tempfile : file; { used in renaming files }
-
- CRC_value : Integer;
-
- filename : string12;
- Name_of_File, CRC_string, instring : string255;
-
- attribute : byte;
- lowsize, highsize : integer;
- new, new_dir : boolean;
-
- number_directories, direct_count : integer;
-
- this_directory, current_directory : string64;
-
- directories : array [1..MAX_DIR] of directory_record;
- fileinfo : array [1..MAX_FILE] of file_rec;
- sensitive_file : array [1..MAX_SENS] of string77;
-
- function get_string : string255;
- {
- This function returns a string up to the first space from infile
- }
- var
- inchar : char;
- temp_string : string255;
-
- begin
- { Ignore any leading blanks }
- Repeat
- read(infile, inchar);
- Until inchar <> ' ';
-
- temp_string := '';
-
- { Now, add on to temp_string until a blank is found }
- Repeat
- temp_string := temp_string + inchar;
- read(infile, inchar);
- Until inchar = ' ';
-
- get_string := temp_string;
-
- end;
-
- procedure read_sensitive;
- {
- Procedure to read in the list of sensitive files
-
- }
-
- begin
- Reset (sens_file); { Set to read Old List of Files }
- sensitive_end := 0; { Number of files in the list }
- While not eof(sens_file) do
- begin
- sensitive_end := sensitive_end + 1;
- Readln(sens_file,sensitive_file[sensitive_end]);
- end;
- Close (sens_file);
- end;
-
-
- procedure read_old_file;
- {
- Procedure to read in the old list of files and set up the list of
- directories (variable directories), and the list of files along with
- the various data (variable fileinfo).
- On return,
- old_file has the number of files in the list and
- number_directories has the number of directories.
-
- The variables directories and fileinfo have the following information:
- directories directory : Name of the directory (up to 64 characters)
- FileNum : Number of the name in fileinfo that contains
- the information for the first file in this
- directory.
-
- fileinfo name : Name of the file
- time_of_day : Time of day in DOS format
- date : Date in DOS format
- low_size : Low byte of the file size
- high_size : High byte of the file size
- attribute : Attribute of the file
- crc : CRC of the file
- found : Boolean -- Has this file been found?
- All those file where found=FALSE have been
- deleted.
-
- }
-
- begin
- Reset (infile); { Set to read Old List of Files }
- old_file := 0; { Number of files in the list }
- number_directories := 0; { Number of directories in the list }
- While not eof(infile) do
- begin
- old_file := old_file + 1; { Another file }
- this_directory := get_string; { Get the directory name }
- fileinfo[old_file].name := get_string; { Get the file name }
- if this_directory <> current_directory then
- begin
- current_directory := this_directory;
- number_directories := number_directories + 1;
- directories[number_directories].directory := this_directory;
- directories[number_directories].FileNum := old_file;
- end;
- With fileinfo[old_file] do
- begin
- found := FALSE;
- Readln(infile,attribute, Time_of_day, date, low_size, high_size, crc);
- end;
- end;
- directories[number_directories + 1].FileNum := old_file + 1;
- Close (infile);
- end;
-
-
- function get_time(date1,date2 : integer) : string64;
- {
- This function returns the time and date of file creation.
- date1 is the time of day in DOS format
- date2 is the date of creation in DOS format
-
- get_time is a string with the time and date (e.g., 14:31:42 8 AUG 1986)
- }
-
- var
- hour, minute, second : integer;
- temp, time : string64;
- year, n_month, day : integer;
-
- begin
-
- if date2 <> 0 then
- begin
- hour := date1 shr 11;
- minute := (date1 shr 5) - (hour shl 6);
- second := (date1 - (minute shl 5) - (hour shl 11))*2;
- year := date2 shr 9;
- n_month := (date2 shr 5) - (year shl 4);
- day := date2 - (n_month shl 5) - (year shl 9);
- Str(hour:2,temp);
- time := temp + ':';
- Str(minute:2,temp);
- if temp[1] = ' ' then temp[1] := '0';
- time := time + temp + ':';
- Str(second:2,temp);
- if temp[1] = ' ' then temp[1] := '0';
- time := time + temp + ' ';
- Str(day:2,temp);
- time := time + temp + ' ' + month[n_month] + ' ';
- Str(year + 1980:4,temp);
- get_time := time + temp;
- end
- else
- get_time := ' ';
-
- end;
-
- procedure write_old_file ( file_number : integer);
- {
- Procedure to write the attribute, size and CRC for a file from
- the old list
-
- file_number is the number of the file name
-
- }
-
- var
- filesize : real;
- begin
- with fileinfo[file_number] do
- begin
- if low_size < 0 then
- filesize := int(high_size)*65536.0 + 32768.0 + int(low_size and $7FFF)
- else
- filesize := int(high_size)*65536.0 + int(low_size);
- Write (' Attribute = ',attribute:3,', Size = ',filesize:10:0);
- Write (outfile,' Attribute = ',attribute:3,', Size = ',filesize:10:0);
- Writeln (', CRC = ',CRC);
- Writeln (outfile,', CRC = ',CRC);
- end;
- end;
-
-
- procedure write_new_file;
- {
- Procedure to write the attribute, size and CRC for a file from
- the new list
-
- }
-
- var
- filesize : real;
- begin
- if lowsize < 0 then
- filesize := int(highsize)*65536.0 + 32768.0 + int(lowsize and $7FFF)
- else
- filesize := int(highsize)*65536.0 + int(lowsize);
- Write (' Attribute = ',attribute:3,', Size = ',filesize:10:0);
- Write (outfile,' Attribute = ',attribute:3,', Size = ',filesize:10:0);
- Writeln (', CRC = ', CRC_value);
- Writeln (outfile,', CRC = ', CRC_value)
- end;
-
-
- procedure find_directory( var number : integer; var newdir : boolean);
- {
- Procedure to find the directory from the old list that matches the
- directory name from the new list
-
- If the directory name is the same as the current directory, then
- number and newdir are unchanged.
-
- If the directory name is not the same, and it exists on the old list,
- number will be the number of the old directory, and newdir is FALSE.
- The current directory will be updated.
-
- If the directory name is not the same, and it does not exist on the
- old list, newdir is FALSE. Number is number of directories + 1, but
- is never used.
-
- }
- begin
- { If the directory is the same, then the status of number and newdir }
- { will not change }
- if this_directory <> current_directory then
- begin { search from the beginning -- nothing fancy }
- number := 0;
- Repeat
- number := number + 1;
- Until (number > number_directories) or
- (this_directory = directories[number].directory);
- newdir := (number > number_directories);
- current_directory := this_directory;
- end;
- end;
-
- procedure find_file( var number : integer; var new : boolean;
- number_begin, number_end : integer);
- {
- Procedure to find the file name. The directory name has been
- found prior to this time, so the starting point in the search
- has been found. The search will continue until the first file
- name in the next directory.
-
- }
- begin
- number := number_begin -1;
- Repeat
- number := number + 1;
- Until (number = number_end) or (filename = fileinfo[number].name);
- new := (filename <> fileinfo[number].name);
- if not new then
- fileinfo[number].found := TRUE; { Mark file as found }
- end;
-
- procedure sensitive (check_file : string255; changed : Changed_Type);
- {
- Check changed files to see if they are in the sensitive list.
- }
-
- var
- sensitive_number : integer;
- temp : string64;
- begin
- sensitive_number := 1;
- While sensitive_number <= sensitive_end do
- begin
- If check_file = sensitive_file[sensitive_number] then
- begin
- Write ('Sensitive File: ',check_file,' has been ');
- Write (outfile,'Sensitive File: ',check_file,' has been ');
- Case changed of
- created : begin
- Writeln ('created.');
- Writeln (outfile,'created.');
- end;
- updated : begin
- Writeln ('updated.');
- Writeln (outfile,'updated.');
- end;
- deleted : begin
- Writeln ('deleted.');
- Writeln (outfile,'deleted.');
- end;
- modified: begin
- Writeln ('modified.');
- Writeln (outfile,'modified.');
- end;
- end;
- S_file := S_file + 1;
- end;
- sensitive_number := sensitive_number + 1;
- end;
- end;
-
- procedure find_deleted;
- { Procedure to find all those files that were deleted.
- Del_file is the counter for the number of deleted files.
- }
- Var
- filesize : real;
- dir_number, file_number : integer;
-
- Begin
- dir_number := 0;
- For dir_number := 1 to number_directories do
- For file_number := directories[dir_number].Filenum to
- directories[dir_number+1].Filenum - 1 do
- If not fileinfo[file_number].found then
- begin
- Del_file := Del_file + 1;
- With fileinfo[file_number] do
- begin
- sensitive (this_directory + '\' + name,deleted);
- Write (delfile,this_directory + '\' + name);
- Writeln (delfile,' Date: ',get_time(time_of_day,date));
- if lowsize < 0 then
- filesize := int(highsize)*65536.0 + 32768.0 +
- int(lowsize and $7FFF)
- else
- filesize := int(highsize)*65536.0 + int(lowsize);
- Writeln (delfile,' Attr = ',attribute:3,
- ', Size = ',filesize:10:0,', CRC = ', CRC);
- end;
- end;
- end;
-
- procedure file_new;
- {
- This procedure processes the new files. new_file is the counter
- for the number of new files. The file name and information is
- written to the file assigned to newfile.
- }
-
- var
- filesize : real;
-
- begin
- new_file := new_file + 1;
- sensitive (this_directory + '\' + filename,created);
- Write (newfile,this_directory + '\' + filename);
- Writeln (newfile,' Date: ',get_time(TimeOfDay, FileDate));
- if lowsize < 0 then
- filesize := int(highsize)*65536.0 + 32768.0 + int(lowsize and $7FFF)
- else
- filesize := int(highsize)*65536.0 + int(lowsize);
- Writeln (newfile,' Attribute = ',attribute:3,
- ', Size = ',filesize:10:0,', CRC = ', CRC_value);
- end;
-
- procedure file_updated;
- {
- This procedure processes the updated files. Update_file is the counter
- for the number of updated files.
- }
-
- var
- filesize : real;
-
- begin
- Update_file := Update_file + 1;
- sensitive (this_directory + '\' + filename,updated);
- Writeln (updatefile,this_directory + '\' + filename);
- With fileinfo[file_number] do
- Begin
- Write (updatefile,'Old Date: ',get_time(time_of_day,date));
- if lowsize < 0 then
- filesize := int(highsize)*65536.0 + 32768.0 + int(lowsize and $7FFF)
- else
- filesize := int(highsize)*65536.0 + int(lowsize);
- Writeln (updatefile,' Attr = ',attribute:3,
- ', Size = ',filesize:10:0,', CRC = ', CRC);
- End;
- Write (updatefile,'New Date: ',get_time(TimeOfDay, FileDate));
- if lowsize < 0 then
- filesize := int(highsize)*65536.0 + 32768.0 + int(lowsize and $7FFF)
- else
- filesize := int(highsize)*65536.0 + int(lowsize);
- Writeln (updatefile,' Attr = ',attribute:3,
- ', Size = ',filesize:10:0,', CRC = ', CRC_value);
- end;
-
- procedure file_OK;
- {
- This procedure processes the files that have not been changed, modified
- or deleted. OK_file is the counter for the number of such files.
- }
-
- begin
- OK_file := OK_file + 1;
- end;
-
- procedure bad_CRC;
- {
- This procedure processes the files that have been modified without
- changing the directory entry date or time. Mod_file is the counter for
- the number of such files. In normal operations, this should not happen,
- so for such files, the name and date information is shown on the console
- and sent to the file assigned to modfile.
- }
-
- begin
- Mod_file := Mod_file + 1;
- sensitive (this_directory + '\' + filename,modified);
- Writeln ('CRC''s do not match! File: ',this_directory + '\' + filename);
- Writeln ('Date: ',get_time(TimeOfDay, FileDate));
- Write ('Old file:');
- Writeln (outfile,'CRC''s do not match! File: ',this_directory+'\'+filename);
- Writeln (outfile,'Date: ',get_time(TimeOfDay, FileDate));
- Write (outfile,'Old file:');
- write_old_file(file_number);
- Write ('New file:');
- Write (outfile,'New file:');
- write_new_file;
- Write (modfile, this_directory + '\' + filename);
- Writeln (modfile,' Date: ', get_time(TimeOfDay, FileDate));
- end;
-
- procedure read_new_file;
- {
- Procedure to read the list of new files, and compare them to the
- old files. The various comparison types are processed according to
- the preceeding routines.
- }
-
- begin
- current_directory := '';
- new_dir := FALSE;
-
- Assign (infile, new_filename);
- Reset (infile);
-
- While not eof(infile) do
- begin
- this_directory := get_string; { First is the directory name }
- filename := get_string; { Next is the file name }
- Readln(infile, attribute, TimeOfDay, FileDate, lowsize,
- highsize, crc_value); { Then the file parameters }
- { Find the entry in the list of old files with the same name }
- find_directory(directory_number,new_dir);
- if not new_dir then
- find_file(file_number,new,
- directories[directory_number].FileNum,
- directories[directory_number + 1].FileNum-1);
- if (new_dir or new) then { New directory means new file }
- file_new
- else { Existing file, compare the two }
- if (fileinfo[file_number].Time_of_day <> TimeOfDay)
- or (fileinfo[file_number].date <> FileDate) then
- file_updated
- else
- if (fileinfo[file_number].crc <> CRC_value) then bad_CRC
- else
- file_OK;
- end;
- Close (infile);
- end;
-
- procedure set_in_out;
- { Set up the input and output files }
- begin
- { See if any command line file names, and modify accordingly }
-
- Case ParamCount of
- 0 : begin { No command line parameters, use default names }
- old_filename := 'CHECK$$$.CRC';
- new_filename := 'CHECK$$$.NEW';
- end;
- 1 : begin { File name with listing of new files has been given }
- old_filename := 'CHECK$$$.CRC';
- new_filename := ParamStr(1);
- end;
- else
- begin { Both file names have been given }
- old_filename := ParamStr(2);
- new_filename := ParamStr(1);
- end;
- end;
-
- { Set up the various input and output files }
-
- Assign (infile,old_filename);
- Assign (newfile,'FILES$$$.NEW');
- Rewrite (newfile);
- Writeln (newfile,'New files created on this disk');
- Assign (delfile,'FILES$$$.DEL');
- Rewrite (delfile);
- Writeln (delfile,'Files that were deleted');
- Assign (modfile,'FILES$$$.MOD');
- Rewrite (modfile);
- Writeln (modfile,'Files that were modified without updating the directory');
- Assign (updatefile,'FILES$$$.UPD');
- Rewrite (updatefile);
- Writeln (updatefile,'Files that were updated on this disk');
- end;
-
-
- procedure initialize;
- { Initialize various pointers and numbers }
- begin
-
- { Set up the directory and file name pointers }
- number_directories := 1;
- current_directory := '';
- directories[1].directory := current_directory;
- directories[1].FileNum := 1;
-
- { Reset the counters for the various comparisons }
-
- Del_file := 0;
- New_file := 0;
- OK_file := 0;
- Update_file := 0;
- Mod_file := 0;
- S_file := 0;
- end;
-
-
-
- BEGIN { Compare }
-
- Writeln('CRC file integrity comparison program');
- Writeln('Version ',version:5:2,', ',version_date);
- Write('Written by Ted H. Emigh -- ');
- Writeln('emigh@ncsugn.uucp or NEMIGH@TUCC.BITNET');
-
- Assign (outfile,'FILECRC.OUT');
- Rewrite (outfile);
- Writeln(outfile,'CRC file integrity comparison program');
- Writeln(outfile,'Version ',version:5:2,', ',version_date);
- Write(outfile,'Written by Ted H. Emigh -- ');
- Writeln(outfile,'emigh@ncsugn.uucp or NEMIGH@TUCC.BITNET');
-
- { Initialize various pointers and numbers }
-
- initialize;
-
- { Set up the input and output files }
-
- set_in_out;
-
- { Read in the file containing the old CRC list }
-
- Writeln ('Reading old CRC list, please wait ...');
- read_old_file;
-
- { If the file SENSITIV exists, read in the list of sensitive files }
-
- Assign (sens_file, 'SENSITIV');
- {$I-}
- Reset (sens_file); { See if the file exists }
- {$I+}
- if IOresult <> 0 then
- sensitive_end := 0 { Sensitive list does not exist }
- else
- begin
- Writeln ('Reading sensitive file list, please wait ...');
- read_sensitive;
- end;
-
- { Read the new CRC list and check against the old list }
- {
- This procedure will check for all differences except if the
- file has been deleted -- that will be checked after all files
- have been processed
- }
- Writeln ('Reading new CRC list and checking, please wait ...');
- read_new_file;
-
- { Now, check for those files that were deleted -- they will have
- fileinfo[].found = FALSE
- }
- find_deleted;
-
- { Print the summary numbers for this check }
-
- Writeln;
- Writeln ('Number of Files in the last CRC check: ',old_file);
- Writeln ('Number of Files that are the same as last time: ',OK_file);
- Writeln ('Number of New Files: ',new_file);
- Writeln ('Number of Deleted Files: ',
- old_file - update_file - OK_file - Mod_file);
- Writeln ('Number of Updated Files: ',update_file);
- Writeln ('Number of Invalidly Modified Files: ',Mod_file);
- Writeln ('Number of Sensitive Files Changed: ',S_file);
- Writeln;
- Writeln;
-
- Writeln (outfile);
- Writeln (outfile,'Number of Files in the last CRC check: ',
- old_file);
- Writeln (outfile,'Number of Files that are the same as last time: ',
- OK_file);
- Writeln (outfile,'Number of New Files: ',
- new_file);
- Writeln (outfile,'Number of Deleted Files: ',
- old_file - update_file - OK_file - Mod_file);
- Writeln (outfile,'Number of Updated Files: ',
- update_file);
- Writeln (outfile,'Number of Invalidly Modified Files: ',
- Mod_file);
- Writeln (outfile,'Number of Sensitive Files Changed: ',
- S_file);
- Writeln (outfile);
- Writeln (outfile);
- Close (outfile);
-
- { Erase the output files if they are empty }
-
- Close (newfile);
- if new_file = 0 then Erase (newfile);
- Close (delfile);
- if del_file = 0 then Erase (delfile);
- Close (modfile);
- if Mod_file = 0 then Erase (modfile);
- Close (updatefile);
- if update_file = 0 then Erase (updatefile);
-
- { No command line parameters -- Rename the files with the file lists }
-
- if ParamCount = 0 then
- begin
- Assign (tempfile, 'CHECK$$$.OLD');
- {$I-}
- Reset (tempfile); { See if the file already exists }
- {$I+}
- if IOresult = 0 then
- Erase (tempfile); { Yes, it exists -- delete it }
- Close (tempfile);
- Assign (tempfile, 'CHECK$$$.CRC');
- Rename (tempfile, 'CHECK$$$.OLD');
- Assign (tempfile, 'CHECK$$$.NEW');
- Rename (tempfile, 'CHECK$$$.CRC');
- Writeln ('Old CRC file is now CHECK$$$.OLD');
- Writeln ('New CRC file is now CHECK$$$.CRC');
- Writeln;
- end;
-
-
-
- end.