Showing posts with label c. Show all posts
C Program to Print its Own Source Code
Here’s the program:
#include<stdio.h>
char *program=”#include<stdio.h>%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}
char *program=”#include<stdio.h>%cchar *program=%c%s%c;%cvoid main()%c{%cprintf(program,10,34,program,34,10, 10,10,10);%c}”;
void main()
{
printf(program,10,34,program,34,10,10,10,10);
}
C Program Without a Main Function
Have you ever wondered how to write a C program without a main function? Can a C program execute with a main function? Is it possible to do that?
Well, the answer is YES! There can be a C program without a main function. Here is the source code of the program without a main function:
#include<stdio.h>
#include<conio.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 “);
getch();
return 0;
}
save this as test.c
#include<conio.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 “);
getch();
return 0;
}
save this as test.c
The above program runs perfectly fine
even without a main function. But how? What’s the logic behind it? How
can we have a C program working without a main function. Read on to find
out the answer…
Here, we are using a preprocessor directive called #define
with arguments to give an impression that the program runs without the
main function. However, in reality it runs with a hidden main function
in it.
NOTE: A Preprocessor is program which processes the source code before compilation.
The ‘##‘ operator is
called the token pasting or token merging operator. That is, we can
merge two or more characters with it. Now, 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 and t into msut). The logic is, when you pass (s,t,u,m,p,e,d) as argument it merges the 4th, 1st, 3rd and 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 and the 2nd characters must be merged. In the
argument (a,n,i,m,a,t,e) 4th, 1st, 3rd and the 2nd characters are ‘m’,
‘a’, ‘i’ and ‘n’.
So the third line “int begin” is
replaced by “int main” by the preprocessor before the program is passed
on to the compiler. That’s it.
The bottom line is that, there can never
exist a C program without a main function. Here, we are just playing a
gimmick that makes us believe that the program runs without the main,
but there actually 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.
A Virus Program to Restart the Computer with c
For this, the virus needs to be executed
only once and from then on, it will carry out rest of the operation on
its own. I have programmed this virus using the C language. If you are
familiar with the C language then it is too easy to
understand the logic behind the coding. The code is not posted here in
this article, but you can download it from the link below.
Compiling the source code into an executable module:
-
Download the Source Code Here.
-
UnRar the file and you should see the source code: Sysres.C
Testing and removing the virus from your PC:
You can compile and test this virus on your own PC without any fear. To test, just double-click the sysres.exe
file and restart the system manually. From now on, every time the PC is
booted and the desktop is loaded, your PC will restart automatically
again and again.
It will not do any harm apart from
automatically restarting your system. After testing it, you can remove
the virus by following the below mentioned steps:
-
Reboot your computer in the safe mode.
-
Go to:(%systemroot% can be C,D,E or F)%systemroot%\Windows\System
-
You will find a file by name sysres.exe, delete it.
-
Type regedit in run. You will go to the registry editor. Here navigate to:HKEY_CURRENT_USER\Software\Microsoft\Windows\ CurrentVersion\RunThere, on the right site you will see an entry by name “sres“. Delete this entry. That’s it. You have now removed this virus successfully.
Logic Behind the working of this virus program:
If I do not explain the logic(Algorithm) behind the working of the virus program, I think this post would become an incomplete one. So I’ll explain the logic in a simplified manner without getting much into the technical aspects of the program. If you have further doubts, you can pass your comments.
LOGIC:
-
First the virus will find the Root partition (Partition on which Windows is installed).
-
Next, it will determine whether or not the virus file (sysres.exe) is already copied into %systemroot%\Windows\System.
-
If not it will just place a copy of itself into %systemroot%\Windows\System and makes a registry entry to put this virus file into the Windows startup.
-
Or else if the virus is already found in the %systemroot%\Windows\System directory (folder), then it just gives a command to restart the computer.
This process is repeated every time the PC is restarted.
NOTE: The system will not be restarted as soon as you double click the Sysres.exe file.The restarting process will occur from the next boot of the system.
How to change the icon of the executable module (This step is optional):
After you compile, the sysres.exe file that you get will have a default icon.
If you send this file to your friends they may not execute it since it
has a default ICON. So it is possible to change the ICON of this Sysres.exe file into any other ICON that is more trusted and looks attractive.
For example, you can change the icon into Norton antivirus ICON itself so that the people seeing this file believes that it is Norton antivirus. Or you can change its ICON into the ICON of any popular or trusted programs so that people will definitely click on it.
How to Compile C Programs
Here is a step-by-step procedure to install Borland C++ compiler 5.5 on your PC and compile the C programs.
How to Install Borland C++ compiler?
Follow the below steps to install Borland C++ compiler 5.5 on your PC:
-
Download Borland C++ compiler 5.5 (for Windows platform) from the following link:
-
After you download, run the file C++5.51.exe. The default installation path would be:C:\Borland\BCC55
How to configure Borland C++ compiler?
Here is a step-by-step instruction on how to configure the compiler:
-
After you install Borland C++ compier, create two new Text Documents.
-
Open the first New Text Document.txt file and add the following two lines into it :-I”c:\Borland\Bcc55\include”-L”c:\Borland\Bcc55\lib”Save changes and close the file. Now rename the file from New Text Document.txt to bcc32.cfg.
-
Open the second New Text Document (2).txt file and add the following line into it:-L”c:\Borland\Bcc55\lib”Save changes and close the file. Rename the file from New Text Document (2).txt to ilink32.cfg.
-
Now copy the two files bcc32.cfg and ilink32.cfg, navigate to C:\Borland\BCC55\Bin and paste them.
How to Compile the C Source Code (.C files)?
Here is a detailed instruction on how to compile C source codes:
-
You need to place the .C (example.c) file to be compiled in the following location:
-
Now go to the command prompt (Start->Run->type cmd->Enter)
-
Make the following path as the present working directory (use the CD command):
-
To compile the file (example.c) use the following command:bcc32 example.c
-
Now if there exists no error in the source code, you’ll get a compiled executable module (example.exe) in the same location (C:\Borland\BCC55\Bin).
-
Now you have successfully compiled the source code into an executable file(.exe file).
C:\Borland\BCC55\Bin
C:\Borland\BCC55\Bin
NOTE: The above tutorial assumes that you’ve installed the compiler onto the C: drive (by default).
C4droid: Download C/C++ Compiler for Android Platform for Free
In this post i am giving you link to download C4droid, a free c/c++ compiler for android platform. On Google Play Store it is available for $2.99 but I have found it for free at http://appxg.com.
It is very easy to understand and use. By default you will be able to write and run c programs. But for c++ programs you need to download the required plugin from play store. At first when you will open the app it will extract and will ask you you to install the gcc plugin, so install it from google play store. Now download it, install it and share your queries and experience.
It is very easy to understand and use. By default you will be able to write and run c programs. But for c++ programs you need to download the required plugin from play store. At first when you will open the app it will extract and will ask you you to install the gcc plugin, so install it from google play store. Now download it, install it and share your queries and experience.






