Advertisement
Guest User

BINBCHrename

a guest
Dec 8th, 2015
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.97 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <cstring>
  5. using namespace std;
  6.  
  7.     //   compiled version and source sans comments can be found at:
  8.     //         https://dl.dropboxusercontent.com/u/40407085/Stuff/binbchren.zip
  9.     //   put this in the directory of the BINs and run it
  10.     // make sure to pipe the output somewhere so you can track what gets renamed to what
  11.  
  12. unsigned long unlend(char bytes[]) {            // convert little-endian to decimal
  13.     unsigned long pos = 0;
  14.     for (int i=3; i>=0; i--) {
  15.         pos = pos*256 + (unsigned char)bytes[i];
  16.     }
  17.     return pos;
  18. }
  19.  
  20. bool isLowcase(string str) {                // actually checks if there's no uppercase
  21.     int len = str.length();
  22.     bool ret = true;
  23.     for (int i=0; i<len; i++) {
  24.         ret = ret && (tolower(str[i]) == str[i]);
  25.     }
  26.     return ret;
  27. }
  28.  
  29. int main() {
  30.     unsigned long beg,end,len,cpos;
  31.     string nname;
  32.     char* mcode;
  33.     char* pos;
  34.     char* buffer;
  35.     char* name;
  36.     char* pch;
  37.     bool namefound;
  38.     mcode = new char [3];
  39.     pos = new char [4];
  40.     for (int fcount=0; fcount<=25601; fcount++) {
  41.         ifstream infile (to_string(fcount)+".bin", ios::binary);
  42.         if (infile.is_open()){
  43.             namefound = false;
  44.             infile.read(mcode, 3);
  45.             cout << fcount << ".bin\n";
  46.             if (strcmp(mcode,"BCH") == 0) {
  47.                 infile.seekg(0xC);
  48.                 infile.read(pos,4);
  49.                 beg = unlend(pos);
  50.                 infile.read(pos,4);
  51.                 end = unlend(pos);
  52.                 if (end > beg) {
  53.                     len = end-beg;
  54.                     infile.seekg(beg);
  55.                     delete[] buffer;
  56.                     buffer = new char [len];
  57.                     cpos = infile.tellg();
  58.                     infile.read(buffer,len);
  59.                     cpos += strlen(buffer)+1;
  60.                     infile.seekg(cpos);
  61.                     while (cpos < end) {
  62.                         if (strchr(buffer,'@') != NULL) {
  63.                             if (isLowcase(string(buffer))) {
  64.                                 cout << " " << buffer << "\n";  // this part separates file name from
  65.                                 strtok(buffer,"@");     // string containing @s
  66.                                 name = strtok(NULL,"@");
  67.                                 nname = string(name);
  68.                                 namefound = true;
  69.                             }
  70.                         }
  71.                         infile.read(buffer,len);
  72.                         cpos += strlen(buffer)+1;
  73.                         infile.seekg(cpos);
  74.                     }
  75.                 }
  76.             }
  77.             infile.close();
  78.             if (namefound) {
  79.                 string fn = to_string(fcount)+".bin";
  80.                 string ofn = nname+".bch";
  81.                 cout << "  " << fn.c_str() << " -> " << ofn.c_str() << endl;
  82.                 rename(fn.c_str(), ofn.c_str());
  83.             }
  84.         }
  85.     }
  86.     return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement