in the end, any program is just a file stored in some file system. compilers, linkers etc. are programs that take one or more files as input and give out file(s) as output. you can modify these files like you modify any other files.
#include <iostream>
#include <cstdlib>
#include <string>
#include <fstream>
#include <iterator>
#include <vector>
int main( int argc, char** argv )
{
std::system( "/usr/bin/g++ --version" ) ;
std::string original = "This is free software; see the source "
"for copying conditions. There is NO" ;
std::string modified( original.rbegin(), original.rend() ) ;
std::vector<char> bytes ;
{
std::ifstream file( "/usr/bin/g++", std::ios::binary ) ;
file >> std::noskipws ;
std::istream_iterator<char> begin(file), end ;
bytes.assign( begin, end ) ;
}
std::vector<char>::iterator found =
std::search( bytes.begin(), bytes.end(),
original.begin(), original.end() ) ;
if( found != bytes.end() )
{
std::copy( modified.begin(), modified.end(), found ) ;
{
std::ofstream file( "/tmp/g++" ) ;
std::copy( bytes.begin(), bytes.end(),
std::ostream_iterator<char>(file) ) ;
}
std::system( "/bin/chmod +x /tmp/g++ && /tmp/g++ --version" ) ;
}
}
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287