MCPcopy Create free account
hub / github.com/EmmyLua/EmmyLuaDebugger / LoadSymbolsRecursively

Function LoadSymbolsRecursively

emmy_hook/src/emmy_hook.windows.cpp:165–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165void LoadSymbolsRecursively(HANDLE hProcess, HMODULE hModule)
166{
167 char moduleName[_MAX_PATH];
168 ZeroMemory(moduleName, _MAX_PATH);
169 DWORD nameLen = GetModuleBaseName(hProcess, hModule, moduleName, _MAX_PATH);
170 if (nameLen == 0 || loadedModules.find(moduleName) != loadedModules.end())
171 return;
172
173 loadedModules.insert(moduleName);
174 char modulePath[_MAX_PATH];
175 // skip modules in c://WINDOWS
176 {
177 ZeroMemory(modulePath, _MAX_PATH);
178 DWORD fileNameLen = GetModuleFileNameEx(hProcess, hModule, modulePath, _MAX_PATH);
179 if (fileNameLen == 0)
180 return;
181
182 char windowsPath[MAX_PATH];
183 if (SHGetFolderPath(nullptr, CSIDL_WINDOWS, nullptr, SHGFP_TYPE_CURRENT, windowsPath) == 0)
184 {
185 std::string module_path = modulePath;
186 if (module_path.find(windowsPath) != std::string::npos)
187 {
188 return;
189 }
190 }
191 }
192 // skip emmy modules
193 {
194 static const char* emmyModules[] = {"emmy_hook.dll", "EasyHook.dll"};
195 std::string module_path = modulePath;
196 for (const char* emmyModuleName : emmyModules)
197 {
198 if (strcmp(moduleName, emmyModuleName) == 0)
199 return;
200 }
201 }
202
203 EmmyFacade::Get().SendLog(LogType::Info, "analyze: %s", moduleName);
204
205 PE pe = {};
206 PE_STATUS st = peOpenFile(&pe, modulePath);
207 std::unordered_map<std::string, DWORD64> symbols;
208
209 if (st == PE_SUCCESS)
210 st = peParseExportTable(&pe, INT32_MAX);
211 if (st == PE_SUCCESS && PE_HAS_TABLE(&pe, ExportTable))
212 {
213 PE_FOREACH_EXPORTED_SYMBOL(&pe, pSymbol)
214 {
215 if (PE_SYMBOL_HAS_NAME(pSymbol))
216 {
217 const char* name = pSymbol->Name;
218 if (name[0] == 'l' && name[1] == 'u' && name[2] == 'a')
219 {
220 auto addr = (uint64_t)hModule;
221 addr += pSymbol->Address.VA - pe.qwBaseAddress;
222 symbols[pSymbol->Name] = addr;

Callers 1

PostLoadLibraryFunction · 0.85

Calls 10

peOpenFileFunction · 0.85
peParseExportTableFunction · 0.85
HookLuaFunctionsFunction · 0.85
peParseImportTableFunction · 0.85
findMethod · 0.80
endMethod · 0.80
insertMethod · 0.80
SendLogMethod · 0.80

Tested by

no test coverage detected