This source file includes following definitions.
- GetLoadedModulesSnapshot
#include "chrome/browser/install_verification/win/loaded_modules_snapshot.h"
#include <Psapi.h>
#include "base/logging.h"
bool GetLoadedModulesSnapshot(std::vector<HMODULE>* snapshot) {
DCHECK(snapshot);
DCHECK_EQ(0u, snapshot->size());
snapshot->resize(1);
HANDLE process = ::GetCurrentProcess();
int retries_remaining = 5;
do {
DWORD bytes_required = 0;
if (!::EnumProcessModules(process,
&(*snapshot)[0],
snapshot->size() * sizeof(HMODULE),
&bytes_required)) {
DPLOG(ERROR) << "::EnumProcessModules failed.";
return false;
}
DCHECK_EQ(0u, bytes_required % sizeof(HMODULE));
size_t num_modules = bytes_required / sizeof(HMODULE);
if (num_modules <= snapshot->size()) {
snapshot->erase(snapshot->begin() + num_modules, snapshot->end());
return true;
} else if (num_modules == 0) {
DLOG(ERROR) << "Can't determine the module list size.";
return false;
} else {
snapshot->resize(num_modules, NULL);
}
} while (--retries_remaining);
DLOG(ERROR) << "Failed to enumerate modules.";
return false;
}