我正在学习如何修补功能,并且我有以下代码在 32 位程序中运行良好。但是,我试图让它在 64 位程序中也能工作,但它只是崩溃了。
#ifndef __x86_64
std::uint8_t Store[8] = {0};
#else
std::uint8_t Store[15] = {0};
#endif
void Patch(std::uint8_t* OriginalAddress, std::uint8_t* ReplacementAddress)
{
#ifndef __x86_64
const static std::uint8_t jmp[] = {0xb8, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe0}; /** movl $0x0, %eax ;;; jmp *%eax **/
#else
const static std::uint8_t jmp[] = {0x48, 0xb8, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xe0, 0x90, 0x90}; /** movq $0x0, %rax ;;; jmp *%rax **/
#endif
DWORD dwProtect = 0;
const static std::int8_t jmp_size = sizeof(jmp) / sizeof(std::uint8_t);
VirtualProtect(OriginalAddress, jmp_size, PAGE_EXECUTE_READWRITE, &dwProtect);
memcpy(Store, OriginalAddress, jmp_size);
memcpy(OriginalAddress, jmp, jmp_size);
memcpy(OriginalAddress + 1, &ReplacementAddress, sizeof(void*));
VirtualProtect(OriginalAddress, jmp_size, dwProtect, &dwProtect);
}
任何想法代码有什么问题?