MCPcopy Create free account
hub / github.com/Norbyte/bg3se / AddModule

Method AddModule

CoreLib/SymbolMapper.cpp:1060–1095  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1058}
1059
1060bool SymbolMapper::AddModule(std::string const& name, std::wstring const& modName)
1061{
1062 auto hLib = LoadLibraryW(modName.c_str());
1063 if (hLib == NULL) {
1064 ERR("SymbolMapper::AddModule(): Couldn't load module '%s'", ToUTF8(modName).c_str());
1065 return false;
1066 }
1067
1068 MODULEINFO moduleInfo;
1069 if (!GetModuleInformation(GetCurrentProcess(), hLib, &moduleInfo, sizeof(moduleInfo))) {
1070 ERR("SymbolMapper::AddModule(): Couldn't get module info for '%s'", ToUTF8(modName).c_str());
1071 return false;
1072 }
1073
1074 ModuleInfo modInfo;
1075 modInfo.ModuleStart = (uint8_t const*)moduleInfo.lpBaseOfDll;
1076 modInfo.ModuleSize = moduleInfo.SizeOfImage;
1077
1078 // Fallback, if .text segment was not found
1079 modInfo.ModuleTextStart = modInfo.ModuleStart;
1080 modInfo.ModuleTextSize = modInfo.ModuleSize;
1081
1082 auto pNtHdr = ImageNtHeader(const_cast<uint8_t*>(modInfo.ModuleStart));
1083 auto pSectionHdr = (IMAGE_SECTION_HEADER*)(pNtHdr + 1);
1084
1085 for (std::size_t i = 0; i < pNtHdr->FileHeader.NumberOfSections; i++) {
1086 if (memcmp(pSectionHdr->Name, ".text", 6) == 0) {
1087 modInfo.ModuleTextStart = modInfo.ModuleStart + pSectionHdr->VirtualAddress;
1088 modInfo.ModuleTextSize = pSectionHdr->SizeOfRawData;
1089 break;
1090 }
1091 }
1092
1093 modules_.insert(std::make_pair(name, modInfo));
1094 return true;
1095}
1096
1097void SymbolMapper::AddEngineCallback(std::string const& name, std::function<MappingResult(uint8_t const*)> const& cb)
1098{

Callers 2

RegisterLibrariesMethod · 0.80
BindAppMethod · 0.80

Calls 2

ToUTF8Function · 0.70
insertMethod · 0.45

Tested by

no test coverage detected