MCPcopy Create free account
hub / github.com/NoMercy-ac/NoMercy / ScanModuleInformations

Function ScanModuleInformations

Source/Client/NM_Engine/IModuleScanner.cpp:260–372  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260bool ScanModuleInformations(HANDLE hProcess, const std::string & szModuleName, DWORD64 dwModuleBase, DWORD dwModuleSize)
261{
262 auto bRet = false;
263 auto ntStat = DWORD64(0x0);
264 auto dwReadFileByteCount = ULONG(0);
265#ifdef _M_X64
266 auto dwReadMemByteCount = 0ULL;
267#else
268 auto dwReadMemByteCount = 0UL;
269#endif
270 auto szMemoryHash = std::string("");
271 auto szMappedHash = std::string("");
272 auto pOldFSValue = PVOID(nullptr);
273 auto pFileBuffer = PVOID(nullptr);
274 auto hFile = HANDLE(INVALID_HANDLE_VALUE);
275 auto dwLastError = 0UL;
276 LARGE_INTEGER liFileSize = { 0 };
277
278 // Dump module
279
280 auto pModuleDump = g_nmApp->DynamicWinapiInstance()->NTHelper()->Alloc(dwModuleSize, __FUNCTION__);
281 if (!pModuleDump)
282 {
283 SCANNER_LOG(LL_ERR, "Memory can NOT allocated! Error: %u", g_winapiApiTable->GetLastError());
284 goto _Complete;
285 }
286
287 ntStat = ReadProcessMemory64(hProcess, dwModuleBase, pModuleDump, dwModuleSize, &dwReadMemByteCount);
288 if (!NT_SUCCESS(ntStat) || dwModuleSize != dwReadMemByteCount)
289 {
290 SCANNER_LOG(LL_ERR, "ReadProcessMemory64 fail! Target process: %p Status: %p", hProcess, ntStat);
291 goto _Complete;
292 }
293
294 // Get module's memory hash
295
296 szMemoryHash = g_nmApp->DirFunctionsInstance()->GetSHA256(pModuleDump, dwModuleSize);
297 if (szMemoryHash.empty())
298 {
299 SCANNER_LOG(LL_ERR, "Memory hash can NOT generated! Error: %u", g_winapiApiTable->GetLastError());
300 goto _Complete;
301 }
302
303// g_nmApp->ScannerInstance()->SendViolationMessageToMasterServer();
304
305 // Get module's mapped hash
306
307 // Disables file system redirection for the calling thread.
308 if (!g_nmApp->DirFunctionsInstance()->ManageFsRedirection(true, nullptr, &pOldFSValue))
309 goto _Complete;
310
311 hFile = g_winapiApiTable->CreateFileA(szModuleName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
312 dwLastError = g_winapiApiTable->GetLastError();
313
314 // Restore file system redirection for the calling thread.
315 if (!g_nmApp->DirFunctionsInstance()->ManageFsRedirection(false, pOldFSValue, nullptr))
316 goto _Complete;
317

Callers 1

ScanModuleMethod · 0.85

Calls 9

ReadProcessMemory64Function · 0.85
NTHelperMethod · 0.80
DynamicWinapiInstanceMethod · 0.80
GetSHA256Method · 0.80
DirFunctionsInstanceMethod · 0.80
ManageFsRedirectionMethod · 0.80
SafeCloseHandleMethod · 0.80
AllocMethod · 0.45
FreeMethod · 0.45

Tested by

no test coverage detected