Мусорит в системе множеством файлов
Код:
program FileFaker;
{$APPTYPE CONSOLE}
uses Windows;
const
METHOD_BUFFERED=$00000000;
FILE_SPECIAL_ACCESS=$00000000;
FILE_DEVICE_FILE_SYSTEM=$00000009;
FILE_WRITE_DATA=$0002;
FSCTL_SET_SPARSE=FILE_DEVICE_FILE_SYSTEM shl 16 or FILE_SPECIAL_ACCESS shl 14 or 49 shl 2 or METHOD_BUFFERED;
type
TFileZeroDataInformation=packed record
FileOffset,BeyondFinalZero:LARGE_INTEGER;
end;
var
InputFile:TextFile;
FileHandle:THandle;
BytesReturned:Cardinal;
InputFileName,OutDir,Line,FileName:string;
Size,SizeFrom,SizeTo:LARGE_INTEGER;
{usysutils}
function StrToIntDef(AStr:string;ADef:Int64=0):Int64;
var
LCode:Integer;
begin
Val(AStr,Result,LCode);
if LCode<>0 then Result:=ADef;
end;
function ExtractFilePath(APath:string):string;
var
LI,LJ:Integer;
begin
if (Length(APath)<>0) and (Pos('\',APath)>0) then
begin
LJ:=0;
for LI:=Length(APath) downto 1 do
if APath[*]='\' then
begin
LJ:=LI;
Break;
end;
Result:=Copy(APath,1,LJ);
end else Result:='';
end;
function ExtractFileName(APath:string):string;
var
LI,LJ:Integer;
begin
if Length(APath)<>0 then
begin
LJ:=0;
for LI:=Length(APath) downto 1 do
if APath[*]='\' then
begin
LJ:=LI;
Break;
end;
Result:=Copy(APath,LJ+1,MaxInt);
end else Result:='';
end;
function FileExists(AFileName:string):Boolean;
var
LHandle:THandle;
LFindData:TWin32FindData;
begin
Result:=False;
LHandle:=FindFirstFile(PChar(AFileName),LFindData);
if LHandle<>INVALID_HANDLE_VALUE then
begin
Windows.FindClose(LHandle);
Result:=LFindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY=0;
end;
end;
function LastChar(AStr:string;AChar:Char):Boolean;
begin
Result:=False;
if Length(AStr)=0 then Exit;
Result:=AStr[Length(AStr)]=AChar;
end;
procedure AddLastBackSlash(var AStr:string);
begin
if not ((Length(AStr)=0) or LastChar(AStr,'\')) then AStr:=AStr+'\';
end;
procedure DeleteLastBackSlash(var AStr:string);
begin
if (Length(AStr)<>0) and LastChar(AStr,'\') then Delete(AStr,Length(AStr),1);
end;
function ForceDirectories(APath:string):Boolean;
begin
Result:=True;
if Length(APath)=0 then Exit;
DeleteLastBackSlash(APath);
if CreateDirectory(PChar(APath),nil) then Result:=True
else Result:=ForceDirectories(ExtractFilePath(APath)) and CreateDirectory(PChar(APath),nil);
end;
{/usysutils}
procedure About;
begin
WriteLn;
WriteLn('File faker for NTFS v1.1');
WriteLn('programmed by Holy_Father');
WriteLn('Copyright (c) 2000,forever ExEwORx');
WriteLn('birthday: 01.04.2003');
WriteLn('home: http://www.hxdef.org, http://hxdef.net.ru,');
WriteLn(' http://hxdef.czweb.org, http://rootkit.host.sk');
WriteLn;
end;
procedure Usage;
var
LExeName:string;
begin
LExeName:=ExtractFileName(ParamStr(0));
WriteLn('This program can create very small files on NTFS.');
WriteLn('But their size is only illusion.');
WriteLn('Their size on the disk is only few kilobytes.');
WriteLn;
WriteLn('Usage: '+LExeName+' inputfile outdir');
WriteLn;
WriteLn('inputfile struct:');
WriteLn(':sizefrom:sizeto');
WriteLn('filename1');
WriteLn('filename2');
WriteLn('...');
WriteLn(':sizefrom:sizeto');
WriteLn('filename1');
WriteLn('filename2');
WriteLn('...');
WriteLn;
WriteLn('inputfile example:');
WriteLn(':600000000:800000000');
WriteLn('Matrix CD 1.avi');
WriteLn('Matrix CD 2.avi');
WriteLn(':7000000000:8000000000');
WriteLn('Matrix full.vob');
WriteLn;
Halt;
end;
begin
About;
if ParamCount<>2 then Usage;
InputFileName:=ParamStr(1);
OutDir:=ParamStr(2);
if not FileExists(InputFileName) then
begin
WriteLn(InputFileName,' does not exist!');
Exit;
end;
Randomize;
AddLastBackslash(OutDir);
ForceDirectories(OutDir);
SizeTo.QuadPart:=0;
AssignFile(InputFile,InputFileName);
Reset(InputFile);
while not EoF(InputFile) do
begin
Line:='';
while Length(Line)=0 do ReadLn(InputFile,Line);
if Line[1]=':' then
begin
Line:=Copy(Line,2,MaxInt);
SizeFrom.QuadPart:=StrToIntDef(Copy(Line,1,Pos(':',Line)-1));
SizeTo.QuadPart:=StrToIntDef(Copy(Line,Pos(':',Line)+1,MaxInt));
end else
begin
if SizeTo.QuadPart=0 then Continue;
FileName:=OutDir+Line;
FileHandle:=CreateFile(PChar(FileName),GENERIC_WRITE,0,nil,CREATE_ALWAYS,FILE_FLAG_RANDOM_ACCESS,0);
Write(FileName,' - ');
if FileHandle<>INVALID_HANDLE_VALUE then
begin
if DeviceIoControl(FileHandle,FSCTL_SET_SPARSE,nil,0,nil,0,BytesReturned,nil) then
begin
Size.QuadPart:=SizeFrom.QuadPart+Trunc(Random*(SizeTo.QuadPart-SizeFrom.QuadPart));
SetFilePointer(FileHandle,Size.LowPart,@Size.HighPart,FILE_BEGIN);
SetEndOfFile(FileHandle);
WriteLn('OK (',Size.QuadPart,')');
CloseHandle(FileHandle);
end else
begin
WriteLn('failed');
CloseHandle(FileHandle);
DeleteFile(PChar(FileName));
end;
end else WriteLn('failed');
end;
end;
CloseFile(InputFile);
end.