15static std::string_view
BaseName(std::string_view path)
17 const size_t slash = path.find_last_of(
"\\/");
18 return slash == std::string_view::npos ? path : path.substr(slash + 1);
22static bool SameFileName(std::string_view left, std::string_view right)
24 return left.size() == right.size() && _strnicmp(left.data(), right.data(), left.size()) == 0;
27bool FindModuleAndRanges(std::string_view fileName, Image& module, std::vector<ScanRange>& ranges)
29 HANDLE process = GetCurrentProcess();
30 HMODULE modules[1024];
33 if (!EnumProcessModules(process, modules,
sizeof(modules), &needed))
39 for (DWORD i = 0; i < needed /
sizeof(HMODULE); ++i)
41 char buffer[MAX_PATH];
42 const DWORD length = GetModuleFileNameA(modules[i], buffer,
sizeof(buffer));
48 const std::string_view path(buffer, length);
55 if (GetModuleInformation(process, modules[i], &info,
sizeof(info)) && info.SizeOfImage > best.Size)
57 best = {
static_cast<const uint8_t*
>(info.lpBaseOfDll), info.SizeOfImage, std::string(path)};
66 module = std::move(best);
67 ranges.assign(1,
ScanRange{
module.Base, module.Size});
bool FindModuleAndRanges(std::string_view fileName, Image &module, std::vector< ScanRange > &ranges)
static bool SameFileName(std::string_view left, std::string_view right)
static std::string_view BaseName(std::string_view path)