Home » C SOURCE CODES

File Embedder Project in C

Submitted by Srikanth on Monday, 21 July 20086 Comments

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

Popularity: 1% [?]


  By using/following this site you agree to our Legal Disclaimer

Subscribe to GoHacking.Com


Enjoyed this article?
Subscribe to GoHacking.Com and get daily updates in your email for free

6 Comments »

  • emmet said:

    how to use this script

  • Srikanth (author) said:

    @ emmet

    Download the compiled module, run it.It asks for

    1. Embed a file 2. extract a file 3.exit

    Embed a file

    If you have to embed a file A in file B then for source file you have to specify the name of B and for target file, the name of A.

    The tool will automatically embed the FILE A into B and creates a Data.cfg file

    To extract

    Specify the source file name B (in which another file is embeded) and also Data.cfg file

    Specify any name for target file with the correct(desired) extension.

    The tool will extract the embeded file back to it’s original form…

  • Bonnie said:

    I am greatly impressed by your witticism in Computer Science and especially the way you make Computer virus coding an easy tasks for novices .I’m a budding and ambitious computer programmer in my first year 2nd semester and I hope that one day am also going to make major contributions to the world of computing .Continue doing the good work……..

  • scatmanrk said:

    is this like a binder??
    if i embed 2 EXE files, will both of them run when the user double clicks the file?
    can i embed an exe file within an mp3 file?? so that when a person runs the mp3 the exe file runs without the knowledge of the user??

  • Srikanth (author) said:

    @ scatmanrk

    No it’s not possible to make both the exe to run at a time. This program only joins two files and also can unjoin them.

  • Mars M said:

    Dear Sir,
    I want to learn C programming. Can you help me please…..

    Thank you
    Mars M

Leave your response!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.