MCPcopy Create free account
hub / github.com/AlSch092/UltimateAntiCheat / SetSectionHash

Method SetSectionHash

Core/Detections.cpp:436–489  ·  view source on GitHub ↗

SetSectionHash sets the member variable `_TextSectionHashes` or `_RDataSectionHashes` via SetSectionHashList() call after finding the `sectionName` named section (.text in our case) Returns a list which we can use in later hashing calls to compare sets of these hashes and detect memory tampering within the section * The integrity checking code in this project should be replaced wi

Source from the content-addressed store, hash-verified

434 * It also does integrity checking for every non-writable section in all loaded modules, which is way better than here
435*/
436bool Detections::SetSectionHash(__in const char* moduleName, __in const char* sectionName)
437{
438 if (moduleName == nullptr || sectionName == nullptr)
439 {
440 Logger::logf(Err, "one or more parameters were nullptr @ SetSectionHash");
441 return false;
442 }
443
444 if (this->GetIntegrityChecker().get() == nullptr)
445 {
446 Logger::logf(Err, "IntegrityChecker was nullptr @ SetSectionHash");
447 return false;
448 }
449
450 bool funcFailed = false;
451
452 uintptr_t ModuleAddr = (uintptr_t)GetModuleHandleA(moduleName);
453
454 if (ModuleAddr == 0)
455 {
456 Logger::logf(Err, "ModuleAddr was 0 @ SetSectionHash");
457 return false;
458 }
459
460 list<ProcessData::Section> sections = Process::GetSections(moduleName);
461
462 if (sections.size() == 0)
463 {
464 Logger::logf(Err, "sections.size() of section %s was 0 @ SetSectionHash", sectionName);
465 return false;
466 }
467
468 for (const auto& section : sections)
469 {
470 if (section.name == sectionName)
471 {
472 vector<uintptr_t> hashes = GetIntegrityChecker()->GetMemoryHash((uintptr_t)section.address + ModuleAddr, section.size);
473
474 if (hashes.size() > 0)
475 {
476 GetIntegrityChecker()->SetSectionHashList(hashes, sectionName);
477 break;
478 }
479 else
480 {
481 Logger::logf(Err, "hashes.size() was 0 @ SetSectionHash", sectionName);
482 funcFailed = true;
483 break;
484 }
485 }
486 }
487
488 return !funcFailed;
489}
490
491/*
492 IsSectionHashUnmatching compares our collected hash list from ::SetSectionHash() , we use cached address + size to prevent spoofing (sections can be renamed at runtime by an attacker)

Callers 1

MonitorMethod · 0.80

Calls 5

GetIntegrityCheckerMethod · 0.95
getMethod · 0.80
sizeMethod · 0.80
GetMemoryHashMethod · 0.80
SetSectionHashListMethod · 0.80

Tested by

no test coverage detected