| 311 | } |
| 312 | |
| 313 | void CProcessATHookTable::CheckIATHook(const std::shared_ptr<WinSys::ModuleInfo>& m) { |
| 314 | PEParser parser(m->Path.c_str()); |
| 315 | if (!parser.IsValid()) |
| 316 | return; |
| 317 | if (!parser.HasImports()) |
| 318 | return; |
| 319 | |
| 320 | bool isSystemFile = parser.IsSystemFile(); |
| 321 | if (isSystemFile) |
| 322 | return; |
| 323 | |
| 324 | SubsystemType type = parser.GetSubsystemType(); |
| 325 | if (type == SubsystemType::Native) { |
| 326 | return; |
| 327 | } |
| 328 | std::vector<ImportedLibrary> libs = parser.GetImports(); |
| 329 | for (const auto& lib : libs) { |
| 330 | void* iat = (byte*)m->Base + lib.IAT; |
| 331 | SIZE_T size = 0; |
| 332 | bool isPe64 = parser.IsPe64(); |
| 333 | if (isPe64) |
| 334 | size = lib.Symbols.size() * sizeof(ULONG_PTR); |
| 335 | else |
| 336 | size = lib.Symbols.size() * sizeof(DWORD); |
| 337 | void* buffer = malloc(size); |
| 338 | if (!buffer) |
| 339 | continue; |
| 340 | bool ok = ReadProcessMemory(m_hProcess, iat, buffer, size, &size); |
| 341 | if (ok) { |
| 342 | int index = 0; |
| 343 | for (auto& item : lib.Symbols) { |
| 344 | DWORD64 address = 0; |
| 345 | int inc = 0; |
| 346 | if (isPe64) { |
| 347 | address = *((PULONG_PTR)buffer + index); |
| 348 | inc = 8; |
| 349 | } |
| 350 | else { |
| 351 | address = *((PULONG)buffer + index); |
| 352 | inc = 4; |
| 353 | } |
| 354 | |
| 355 | auto& symbols = SymbolManager::Get(); |
| 356 | DWORD64 offset = 0; |
| 357 | auto symbol = symbols.GetSymbolFromAddress(m_Pid, address, &offset); |
| 358 | if (symbol) { |
| 359 | auto sym = symbol->GetSymbolInfo(); |
| 360 | std::string symName(sym->Name); |
| 361 | std::wstring wlibName = Helpers::StringToWstring(lib.Name); |
| 362 | std::vector<std::wstring> hosts = GetApiSetHostName(wlibName); |
| 363 | std::vector<ULONG_PTR> orgAddresses; |
| 364 | ULONG_PTR orgAddress = 0; |
| 365 | if (hosts.size() > 0) { |
| 366 | for (const auto& host : hosts) { |
| 367 | orgAddresses = GetExportedProcAddr(host, item.Name, isPe64); |
| 368 | if (orgAddresses.size() > 0 ) { |
| 369 | break; |
| 370 | } |
nothing calls this directly
no test coverage detected