欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 八卦 > Chromium 加载chrome.dll过程分析c++

Chromium 加载chrome.dll过程分析c++

2024/11/30 12:38:01 来源:https://blog.csdn.net/jangdong/article/details/142897603  浏览:    关键词:Chromium 加载chrome.dll过程分析c++

chrome.exe加载同级版本号目录-》chrome.exe和chrome.dll同级目录。

一、优先从chrome.exe同级版本号目录下加载

例如:chrome.exe [版本号:129.0.6668.101] 从129.0.6668.101\chrome.dll下加载

          

发布版大多数都是以此种办法,主要是方便升级时候,防止不同版本号chrome.exe加载错误的chrome.dll。 

二、 chrome.exe和chrome.dll在同目录直接加载。

三、看下代码逻辑:

   F:\code\google\src\chrome\app\main_dll_loader_win.cc

// Returns the full path to |module_name|. Both dev builds (where |module_name|
// is in the current executable's directory) and proper installs (where
// |module_name| is in a versioned sub-directory of the current executable's
// directory) are supported. The identified file is not guaranteed to exist.
base::FilePath GetModulePath(std::wstring_view module_name) {base::FilePath exe_dir;const bool has_path = base::PathService::Get(base::DIR_EXE, &exe_dir);DCHECK(has_path);// Look for the module in a versioned sub-directory of the current// executable's directory and return the path if it can be read. This is the// expected location of modules for proper installs.const base::FilePath module_path =exe_dir.AppendASCII(chrome::kChromeVersion).Append(module_name);if (ModuleCanBeRead(module_path))return module_path;// Othwerwise, return the path to the module in the current executable's// directory. This is the expected location of modules for dev builds.return exe_dir.Append(module_name);
}

 1、 在base::FilePath GetModulePath(std::wstring_view module_name)函数中优先获取chrome.exe所在路径:F:\code\google\src\out\Debug

2、版本号目录F:\code\google\src\out\Debug\122.0.6224.0\chrome.dll

3、如果122.0.6224.0\chrome.dll目录下没有crome.dll直接返回F:\code\google\src\out\Debug

4、最终结果是加载F:\code\google\src\out\Debug\chrome.dll

// Prefetches and loads |module| after setting the CWD to |module|'s
// directory. Returns a handle to the loaded module on success, or nullptr on
// failure.
HMODULE LoadModuleWithDirectory(const base::FilePath& module,const base::CommandLine& cmd_line) {::SetCurrentDirectoryW(module.DirName().value().c_str());if (!cmd_line.HasSwitch(switches::kNoPreReadMainDll)) {base::PreReadFile(module, /*is_executable=*/true);}HMODULE handle = ::LoadLibraryExW(module.value().c_str(), nullptr,LOAD_WITH_ALTERED_SEARCH_PATH);return handle;
}// Prefetches and loads the appropriate DLL for the process type
// |process_type_|. Populates |module| with the path of the loaded DLL.
// Returns a handle to the loaded DLL, or nullptr on failure.
HMODULE Load(base::FilePath* module, const base::CommandLine& cmd_line) {*module = GetModulePath(installer::kChromeDll);if (module->empty()) {PLOG(ERROR) << "Cannot find module " << installer::kChromeDll;return nullptr;}HMODULE dll = LoadModuleWithDirectory(*module, cmd_line);if (!dll)PLOG(ERROR) << "Failed to load Chrome DLL from " << module->value();return dll;
}

总结:end

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com