PASCAL - CLOAK.ZIP - CLOAK.PAS

 
Output of file : CLOAK.PAS contained in archive : CLOAK.ZIP

program cloak;

uses crt,fcunit;

const
endoffile = chr(26);
protectmarker : string = chr(195)+chr(180);
type
eofaction = (Add, Remove, Noaction);
xfileobj1= object(fileobj)
procedure addeof(message:string);
procedure deleof;
end;

procedure xfileobj1.addeof;
begin
blockwrite(fp,message[1],length(message))
end;

procedure xfileobj1.deleof;
var
intro : datablk;
size, i : integer;
begin
readblock(intro,size);
i := 1;
while (i <= size) and (intro[i] <> ord(endoffile)) do
inc(i);
if (i > 255) or (intro[1] <> ord(protectmarker[1])) or
(intro[2] <> ord(protectmarker[2])) or
(intro[i-2] <> ord(protectmarker[1])) or
(intro[i-1] <> ord(protectmarker[2])) then
begin
writeln('File not protected');
halt(1)
end;
seek(fp,longint(i));
end;

var
infile, outfile : xfileobj1;
data : datablk;
size : integer;
option : byte;
msg : string; { debug msg = message }

begin
clrscr;
writeln('Cloaking program');
writeln;
writeln(' 1 to cloak File');
writeln(' 2 to uncloak a File');
writeln(' 0 to quit');
writeln;
write('Input: ');
readln(option);
if option = 0 then
begin
writeln('Program Terminated');
halt;
end;
case option of
1 : begin
msg := protectmarker + '- You can''t touch this -'+ protectmarker +
endoffile;
infile.openfile('Testfile.txt',input);
outfile.openfile('Testfile.cpy',output);
outfile.addeof(msg);
end;
2 : begin
infile.openfile('Testfile.cpy',input);
infile.deleof;
outfile.openfile('Testfile.chk',output);
end;
end;
repeat
infile.readblock(data,size);
outfile.writeblock(data,size);
until size <> sizeof(datablk);
infile.closefile;
outfile.closefile;
write('Press Enter to quit ... ');
readln;
end.