MCPcopy Create free account
hub / github.com/BeneficialCode/WinArk / GetUserModuleByAddress

Method GetUserModuleByAddress

WinSysCore/Helpers.cpp:224–243  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

222
223
224std::wstring Helpers::GetUserModuleByAddress(ULONG_PTR address, ULONG pid) {
225 std::wstring moduleName = L"";
226 if (pid == 0||pid==4) {
227 return StringToWstring(GetKernelModuleByAddress(address));
228 }
229 WinSys::ProcessModuleTracker m_Tracker(pid);
230 auto count = m_Tracker.EnumModules();
231 auto modules = m_Tracker.GetModules();
232 for (decltype(count) i = 0; i < count; i++) {
233 auto m = modules[i];
234 ULONG_PTR limit = (ULONG_PTR)((char*)m->Base + m->ModuleSize);
235 if (address > (ULONG_PTR)m->Base && address < limit) {
236 moduleName = m->Path;
237 }
238 }
239
240 if (moduleName == L"" && address != 0)
241 return StringToWstring(GetKernelModuleByAddress(address));
242 return moduleName;
243}
244
245std::wstring Helpers::StringToWstring(const std::string& str) {
246 int len = MultiByteToWideChar(CP_ACP, 0, str.c_str(), -1, nullptr, 0);

Callers

nothing calls this directly

Calls 1

EnumModulesMethod · 0.45

Tested by

no test coverage detected