forked from stoneharry/RCEPatcher
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
78 lines (63 loc) · 2.3 KB
/
main.cpp
File metadata and controls
78 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include <fstream>
#include <string>
#include <filesystem>
const uint32_t PatchOffset = 0x2A7;
const uint8_t PatchValue = 0xC0;
bool IsPatchedExe(const std::string& filePath) {
std::ifstream stream(filePath, std::ios::binary);
if (!stream) {
return false;
}
stream.seekg(PatchOffset);
uint8_t value = 0;
stream.read(reinterpret_cast<char*>(&value), sizeof(value));
return value == PatchValue;
}
void PatchExe(const std::string& filePath, const std::string& newPath) {
std::ifstream src(filePath, std::ios::binary);
std::ofstream dst(newPath, std::ios::binary);
dst << src.rdbuf();
std::fstream stream(newPath, std::ios::in | std::ios::out | std::ios::binary);
stream.seekp(PatchOffset);
stream.write(reinterpret_cast<const char*>(&PatchValue), sizeof(PatchValue));
}
std::string GetNewPath(const std::string& filePath) {
std::filesystem::path path(filePath);
std::string fileName = path.stem().string();
std::string directory = path.parent_path().string();
std::string defaultSeperator = "";
std::string separator;
if (directory.empty())
separator = defaultSeperator;
else
separator = std::filesystem::path::preferred_separator;
return directory + separator + fileName + "_patched.exe";
}
int main(int argc, char* argv[]) {
if (argc == 1) {
std::cerr << "[ERROR] Input your WoW.exe file path to patch." << std::endl;
return 1;
}
std::string filePath = argv[1];
try {
if (!std::filesystem::exists(filePath)) {
std::cerr << "[ERROR] Unable to find file: " << filePath << std::endl;
return 1;
}
if (IsPatchedExe(filePath)) {
std::cout << "[COMPLETE] File is already patched: " << filePath << std::endl;
return 0;
}
std::string newPath = GetNewPath(filePath);
if (std::filesystem::exists(newPath)) {
std::cerr << "[ERROR] File already exists: " << newPath << std::endl;
return 1;
}
PatchExe(filePath, newPath);
std::cout << "[COMPLETE] Created patched executable: " << newPath << std::endl;
} catch (const std::exception& exception) {
std::cerr << "[ERROR] Unexpected: " << exception.what() << std::endl;
}
return 0;
}