我只是想:
这是我尝试的但看起来它不起作用
#include <fstream>
#include <iterator>
#include <algorithm>
void FindAndReplace(CHAR Before[], CHAR After[], int Size)
{
typedef std::istream_iterator<unsigned char> input_iter_t;
typedef std::ostream_iterator<unsigned char> output_iter_t;
std::fstream f("C:\\myfile.exe", std::ios::binary | std::ios::in | std::ios::out);
if (search(input_iter_t(f), input_iter_t(), Before, Before + Size) != input_iter_t()) {
f.seekp(-Size, std::ios::cur);
f.write(After, Size);
}
}
并以这种方式调用
CHAR Before[] = {0x2D,0x43,0x89,0x5D};
CHAR After[] = {0x00,0x00,0x00,0x00};
FindAndReplace(Before,After,4);
你知道其他任何办法吗?或者我做错了什么?