这是一个将函数复制到堆上,将其设置为可执行文件并调用它的程序。
#include <iostream>
#include <iomanip>
#include <csignal>
#include <Windows.h>
using std::cout;
#define RET 0xC3
void printBytes(void* start, uintptr_t numBytes) {
std::ios_base::fmtflags savedFlags(cout.flags());
cout << std::hex << std::uppercase << std::setfill('0');
bool lineComplete = false;
for (unsigned int byte = 0; byte < numBytes; byte++) {
lineComplete = byte % 4 == 3;
cout << std::setw(2)
<< (int)*((uint8_t*)start + byte)
<< (lineComplete ? '\n' : ' ');
}
cout << (lineComplete ? "\n" : "\n\n");
cout.flags(savedFlags);
}
uint8_t* findByte(void* start, uint8_t targetByte) …Run Code Online (Sandbox Code Playgroud)