DWORD FindPattern(DWORD base, DWORD size, char *pattern, char *mask)
{
// Get length for our mask, this will allow us to loop through our array
DWORD patternLength = (DWORD)strlen(mask);
for (DWORD i = 0; i < size - patternLength; i++)
{
bool found = true;
for (DWORD j = 0; j < patternLength; j++)
{
// If we have a ? in our mask then we have true by default,
// or if the bytes match then we keep searching until finding it or not
found &= mask[j] == '?' || pattern[j] == *(char*)(base + i + j);
}
// Found = true, our entire pattern was found
// Return the memory addy so we can write to it
if (found)
{
return base + i;
}
}
return NULL;
}
以上是我的,我用它來尋找字節的內存給定部分FindPattern功能,這裏是我如何調用該函數:轉換十六進制整數到形式「 X」(C++ - 內存)
DWORD PATTERN = FindPattern(0xC0000000, 0x20000,"\x1F\x37\x66\xE3", "xxxx");
PrintStringBottomCentre("%02x", PATTERN);
現在,假設我有一個整數,例如:0xDEADBEEF 我想將它轉換爲像「:xDE \ xAD \ xBE \ xEF」這樣的字符指針,這樣我就可以將它放到我的FindPattern函數中。我將如何做到這一點?
的'\ x'形式是在你的代碼串_literal_形式。它不存在於內存中。事實上與「0xDEADBEEF」相同; 「0x」僅用於編譯器。 – MSalters
所以你說我不需要\ x? –
確實,你在運行時創建了模式,然後就沒有編譯器。 – MSalters