Skip to content

Commit

Permalink
Use signature instead of raw memcmp
Browse files Browse the repository at this point in the history
  • Loading branch information
maximegmd committed Dec 20, 2020
1 parent f39476a commit 50c63a2
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/smt_amd_patch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,24 @@
#include <filesystem>

#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");
Expand Down

0 comments on commit 50c63a2

Please sign in to comment.