I'm pretty new to C++, and I feel like this is an easy thing to do, but I have been stuck on it for too long now.
I am trying to compare a value in memory and a const buffer.
The issue seems to be that my buffer is being declared as char validFuncCall[] = "4c8bd1b8";
and the value in memory is being encoded as UTF-16LE (I'm using Windows).
A bit of code:
bool checkEqual(char* src, char* dst, size_t length) {
return memcmp(src, dst, length) == 0;
}
char validFuncCall[] = "4c8bd1b8" ;
PVOID NTwf = GetProcAddress(GetModuleHandle(TEXT("ntdll")), "NtWriteFile");
std::cout << "memory values: ";
unsigned char* p = (unsigned char*)NTwf;
for (int i = 0; i < 4; i++) {
printf("%02hhX ", p[i]);
}
std::cout << std::endl;
if (checkEqual((char*) NTwf, validFuncCall, 4)) {
std::cout << "True" << std::endl;
}
else {
std::cout << "False" << std::endl;
}
Output:
memory values: 4C 8B D1 B8
False
I noticed this question: How can I search for a string in the memory of another process?, but the answer is using ReadProcessMemory()
, which I would rather not use, as the value is in my own process space.