#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
class hexo {
public:
hexo() = default;
static unsigned short hextobyte(std::string hexstr) { //one at a time. == 0x00 ~ 0xFF
int cnt = 0, byte = 0;
char ch;
for (int i = (int)hexstr.length() - 1; i >= 0; i--)
{
ch = hexstr[i];
if (ch >= '0' && ch <= '9')
byte += (ch - '0') * (int)std::pow(16, cnt++);
else if (ch >= 'A' && ch <= 'F')
byte += (ch - 'A' + 10) * (int)std::pow(16, cnt++);
else if (ch >= 'a' && ch <= 'f')
byte += (ch - 'a' + 10) * (int)std::pow(16, cnt++);
else
return -1;
}
return byte;
}
static std::vector<unsigned short> hexstrtobytes(std::string hexstr) {
std::vector<unsigned short> hexbytes;
int cnt = 0;
hexstr = hexstr.substr(2, hexstr.length() - 1);
for (int i = (int)hexstr.length() - 2; i >= -1; i = i - 2)
if (i == -1)
hexbytes.push_back(hextobyte(hexstr.substr(0, 1)));
else
hexbytes.push_back(hextobyte(hexstr.substr(i, 2)));
return hexbytes;
}
};
int main(int argc, char const* argv[]) {
if (argc == 4) {
/*
* argv[1] == file name to patch.
* argv[2] == Patch Address
* argv[3] == Patch Value [must be the multiply of 2]
*/
std::cout << "File Name: " << argv[1] << std::endl;
std::cout << "Patch Start Address: " << argv[2] << std::endl;
std::cout << "Patch Value: " << argv[3] << std::endl;
std::istringstream addr(argv[2]);
std::vector<unsigned short> hexbytes = hexo::hexstrtobytes(argv[3]);
std::fstream binaryfile(argv[1], std::ios::in | std::ios::out | std::ios::binary);
int patchaddr;
//convert patch address from text to hex number.
addr >> std::hex >> patchaddr;
size_t arrlen = hexbytes.size();
for (size_t i = 0; i < arrlen; i++) {
binaryfile.seekp(patchaddr + i);
binaryfile << char(hexbytes[i]);
}
binaryfile.close();
}
else {
std::cout << "filepatcher.exe filetopatch patchaddress patchvalue" << std::endl;
std::cout << "\nEx: " << std::endl;
std::cout << " filepatcher.exe at4re.exe 0x4325 0x56789654" << std::endl;
}
system("pause"); //Works on Windows only
return 0;
}
أو من هنا
https://pastebin.com/8uWAjv2F
كلمة السر: AT4RETEAM
من طلب العلا ... سهر الليالي