Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- using namespace std;
- // compiled version and source sans comments can be found at:
- // https://dl.dropboxusercontent.com/u/40407085/Stuff/binbchren.zip
- // put this in the directory of the BINs and run it
- // make sure to pipe the output somewhere so you can track what gets renamed to what
- unsigned long unlend(char bytes[]) { // convert little-endian to decimal
- unsigned long pos = 0;
- for (int i=3; i>=0; i--) {
- pos = pos*256 + (unsigned char)bytes[i];
- }
- return pos;
- }
- bool isLowcase(string str) { // actually checks if there's no uppercase
- int len = str.length();
- bool ret = true;
- for (int i=0; i<len; i++) {
- ret = ret && (tolower(str[i]) == str[i]);
- }
- return ret;
- }
- int main() {
- unsigned long beg,end,len,cpos;
- string nname;
- char* mcode;
- char* pos;
- char* buffer;
- char* name;
- char* pch;
- bool namefound;
- mcode = new char [3];
- pos = new char [4];
- for (int fcount=0; fcount<=25601; fcount++) {
- ifstream infile (to_string(fcount)+".bin", ios::binary);
- if (infile.is_open()){
- namefound = false;
- infile.read(mcode, 3);
- cout << fcount << ".bin\n";
- if (strcmp(mcode,"BCH") == 0) {
- infile.seekg(0xC);
- infile.read(pos,4);
- beg = unlend(pos);
- infile.read(pos,4);
- end = unlend(pos);
- if (end > beg) {
- len = end-beg;
- infile.seekg(beg);
- delete[] buffer;
- buffer = new char [len];
- cpos = infile.tellg();
- infile.read(buffer,len);
- cpos += strlen(buffer)+1;
- infile.seekg(cpos);
- while (cpos < end) {
- if (strchr(buffer,'@') != NULL) {
- if (isLowcase(string(buffer))) {
- cout << " " << buffer << "\n"; // this part separates file name from
- strtok(buffer,"@"); // string containing @s
- name = strtok(NULL,"@");
- nname = string(name);
- namefound = true;
- }
- }
- infile.read(buffer,len);
- cpos += strlen(buffer)+1;
- infile.seekg(cpos);
- }
- }
- }
- infile.close();
- if (namefound) {
- string fn = to_string(fcount)+".bin";
- string ofn = nname+".bch";
- cout << " " << fn.c_str() << " -> " << ofn.c_str() << endl;
- rename(fn.c_str(), ofn.c_str());
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement