Skip to content

Commit

Permalink
Fix: Check for search result for nullptr
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceiridge committed Aug 1, 2021
1 parent 59b6fc4 commit 7c2b178
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions ChromePatcherDll/patches.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ namespace ChromePatch {
GetModuleInformation(proc, chromeDll, &chromeDllInfo, sizeof(chromeDllInfo));
MEMORY_BASIC_INFORMATION mbi{};

int patchedPatches = 0;
for (uintptr_t i = (uintptr_t)chromeDll; i < (uintptr_t)chromeDll + (uintptr_t)chromeDllInfo.SizeOfImage; i++) {
if (VirtualQuery((LPCVOID)i, &mbi, sizeof(mbi))) {
if (mbi.Protect & (PAGE_GUARD | PAGE_NOCACHE | PAGE_NOACCESS) || !(mbi.State & MEM_COMMIT)) {
Expand All @@ -165,6 +164,12 @@ namespace ChromePatch {

byte* searchResult = simpleSearcher->SearchBytePattern(patch, static_cast<byte*>(mbi.BaseAddress), mbi.RegionSize);

if(searchResult == nullptr) {
std::cerr << "Pattern not found for patch " << patch << std::endl;
patch.finishedPatch = true;
continue;
}

int offsetAttempt = 0;
while(!patch.successfulPatch) {
byte* patchAddr = searchResult + patch.offsets[offsetAttempt];
Expand Down Expand Up @@ -197,13 +202,12 @@ namespace ChromePatch {
std::cerr << "Byte (" << std::hex << (int)*patchAddr << ") not original (" << (int)patch.origByte << ") at " << patchAddr << std::endl;

if(offsetAttempt == patch.offsets.size()) {
break; // Abort trying out offsets if all didn't work
break; // Abort trying out offsets if none worked
}
}
}

patch.finishedPatch = true;
patchedPatches++;
}

i = (uintptr_t)mbi.BaseAddress + mbi.RegionSize; // Skip to the next region after this one has been searched
Expand Down

0 comments on commit 7c2b178

Please sign in to comment.