Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- { Written by Kulverstukas on 2010.02.20 for EZ community - evilzone.org || last update: 2010.04.03 }
- program SystemProtekter;
- uses SysUtils, Crt, Windows, Dos;
- var original_autoexec, original_boot, original_ntldr, original_hal, original_config, original_io, original_ntdetect, original_msdos,
- backup_autoexec, backup_boot, backup_ntldr, backup_hal, backup_config, backup_io, backup_ntdetect, backup_msdos : File of byte;
- // homedrive_envvar, homedrive_autoexec_orig, system32_var, homedrive_autoexec_bak : pchar;
- //=================================
- {
- check if backup folder exist in designated location, if folder exists, check if files exist in the backup folder,
- if files exist, then say that it's all cool and exit. If files in backup folder doesn't exist then copy them
- If backup folder doesn't exist then create one and copy files from WINDOWS dir. However, if files in WINDOWS dir
- doesn't exist, then copy them from backup folder to WINDOWS dir. *If files in SYSTEM are different in size then
- backup files, then remove the SYSTEM files and copy backup ones*.
- *** Caution: this program was written assuming that if you run this program for the first time, files that are
- critical for system boot already exist in WINDOWS dir.
- }
- {$I-} // disable IO checking. If folder/file exists then do what is written instead of halting.
- //=================================
- {
- "FileAge" returns the last modification time of file "FileName". The "RawDate" format can be transformed to
- "TDateTime" format with the "FileDateToDateTime" function.
- }
- function GetTimeStamp(FileName : string); //*** GetTimeStamp starts from this line
- var DateTime : TDateTime;
- RawDate : longint;
- begin
- RawDate := FileAge(FileName); // Get the Time Stamp in it's raw stage - not readable to humans.
- if RawDate <> -1 then // If something goes wrong then -1 is returned
- begin
- DateTime := FileDateToDateTime(RawDate); // Second stage transformation - still not readable to humans.
- Writeln(DateTimeToStr(DateTime)); // Third stage transformation - now it's readable.
- end
- else
- begin
- TextColor(Red);
- WriteLn('Malfunction'); // Write this if anything goes wrong
- TextColor(white);
- end;
- end;
- //=================================
- {
- Environmental Variables does not work with CopyFile(); because procedure in SysUtils is like this:
- CopyFile(const FileName, NewFileName:string; SkipIfExists:boolean);
- So to use Environmental Variables they have to be in raw text and not stored into a variable.
- Whatever written between '' is used directly with no conversion. So if "%systemdrive%" was written instead of
- "C:", compiler will think that "%systemdrive%" is a name of disk.
- }
- procedure copy_windows_files; //*** windows file copying from windows starts from this line
- begin
- {
- homedrive_envvar := SysUtils.GetEnvironmentVariable('systemdrive');
- homedrive_autoexec_orig := homedrive_envvar+'\autoexec.bat';
- homedrive_autoexec_bak := homedrive_envvar+'\Documents and Settings\SystemProtekter\autoexec.b4ckup';
- system32_var := SysUtils.GetEnvironmentVariable('windir');
- }
- CopyFile('C:\autoexec.bat','C:\Documents and Settings\SystemProtekter\autoexec_bat.b4ckup',true);
- CopyFile('C:\boot.ini','C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup',true);
- CopyFile('C:\ntldr','C:\Documents and Settings\SystemProtekter\ntldr.b4ckup',true);
- CopyFile('C:\windows\system32\HAL.DLL','C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup',true);
- CopyFile('C:\CONFIG.sys','C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup',true);
- CopyFile('C:\IO.sys','C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup',true);
- CopyFile('C:\NTDETECT.COM','C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup',true);
- CopyFile('C:\MSDOS.SYS','C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup',true);
- end;
- //=================================
- procedure copy_backup_files; //*** backup file copying from backup starts from this line
- begin
- CopyFile('C:\Documents and Settings\SystemProtekter\AUTOEXEC_bat.b4ckup','C:\AUTOEXEC.bat',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup','C:\boot.ini',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\ntldr.b4ckup','C:\ntldr',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup','C:\windows\system32\HAL.DLL',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup','C:\CONFIG.sys',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup','C:\IO.sys',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup','C:\NTDETECT.COM',true);
- CopyFile('C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup','C:\MSDOS.SYS',true);
- end;
- //=================================
- {
- This doesn't work when everything is written in one piece, like first assigning and opening, then comparison.
- This has to be done separatly as it is now, wich is not practical because takes more space and size.
- When written in one chunk of code, it returns "Access denied" although all other procedures work file.
- ***There is something wrong with this that it doesn't delete and copy files and I have no clue what could be
- wrong. Gotta leave this for now.
- }
- {procedure filesize_comparison; //*** comparison starts from this line
- begin
- begin
- //=====
- Assign(original_boot,'C:\boot.ini');
- Reset(original_boot);
- Assign(backup_boot,'C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup');
- Reset(backup_boot);
- if (FileSize(original_boot) = FileSize(backup_boot)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''boot.ini'' matches the backup');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''boot.ini'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_boot, 'C:\boot.ini');
- Erase(erase_boot);
- CopyFile('C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup','C:\boot.ini',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_boot);
- Close(backup_boot);
- //=====
- Assign(original_ntldr, 'C:\ntldr');
- Reset (original_ntldr);
- Assign(backup_ntldr, 'C:\Documents and Settings\SystemProtekter\ntldr.b4ckup');
- Reset (backup_ntldr);
- if (FileSize(original_ntldr) = FileSize(backup_ntldr)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''ntldr'' matches the backup');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''ntldr'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_ntldr, 'C:\ntldr');
- Erase(erase_ntldr);
- CopyFile('C:\Documents and Settings\SystemProtekter\ntldr.b4ckup','C:\ntldr',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_ntldr);
- Close(backup_ntldr);
- //=====
- Assign(original_hal, 'C:\windows\system32\HAL.DLL');
- Reset (original_hal);
- Assign(backup_hal, 'C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup');
- Reset (backup_hal);
- if (FileSize(original_hal) = FileSize(backup_hal)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''hall.dll'' matches the backup');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''hal.dll'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_hal, 'C:\windows\system32\HAL.DLL');
- Erase(erase_hal);
- CopyFile('C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup','C:\windows\system32\HAL.DLL',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_hal);
- Close(backup_hal);
- //=====
- Assign(original_config, 'C:\CONFIG.sys');
- Reset (original_config);
- Assign(backup_config, 'C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup');
- Reset (backup_config);
- if (FileSize(original_config) = FileSize(backup_config)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''config.sys'' matches the backup');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''config.sys'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_config, 'C:\CONFIG.sys');
- Erase(erase_config);
- CopyFile('C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup','C:\CONFIG.sys',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_config);
- Close(backup_config);
- //=====
- Assign(original_io, 'C:\IO.sys');
- Reset (original_io);
- Assign(backup_io, 'C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup');
- Reset (backup_io);
- if (FileSize(original_io) = FileSize(backup_io)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''IO.sys'' matches the backup.');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''IO.sys'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_io, 'C:\IO.sys');
- Erase(erase_io);
- CopyFile('C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup','C:\IO.sys',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_io);
- Close(backup_io);
- //=====
- Assign(original_ntdetect, 'C:\NTDETECT.COM');
- Reset (original_ntdetect);
- Assign(backup_ntdetect, 'C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup');
- Reset (backup_ntdetect);
- if (FileSize(original_ntdetect) = FileSize(backup_ntdetect)) then
- begin
- TextColor(green);
- WriteLn('Original file size of ''NTDETECT.com'' matches the backup.');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original file size of ''NTDETECT.com'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_ntdetect, 'C:\NTDETECT.COM');
- Erase(erase_ntdetect);
- CopyFile('C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup','C:\NTDETECT.COM',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- Close(original_ntdetect);
- Close(backup_ntdetect);
- //=====
- Assign(original_msdos, 'C:\MSDOS.SYS');
- Reset (original_msdos);
- Assign(backup_msdos, 'C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup');
- Reset (backup_msdos);
- if (FileSize(original_msdos) = FileSize(backup_msdos)) then
- begin
- TextColor(green);
- WriteLn('Original files size of ''MSDOS.sys'' matches the backup');
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Original files size of ''MSDOS.sys'' doesn''t match the backup.');
- WriteLn('Deleting original files and copying backup');
- Assign(erase_msdos, 'C:\MSDOS.SYS');
- Erase(erase_msdos);
- CopyFile('C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup','C:\MSDOS.SYS',true);
- TextColor(green);
- WriteLn('System is protected');
- TextColor(white);
- end;
- end;
- Close(original_msdos);
- Close(backup_msdos);
- //=====
- end;
- end; }
- //=================================
- function backup_file; //*** backup file operations start from this line
- begin
- if FileExists('C:\Documents and Settings\SystemProtekter\AUTOEXEC_bat.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\ntldr.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup')
- and FileExists('C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup') then
- begin
- TextColor(white);
- WriteLn;
- TextColor(green);
- WriteLn('Backup files exist. Sizes of backup files:');
- //======
- Assign(backup_boot,'C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup');
- Reset(backup_boot);
- TextColor (lightgreen);
- Write ('[backup]\boot_ini.b4ckup...............: ',FileSize(backup_boot),' bytes. Mod: ');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\boot_ini.b4ckup');
- Close(backup_boot);
- //======
- Assign(backup_ntldr,'C:\Documents and Settings\SystemProtekter\ntldr.b4ckup');
- Reset(backup_ntldr);
- Write ('[backup]\ntldr.b4ckup..................: ',FileSize(backup_ntldr),' bytes. Mod: ');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\ntldr.b4ckup');
- Close(backup_ntldr);
- //======
- Assign(backup_hal,'C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup');
- Reset(backup_hal);
- Write ('[backup]\hal_dll.b4ckup................: ',FileSize(backup_hal),' bytes. Mod: ');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\hal_dll.b4ckup');
- Close(backup_hal);
- //======
- Assign(backup_config,'C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup');
- Reset(backup_config);
- Write ('[backup]\CONFIG_sys.b4ckup.............: ',FileSize(backup_config),' bytes. Mod: ');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\CONFIG_sys.b4ckup');
- Close(backup_config);
- //======
- Assign(backup_io,'C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup');
- Reset(backup_io);
- Write ('[backup]\IO_SYS.b4ckup.................: ',FileSize(backup_io),' bytes. Mod:');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\IO_SYS.b4ckup');
- Close(backup_io);
- //======
- Assign(backup_ntdetect,'C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup');
- Reset(backup_ntdetect);
- Write ('[backup]\NTDETECT_COM.b4ckup...........: ',FileSize(backup_ntdetect),' bytes. Mod: ');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\NTDETECT_COM.b4ckup');
- Close(backup_ntdetect);
- //======
- Assign(backup_msdos,'C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup');
- Reset(backup_msdos);
- Write ('[backup]\MSDOS_SYS.b4ckup..............: ',FileSize(backup_msdos),' bytes. Mod:');
- GetTimeStamp('C:\Documents and Settings\SystemProtekter\MSDOS_SYS.b4ckup');
- Close(backup_msdos);
- TextColor(white);
- //======
- TextColor(white);
- end
- else
- begin
- TextColor(red);
- WriteLn('Files doesn''t exist. Copying from SYSTEM dir...');
- TextColor(white);
- copy_windows_files;
- end;
- end;
- //=================================
- procedure backup_folder; //*** backup folder operations start from this line
- begin
- MkDir('C:\Documents and Settings\SystemProtekter');
- if (IOResult <> 0) then // if folder exists then IOResult returns 1 if it doesn't, IOResult returns 0
- begin
- TextColor(white);
- WriteLn('========================================================');
- TextColor(green);
- WriteLn ('Backup folder exists. Checking if backup files exist...'); // IOResult is returened as 1, so write that it does exist
- TextColor(white);
- backup_file;
- end
- else
- begin
- TextColor(white);
- WriteLn('========================================================');
- TextColor(red);
- WriteLn('Backup folder doesn''t exist. Creating and copying files...');
- TextColor(white);
- MkDir('C:\Documents and Settings\SystemProtekter');
- copy_windows_files; // folder has just been created so obviously no files are in it. Go and copy them
- end;
- end;
- //=================================
- function file_windows; //*** file checking in WINDOWS dir starts from this line
- begin
- if FileExists('C:\AUTOEXEC.bat')
- and FileExists('C:\boot.ini')
- and FileExists('C:\ntldr')
- and FileExists('C:\windows\system32\HAL.DLL')
- and FileExists('C:\CONFIG.sys')
- and FileExists('C:\IO.sys')
- and FileExists('C:\NTDETECT.COM')
- and FileExists('C:\MSDOS.SYS') then
- begin
- TextColor (white);
- WriteLn('========================================================');
- TextColor (green);
- WriteLn ('Files exists in SYSTEM. Sizes of original files:');
- TextColor (white);
- //======
- Assign(original_boot,'C:\boot.ini');
- Reset(original_boot);
- TextColor (lightgreen);
- Write ('C:\boot.ini............................: ',FileSize(original_boot),' bytes. Mod: ');
- GetTimeStamp('C:\boot.ini');
- Close(original_boot);
- //======
- Assign(original_ntldr,'C:\ntldr');
- Reset(original_ntldr);
- Write ('C:\ntldr...............................: ',FileSize(original_ntldr),' bytes. Mod: ');
- GetTimeStamp('C:\ntldr');
- Close(original_ntldr);
- //======
- Assign(original_hal,'C:\windows\system32\HAL.DLL');
- Reset(original_hal);
- Write ('%windir%\system32\HAL.DLL..............: ',FileSize(original_hal),' bytes. Mod: ');
- GetTimeStamp('C:\windows\system32\HAL.DLL');
- Close(original_hal);
- //======
- Assign(original_config,'C:\CONFIG.sys');
- Reset(original_config);
- Write ('C:\CONFIG.sys..........................: ',FileSize(original_config),' bytes. Mod: ');
- GetTimeStamp('C:\CONFIG.sys');
- Close(original_config);
- //======
- Assign(original_io,'C:\IO.sys');
- Reset(original_io);
- Write ('C:\IO.sys..............................: ',FileSize(original_io),' bytes. Mod: ');
- GetTimeStamp('C:\IO.sys');
- Close(original_io);
- //======
- Assign(original_ntdetect,'C:\NTDETECT.com');
- Reset(original_ntdetect);
- Write ('C:\NTDETECT.com........................: ',FileSize(original_ntdetect),' bytes. Mod: ');
- GetTimeStamp('C:\NTDETECT.com');
- Close(original_ntdetect);
- //======
- Assign(original_msdos,'C:\MSDOS.sys');
- Reset(original_msdos);
- Write ('C:\MSDOS.sys...........................: ',FileSize(original_msdos),' bytes. Mod: ');
- GetTimeStamp('C:\MSDOS.sys');
- Close(original_msdos);
- TextColor(white);
- //======
- backup_folder;
- WriteLn('========================================================');
- end
- else
- begin
- TextColor(red);
- WriteLn('Files doesn''t exist in SYSTEM. Copying...');
- copy_backup_files;
- end;
- end;
- //=================================
- begin
- file_windows;
- Write ('Hit any key to exit...');
- //=====
- GoToXY(40,23); // Date-to-String and Time-to-String converts date and time to human language. "now" returns current time and date
- Write('Time and date: ',DateToStr(now),' // ',TimeToStr(now));
- //=====
- readkey;
- end.
Add Comment
Please, Sign In to add comment