Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Native CrossMap Patcher by Mike Rohsoft */
- /* Paste in folder Crossmap.txt with new data */
- #include "stdafx.h"
- #include <string>
- #include <algorithm>
- #include <vector>
- #include <sstream>
- #include <fstream>
- #include <iostream>
- #include <map>
- #include <regex>
- #include <inttypes.h>
- #include <Windows.h>
- using namespace std;
- enum FILEMODE
- {
- NEW_CROSS_MAP = 0,
- CPP_CROSS_MAP,
- //NATIVES_H
- };
- static regex new_cross_map_regexp = regex("\\{\\s*0x0*([1-9a-fA-F][0-9a-fA-F]+)\\s*,\\s*0x0*([1-9a-fA-F][0-9a-fA-F]+)\\s*\\},");
- static regex cpp_cross_map_regexp = regex("\\s*0x0*([1-9a-fA-F][0-9a-fA-F]+)\\s*,\\s*0x0*([1-9a-fA-F][0-9a-fA-F]+)\\s*,");
- //static regex natives_h_map_regexp = regex("^\\s*static\\s*[a-zA-Z0-9\\*]+\\s*([A-Z0-9_-x]+)\\(.*?(0x[0-9a-fA-F]+).*$");
- static vector<string> crossMap;
- map<string, string> newkeys;
- map<string, string> getMap(FILEMODE mode, string fileName)
- {
- map<string, string> ret;
- regex e;
- switch (mode)
- {
- case NEW_CROSS_MAP: e = new_cross_map_regexp; break;
- case CPP_CROSS_MAP: e = cpp_cross_map_regexp; break;
- //case NATIVES_H: e = natives_h_map_regexp; break;
- default: cout << "Error: Unknown Filemode" << endl; exit(1337);
- }
- ifstream infile(fileName);
- if (infile.good())
- {
- string line;
- string key = "0x";
- string value = "0x";
- cmatch cm;
- int i = 0;
- while (getline(infile, line))
- {
- if (mode == CPP_CROSS_MAP)
- crossMap.push_back(line);
- if (regex_match(&line[0], cm, e, regex_constants::match_default))
- {
- if (mode == NEW_CROSS_MAP)
- {
- key += cm[1];
- value += cm[2];
- }
- else
- {
- key += cm[2];
- value += cm[1];
- }
- transform(key.begin(), key.end(), key.begin(), ::tolower);
- transform(value.begin(), value.end(), value.begin(), ::tolower);
- if (ret.find(key) != ret.end())
- {
- newkeys[value] = value;
- }
- else
- ret[key] = value;
- key = "0x";
- value = "0x";
- i++;
- }
- }
- printf("found %d pairs\n", i);
- infile.close();
- }
- else //if (mode != NATIVES_H)
- {
- cout << "Error: Map File not found: " << fileName << endl;
- exit(1337);
- }
- return ret;
- }
- string getCurrentPath()
- {
- char buffer[MAX_PATH];
- GetModuleFileNameA(NULL, &buffer[0], MAX_PATH);
- string b = string(&buffer[0]);
- string::size_type pos = b.find_last_of("\\/");
- return b.substr(0, pos) + "\\";
- }
- const string ALEXANDER_BLADES_PASTBIN_POST_FILE = "crossmap.txt";
- const string CODE_CROSSMAP = "CrossMapping.cpp";
- int main()
- {
- cout << "open file: " << "crossmap.txt" << endl;
- map<string, string> updateMap = getMap(NEW_CROSS_MAP, getCurrentPath() + ALEXANDER_BLADES_PASTBIN_POST_FILE);
- cout << "open file: " << "CrossMapping.cpp" << endl;
- map<string, string> currentMap = getMap(CPP_CROSS_MAP, getCurrentPath() + CODE_CROSSMAP);
- //map<string, string> nativeMap = getMap(NATIVES_H, getCurrentPath() + "natives.h");
- map<string, string> newMap;
- int patched = 0;
- cout << "Comparing ... ";
- for (map<string, string>::iterator it = updateMap.begin(); it != updateMap.end(); ++it)
- {
- string key = it->first;
- string value = it->second;
- if (currentMap.find(key) != currentMap.end())
- {
- patched++;
- string basekey = currentMap[key];
- newMap[basekey] = value;
- }
- }
- cout << patched << " Natives can be patched..." << endl;
- cmatch cm;
- ofstream out("CrossMapping_new.cpp");
- patched = 0;
- for (int i = 0, l = crossMap.size(); i < l; i++)
- {
- if (regex_match(&crossMap[i][0], cm, cpp_cross_map_regexp, regex_constants::match_default))
- {
- string key = "0x";
- key += cm[1];
- string found = cm[2];
- size_t pos = crossMap[i].find(key) + key.size();
- string value = newMap[key];
- if (value.size() > 0)
- {
- crossMap[i].replace(pos + 2, found.size() + 2, value);
- patched++;
- }
- }
- out << crossMap[i] << endl;
- }
- out.close();
- printf("Done ... patched %d Natives\n", patched);
- string bla;
- getline(cin, bla);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement