Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Reply
 
LinkBack Thread Tools Display Modes
Old 08-02-2011, 08:50 PM   #1 (permalink)
Right Off the Assembly Line
 
Join Date: Feb 2011
Posts: 1
Default c++ program to alter bytes of an image file


hey guys,
i was trying to write a c++ program to alter every 4th byte of an image file....
i want to replace every 4th byte in the file with a 7....
but the program doesnt seem to be working...can someone help me out with it....

this what i wrote:

#include<conio.h>
#include<dirent.h>
#include<stdio.h>
#include<fstream.h>

void main()
{

DIR *dir; int c=-1; char buf[10];
char files[1000][1000];
struct dirent *ent;
dir = opendir ("d:\\test");
if (dir!= NULL) {
while ((ent = readdir (dir)) != NULL)
{
printf ("%s\n", ent->d_name);
strcpy(files[++c],ent->d_name);


}// retrieves names of files in the directory and puts them in the files array

for(int i=2;i<=c;i++)
{ fstream file(files[i], ios::in|ios::binary|ios:ut);

while(file.eof()!=-1)
{
file.read(buf,sizeof(buf));
cout<<buf<<"\n";
for(int j=0;i<10;i++)
{ buf[j]=77777;i=i+2;
}
file.seekg(-10,ios::cur);

file.write(buf,sizeof(buf)); cout<<"\n"<<"written";
}
file.close();
}



closedir (dir);
} else {
/* could not open directory */
perror ("");
//return EXIT_FAILURE;
}
getch();
}

Last edited by zorrotech; 09-02-2011 at 12:03 AM.
zorrotech is offline   Reply With Quote
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 19-02-2011, 10:49 AM   #2 (permalink)
gkbhat.blogspot.com
 
Join Date: Apr 2008
Location: Mangalore/Bangalore
Posts: 103
Default Re: c++ program to alter bytes of an image file

Each image file format has its own headers you need to take care of them
__________________
blogging at http://gkbhat.blogspot.com
gk2k is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


 
Latest Threads
- by Charan
- by Charan

Advertisement




All times are GMT +5.5. The time now is 03:25 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2