From 50c63a275a8d3dc37f3e07e72bedcec92b5ada7d Mon Sep 17 00:00:00 2001 From: yamashi Date: Sun, 20 Dec 2020 13:22:47 +0100 Subject: [PATCH] Use signature instead of raw memcmp --- src/smt_amd_patch.cpp | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/smt_amd_patch.cpp b/src/smt_amd_patch.cpp index 3bb0dbdc..ebaa8c9e 100644 --- a/src/smt_amd_patch.cpp +++ b/src/smt_amd_patch.cpp @@ -7,31 +7,24 @@ #include #include "Image.h" +#include "Pattern.h" void SmtAmdPatch(Image* apImage) { - const uint8_t payload[] = { + auto* pMemoryItor = FindSignature({ 0x75, 0xCC, 0x33, 0xC9, 0xB8, 0x01, 0x00, 0x00, 0x00, 0x0F, 0xA2, 0x8B, 0xC8, 0xC1, 0xF9, 0x08 - }; + }); - auto* pMemoryItor = apImage->pTextStart; - auto* pEnd = apImage->pTextEnd; - - while(pMemoryItor + std::size(payload) < pEnd) + if(pMemoryItor) { - if(memcmp(pMemoryItor, payload, std::size(payload)) == 0) - { - DWORD oldProtect = 0; - VirtualProtect(pMemoryItor, 8, PAGE_EXECUTE_WRITECOPY, &oldProtect); - *pMemoryItor = 0xEB; - VirtualProtect(pMemoryItor, 8, oldProtect, nullptr); - - spdlog::info("\tAMD SMT Patch: success"); + DWORD oldProtect = 0; + VirtualProtect(pMemoryItor, 8, PAGE_EXECUTE_WRITECOPY, &oldProtect); + *pMemoryItor = 0xEB; + VirtualProtect(pMemoryItor, 8, oldProtect, nullptr); - return; - } + spdlog::info("\tAMD SMT Patch: success"); - pMemoryItor++; + return; } spdlog::warn("\tAMD SMT Patch: failed");