How To Make Antivirus Using C++ Programming Language

Posted on Feb 6 2013 - 11:08pm by 0ffliner

How To Make Antivirus Using C++ ?

You may like to Read:

There are many tutorials on the internet teaching you how to write virus programs that could destroy the basic configurations of any Operating System. But here at CodeMink, we’ll tell you how to make AntiVirus using C++. Although, you can write the code in any programming language of your choice, but we’ll focus the concept in C++.

 Also See :How to Make Antivirus Using Java Programming Language


What’s the focus Point?

The main point behind searching any virus is identifying the code structure of any virus file.

Suppose, we’ve found this following virus in computer,

You may like to Read:
Virus File: How to Make Antivirus in C++

Virus File: How to Make Antivirus in C++

Now we’ll see the Binary code of this file.

Simply open this file in your favorite text editor. I advise you to use Notepad++ for the purpose.

You may like to Read:

Upon opening the file, you’ll see all unknown characters in file. What you have to do is just concentrate on characters which are identifiable (consider the image below)

Virus exe File opened in Notepad++

Virus exe File opened in Notepad++

In the 1st line,
1st character = M
2nd character = Z

In 2nd line,
9th character = P
10th character = E

In 9th line,
3rd character = (
4th character = %


Take at least 10-12 character samples from the file and write then in text file in the following format:

Virus Database

Virus Database


Now this file will act us our virus Database. We can simply update this file and supply to the user for a better protection.


Let the Scanning Begin

Now, suppose we’ve to scan any user specified folder. Let’s write code in C++ for the same.

For doing this, we need to:

  • STEP 1: Get a list of all the files present in that folder including sub directories too.
  • STEP 2: Scan them one by one using the character sample we’ve collected above. If the characters at positions specified above are matched with those in files, then it would be tagged as “Infected”.
  • STEP 3: Delete the virus file, in case we find them.


Its Coding Time Now:

[cpp]/*The program written below is an exclusive property of
You are not allowed to copy/reprint it in any social media like:-
books, internet, blogs, etc. without the permission of its author.
Author: Lavneet Sharma
Release Date(dd/mm/yyy): 7/2/2013 */

#include <dirent.h>
#include <string.h>
#include <fstream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream.h>

int scan_this(char *file_name)
char *pattern, *line_in_file;
char file_ch, ch;
int val, val2, flag;
ifstream fin3, fin4;; // incase the file is not accesible
if(!fin3) return 0;

else // file is accessible | 100% it is a file.
//Opening Virus Database File“db.txt”); // this is our character pattern file

if(!strcmpi(pattern,”End”))return -1;
else if(!strcmpi(pattern, “virus”))
if(flag) return 1;
else continue;
else if(!strcmpi(pattern,”LINE”))
fin4>>val; // got the line number

// skipping initial lines to reach the line number
for(int i=0;i<val-1;i++)
fin3.getline(line_in_file, 300);

fin4>>val; // got the character number
fin4>>file_ch; // got the character

//skipping initial character to reach the character

if(file_ch == ch) flag = 1; // matched.
else flag =0;
fin3.seekg(0); // set to start



void main()
char comm[300], dirpath[100], file_name[200];
char ask;
int response;
ifstream fin;

cout<<“Enter Directory you want to scan: “;

strcpy(comm, “dir “);
strcat(comm, “dirpath /b /s >tmp.$$$”);

fin.getline(file_name, 200);
response = scan_this(file_name);
if(response == 1)
cout<<“<–!! Caution.! A Virus has been Detected..!”;
cout<<“nPress Enter Key to Delete it.”;
ask= getch();
if(ask == 13)
remove(file_name); // delete the virus

cout<<“Scan Complete.!! Thank You for using our anti virus”;


Note: You need to create its Executable (.exe) of this program before using it anywhere. To create Executable, simply save your program in any name and then press F9 twice.

Code Explanation Summary

The code written above has 1 major function as listed below:


It executes the DOS command within the c++ program. The command executed in the program is, dir /b /s >temp.$$$
This, command, lists all the file present in current working directory including sub directories and saves them in temp.$$$ file

and the rest is File Handling.

The complete explanation of this code will be provided in my next post. So, be updated @CodeMink.

So, that’s all on How to make antivirus using c++. For any further doubt or query, please feel free to comment below using the comment Box.

About the Author

90 Comments so far. Feel free to join this conversation.

  1. Rahul pandey April 21, 2013 at 12:09 am - Reply

    Hiii sir i wants to create an antivirus using c++ language , so sir plz. talk me about it deeply on my email ([email protected])
    thanks sir
    i am waiting your mail

  2. akash srivastava May 4, 2013 at 1:06 am - Reply

    hello sir, i want to learn to create an anti virus by using c++ programming. kindly suggest me, from where should i start from..

  3. Atiqur Rahman May 13, 2013 at 6:03 pm - Reply

    Dear sir
    I would like to learn how to development antivirus software
    please help me .which software more efficiency to develop antivirus software .kindly suggest me .my email id :[email protected]
    thanks all

  4. rougerdeluffy June 4, 2013 at 9:21 pm - Reply

    c++ memang yang terbaik

  5. patrickgayo June 28, 2013 at 7:21 pm - Reply

    hey mr. Lavneet please help me to make anti-virus . we need it for our thesis . please

  6. p chinna kondaiah July 4, 2013 at 2:00 am - Reply

    hai! good explanation.

  7. md mohsin July 17, 2013 at 11:05 pm - Reply

    want to learn more abt virus n

  8. Daniel KATUNGA July 22, 2013 at 4:40 pm - Reply

    i want to know more about antivirus

  9. Gab July 27, 2013 at 6:18 pm - Reply

    hi sir! i really need help to make a antivirus program for my self-use computer as i think purchasing for them is a waste of money as i have none.. please help!

  10. XXLinibXX July 31, 2013 at 8:00 am - Reply

    Sir I need to develop an antivirus in c++ please send me a complete idea and process to do so.
    Will be waiting for response .

  11. XXLinibXX July 31, 2013 at 8:01 am - Reply

    Sir I need to develop an antivirus in c++ please send me a complete idea and process to do so.
    Will be waiting for response .
    Email:[email protected]
    [email protected]

  12. HSW August 6, 2013 at 2:48 am - Reply

    Hello, hope all is well. Can you help me with a problem I have.
    I need to create a little scanner in C++ Visual studio that will
    1. Scan all files in a directory and subdirectories
    2. For those files, count how many were produced by the generator(s), and how many were not. If I give you more than 1 generator, you should say which generator it was made by.
    3. You will be graded on handling of errors, false positive rate and false negative rate, as well as code quality.
    Need help badly…..Thanks
    [email protected]

  13. shantanu August 13, 2013 at 2:51 pm - Reply

    sir please help me out in developing a anti virus for my project

  14. M-gumma August 16, 2013 at 5:37 pm - Reply

    Mr cipgerux,
    As I intend to create antivirus software in VC++, Please help and advise me in this small application..

    Thank you in advance

  15. nilesh August 17, 2013 at 3:53 pm - Reply

    i want to develop the antivirus in c and .net,so please guide me for which type of knowledge i want to know and which type of articles have to read. please mail me on “[email protected]

  16. Neeru September 16, 2013 at 5:15 pm - Reply

    hello sir thanks for ur guidance sir i want to really learn that how can i make an anti virus /virus please sir
    reply me at “[email protected]
    i am waiting you…
    thanks a lot

  17. aryan rab September 18, 2013 at 3:41 pm - Reply

    i want to create a new antivirus but i don’t have any idea… how it is create . i need your help . first send me detail of anti virus programming and then i’ll learn . i know your guideline will be very good .so pleasssssssssss help me sir send me response in my email id : [email protected] ….i will remains great full forever to your help………..thanxxxxxxxxxxxxxx

  18. emman September 18, 2013 at 6:00 pm - Reply

    Sir can you please help me to create an antivirus … because this is serve as my case study report …

  19. Kudus October 16, 2013 at 4:44 pm - Reply

    Hello Sir, I want to know how to write any program using cplusplus programing language. I really need your sugestion and where to start from?. You can reach me through my email, thank you. Looking forward to your reply.

  20. Monster X April 30, 2014 at 1:39 pm - Reply

    Thank you sir for this post…
    I want to know the meaning of this coding.

  21. hekmat May 27, 2014 at 5:59 pm - Reply

    Is this running in visual studio

  22. T C July 12, 2014 at 7:51 am - Reply

    Does not work on my computer. Says:
    error: fstream.h: No such file or directory
    and more gibberish like:
    error: iostream.h: No such file or directory
    By the way, i am using Code::blocks
    special build C++ for Dummies

    • chaotic July 15, 2014 at 11:13 pm - Reply

      Sounds like you are missing those libraries, or perhaps your compiler just doesn’t know where they are.

      An ugly, but general solution should be putting them in the same directory where your source is, and write them in quoted form- for example:

      #include “fstream.h”

    • VestedMadScientist July 20, 2014 at 6:23 pm - Reply

      #include is actually depreciated. Use #include instead. Same goes for all the other headers.

  23. Student August 13, 2014 at 1:06 pm - Reply

    What are the advantages of using the system command to list files in folder instead of using the file listing provided by C++? Thanks

  24. Ahmad salman August 10, 2015 at 5:30 am - Reply

    Hello sir i have to make antivirus on my own name and please help me out how to make any antivirus please contact me this is my email ([email protected]) please sir need it please

  25. AAKASH JAIN August 17, 2015 at 11:31 pm - Reply

    I want to be make anti virus in c++ or c
    plzz give me all code of that

  26. Krishna August 21, 2015 at 3:58 pm - Reply

    Hlw sir, i’m getting confuse from above explanation plz advice me in detail help me to made my own antiviruses software

  27. Popo August 28, 2015 at 8:42 pm - Reply

    Please send me the details , how does an antivirus work…..

  28. awinash September 3, 2015 at 12:03 pm - Reply

    sir , i copy this all command and make my programm executable but it shows error …
    it says to me enter the directory.. when i enter c directory it shows bad command but when i enterd d drive or any other it shows nothing… only currsor blinking.

  29. jay bhatt September 8, 2015 at 7:12 pm - Reply

    Sir can we call one file into 2ed file?

  30. Aftab HUssain September 17, 2015 at 11:01 pm - Reply

    hello sir, i want to learn to create an anti virus by using c++ programming.please……

  31. Pradyuman Gupta September 30, 2015 at 4:37 pm - Reply

    I want to learn make an antivirus.

  32. vikas thakur October 16, 2015 at 12:27 pm - Reply

    sir i doing BCA and i want more information about computer sir our collage not provide enough facelity so plz talk me on my gmail id
    sir i wating for u

  33. Leka Maarie October 19, 2015 at 10:16 am - Reply

    can you email me and help me more about creating my own antivirus software, please… email me and we talk about it more .. thank you..!

  34. Ajay Sirsat October 21, 2015 at 10:07 pm - Reply

    sir i want to create full antivirus application can it is possible plz help

  35. Bittu kumar October 31, 2015 at 8:09 pm - Reply

    Sir plz advice me to create an antivirus software by using c++ programe so plz talk me about it to my email

  36. knowledge November 9, 2015 at 7:29 pm - Reply

    I want to learn how to make an antivirus using dev or code blocks compilers

  37. lea may December 29, 2015 at 1:08 pm - Reply

    hi sir i want to create a strong antivirus….may i beg u to help me to do it…

    thank you

  38. dessalegn kassaw February 5, 2016 at 9:05 pm - Reply

    hi sir i started antivirus software i need your help please help me?

  39. phenil February 6, 2016 at 3:34 pm - Reply

    Thanks sir

  40. Joshua February 8, 2016 at 11:00 pm - Reply

    Sir, i really want to know about C++ programming language, you can reach me through my email. Thanks

  41. NARENDRAPAL RATNA February 9, 2016 at 1:47 am - Reply

    I wanna develop antivirus by using c++.please suggest me….thanking you

  42. Benseidseid March 11, 2016 at 10:30 pm - Reply

    Thanks for The valuable information…

  43. me May 19, 2016 at 7:10 pm - Reply

    Thank you!

  44. wafula newton May 27, 2016 at 6:55 pm - Reply

    i want to know how to make un antivirus

  45. kundan May 28, 2016 at 7:18 pm - Reply

    i want to learn more programe making

  46. MATEUS NUNES DOS SANTOS June 2, 2016 at 6:11 pm - Reply

    Can some one help me ?
    the code do not work for me

  47. bharat gautam June 11, 2016 at 12:32 pm - Reply

    Hello! Sir
    i wanna learn how to make software
    Plz tell me Sir

  48. Arun June 13, 2016 at 5:36 pm - Reply

    I am a student of C programming !!

  49. Muhammad Zubair July 25, 2016 at 4:26 pm - Reply

    I am a student of computer software engineering sir i need your help on anti virus

  50. Segun August 1, 2016 at 3:54 am - Reply

    So educating!!!

  51. Rajiv kumar August 2, 2016 at 11:57 am - Reply

    I like you way to make antivirus respond on my email with your innovative ideas..

  52. manas August 7, 2016 at 6:21 pm - Reply

    you should give location and name of file to prevent data loss
    instead of deleting ,its nice :)

  53. manas August 7, 2016 at 6:23 pm - Reply

    And there is no dirent.h in my dosbox

  54. Hajar August 17, 2016 at 5:13 pm - Reply

    I am a computer science student sir iReally appreciate your doing I just read how to create antivirus using c and I will surely try it if I found something difficult I will talk to you thank you sir

  55. Arthur September 21, 2016 at 4:42 pm - Reply

    sir hullo.
    I request that u teach me more about creation of an antivirus and a virus…

  56. Arthur September 21, 2016 at 4:43 pm - Reply

    sir hullo.
    I request that u teach me more about creation of an antivirus and a virus…
    connect me more via my email
    Arthur hag gain

  57. sohail September 24, 2016 at 10:53 pm - Reply

    Sir give ideas developed c** i want special thought very faster to faster to unlimite programs axecute

  58. Joy October 2, 2016 at 8:15 pm - Reply

    Pls sir help me on how to develop antivirus software using c++

  59. Jassir October 5, 2016 at 8:00 pm - Reply

    I want the download form of this source code

  60. elvis October 23, 2016 at 5:09 am - Reply

    I wanted to know how to make antivirus in my phone using c++ by notepad +++ pliz help mi with steps

Leave A Response