Advertisement
hoangcuongflp

Exez21.cpp

Dec 22nd, 2014
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <cstdlib>
  2. #include <stdio.h>
  3. #include <iostream>
  4. #include <cstring>
  5. #include <windows.h>
  6. #include <string>
  7.  
  8. using namespace std;
  9.  
  10. bool Bind(char *args[5]);
  11.  
  12. const char *GetEnding(LPCSTR FileName)
  13. {
  14.     string tmp=FileName, ret;
  15.     int o=tmp.find_last_of(".");
  16.     for (int i=o;i<tmp.length();i++)
  17.     {
  18.         ret+=tmp[i];
  19.     }
  20.     return ret.c_str();
  21. }
  22.  
  23. int main(int argc, char *argv[])
  24. {
  25.     if ( argc!=5 ) //Zomg not any commands
  26.     {
  27.         cout << "Format your input as:nExez21.exe [file1.exe] [file2.exe] -o [output.exe]n[file1.exe]: sourcefile nr1n[file2.exe]: sourcefile nr2n-o: outputn[output.exe]: outputfile)";
  28.         return 0;
  29.     }
  30.     else
  31.     {
  32.         if (!Bind(argv))
  33.         {
  34.             cin.get();
  35.             return 0;
  36.         }
  37.     }
  38. }
  39.  
  40. bool Bind(char *args[5])
  41. {
  42.     if (strcmp(args[3], "-o")!=0)
  43.     {
  44.         cout << "Wrong type of inputn";
  45.         return false;
  46.     }
  47.     if ( ( strcmp(GetEnding(args[1]), ".exe")!=0 ) || ( strcmp(GetEnding(args[2]), ".exe")!=0 ) || ( strcmp(GetEnding(args[4]), ".exe")!=0 ) )
  48.     {
  49.         cout << "Error file endings must be .exen";
  50.         return false;
  51.     }
  52.     FILE *fp = fopen(args[1], "rb");
  53.     if (!fp) {cout << "Couldn't read from input file: " << args[1] << endl;return false;}
  54.    
  55.     fseek(fp, 0, SEEK_END);
  56.    
  57.     unsigned long size = ftell(fp);
  58.    
  59.     char *buffer = (char*)malloc(size);
  60.    
  61.     rewind(fp);
  62.     fread(buffer, size, 1, fp);
  63.     fclose(fp);
  64.    
  65.     fp = fopen(args[2], "rb");
  66.     if (!fp){cout << "Couldn't read from input file: " << args[2] << endl;return false;}
  67.    
  68.     fseek(fp, 0, SEEK_END);
  69.    
  70.     unsigned long size2 = ftell(fp);
  71.    
  72.     char *buffer2 = (char*)malloc(size2);
  73.    
  74.     rewind(fp);
  75.     fread(buffer2, size2, 1, fp);
  76.     fclose(fp);
  77.    
  78.     CopyFile("openall.exe", args[4], FALSE);
  79.    
  80.     fp = fopen(args[4], "ab+");
  81.     if (!fp){cout << "Couldn't write to output file: " << args[4] << endl;return false;}
  82.    
  83.     char *info = (char*)malloc(size+5);
  84.     info[0]='*';
  85.     info[1]='*';
  86.     info[2]='*';
  87.     info[3]='*';
  88.     info[4]='*';
  89.    
  90.     fwrite(info, strlen(info),1, fp);
  91.     fwrite(buffer, size, 1, fp);
  92.     fwrite(info, strlen(info), 1, fp);
  93.     fwrite(buffer2, size2, 1, fp);
  94.     fclose(fp);
  95.     free(info);
  96.    
  97.     return true;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement