Let's annoy fellow co-workers! Run a Hello World Virus on their computers...
While this article uses the term "virus", the code demonstrated here is not a
virus or any other form of malware. If you use this program to annoy your co-
workers - you may have to deal with the repercussions!
Who said programming cannot be fun? Let's create a simple "memory eater"
that executes itself an unlimited number of times - thus consuming all the
Windows memory :)
The "Hello World VIRUS" we will build in this article is, of course, not a true
virus. We'll create a totally useless application that executes itself when it gets
Ok, ok. Let's build a fair virus. The Virus will execute itself only a limited
number of times. The last instance will clean up the system by terminating all
the running instances.
1996
if execCount < MAXExecuteCount then
begin
infoLabel.Caption := Format('Clone Nr: %d',[execCount]) ;
else199
6
begin
//Let's be fair .. kill all clones...
Application.MessageBox('Hello, Scared?',PChar(Application.Title)) ;
Caption := 'I will close normally';
KillClones;
Application.MessageBox('System secured!',PChar(Application.Title)) ;
end; end;
When MAXExecuteCount is reached, since this is not a bad virus, the last
instance ensures that all the running instances are terminated.
procedure THelloWorldVirusForm.KillClones;
var
cloneHandle : THandle;
cloneHandles : TStringList;
sHandle : string;
begin
cloneHandles := TStringList.Create;
try
EnumWindows(@EnumWindowsFunc, LParam(cloneHandles)) ;
for sHandle in cloneHandles do
begin 1996
cloneHandle := StrToInt(sHandle) ;
if cloneHandle <> self.Handle then SendMessage(cloneHandle, WM_CloneQuit, 0, 0) ;
end;
finally
cloneHandles.Free;
end;
end;
;2001
The EnumWindows fills a TStringList with the handles of the running Virus instances. A simple for
loop is used to send a custom message to the Virus instance.
begin
;2001
GetClassName(Handle, className, SizeOf(className)-1) ;
GetWindowText(Handle, caption, SizeOf(caption)-1) ;
Result :=True;
end;
1996
The Virus handles the custom message by calling Application.Terminate.
const
WM_CloneQuit = WM_USer + 2901; //"random" number
...
procedure Quit(var Msg : TMessage) ; message WM_CloneQuit;
...
procedureTHelloWorldVirusForm.Quit(var Msg: TMessage) ;
begin
Application.Terminate;
end;
Final WARNING: do NOT execute the Hello World Virus from the Delphi IDE, build the code and
start the program from the Windows Explorer. If you run the application from the IDE - one instace
will be left running. Use the Task Manager to terminate it.
* Download
Discuss
Related Articles
Zarko Gajic
Zarko Gajic
Delphi Programming Guide
* My Blog
* My Forum ;2001
Sponsored Links
C++ ProgrammingStay on top of trends in parallel computing. Read our expert blog!
www.drdobbs.com/Go-Parallel
Iframe Malware RemoverRemove Malware from live websites CMS, HTML, PHP, ASP, Files and
morewww.SeedCoreGroup.com
Orchid Virus TestFast and easy orchid virus testing Detect ORSV/CymMV in
minuteswww.agdia.com
Advertisement
Explore Delphi Programming
Must Reads
Most Popular
Virtual Key CodesExecute External Program, FileNetwork traffic monitorA Beginner's Guide to
DelphiDate/Time routines - Delphi Programming
See More About:
By Category
;2001