B14CKS1D3 Cheater
Reputation: 0
Joined: 30 Jul 2014 Posts: 26
|
Posted: Sun Jul 24, 2016 8:29 pm Post subject: C++ AOB Scan |
|
|
I'm trying to port my tool(x64, internal) to windows 10 and I'm having the following issue:
On windows 7, I start scanning memory from 0x10000000 to find what I need. Though, on windows 10 memory address are way higher in numbers and that doesn't work. (I can't use GetModuleHandle(0) because the address I search for are before the game's base address)
----------Edit------------
I can get where memory starts, but since on windows 10 memory seems so random and ends up crashing because after a while it gets in a memory region that I can't read.
I got the following code, which seems to work after letting my computer run the ScanC function for over 30min... How can I make it faster?
Code: | static bool IsReadable(void* p)
{
MEMORY_BASIC_INFORMATION mbi = { 0 };
if (VirtualQuery(p, &mbi, sizeof(MEMORY_BASIC_INFORMATION))){
if (mbi.State == MEM_COMMIT && ((mbi.Protect & PAGE_GUARD) == 0) && ((mbi.Protect == PAGE_NOACCESS) == 0)){
bool CanBeAccessed = ((mbi.Protect & PAGE_READWRITE) != 0 || (mbi.Protect & PAGE_WRITECOPY) != 0 || (mbi.Protect & PAGE_EXECUTE_READWRITE) != 0 || (mbi.Protect & PAGE_EXECUTE_WRITECOPY) != 0);
if (CanBeAccessed) return true;
}
}
return false;
}
static DWORD64 ScanC(DWORD64 dwStart, DWORD64 dwLength, std::string s) {
std::vector<PatternByte> p;
std::istringstream iss(s);
std::string w;
while (iss >> w) {
if (w.data()[0] == '?') { // Wildcard
p.push_back(PatternByte());
}
else if (w.length() == 2 && isxdigit(w.data()[0]) && isxdigit(w.data()[1])) { // Hex
p.push_back(PatternByte(w));
}
else {
return NULL;
}
}
printf("Scanning from %p to %p\n", dwStart, dwStart + dwLength);
for (DWORD64 i = 0; i < dwLength; i++) {
UINT8* lpCurrentByte = (UINT8*)(dwStart + i);
if (!IsReadable((void*)(dwStart + i))) {
printf("This is invalid: %p", (dwStart + i));
continue;
}
bool found = true;
for (size_t ps = 0; ps < p.size(); ps++) {
if (p[ps].ignore == false && lpCurrentByte[ps] != p[ps].data) {
found = false;
break;
}
}
if (found) {
return (DWORD64)lpCurrentByte;
}
}
return NULL;
} |
Last edited by B14CKS1D3 on Tue Jul 26, 2016 5:32 pm; edited 2 times in total |
|