当前位置: 首页 > article >正文

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


http://www.kler.cn/news/357947.html

相关文章:

  • 使用Spring Boot打造中小型医院网站
  • 使用Three.js和Force-Directed Graph实现3D知识图谱可视化
  • 【高等数学学习记录】极限存在准则,两个重要极限
  • bash之流程控制
  • 基于SSM+微信小程序的电子点餐管理系统(点餐1)
  • 电影评论网站:Spring Boot技术实践
  • 【微服务】微服务API网关详解:提升系统效率与安全性的关键策略
  • 操作系统学习笔记-1.3操作系统引导,虚拟机
  • 【PHP小课堂】一起学习PHP中的反射(一)
  • 【经管】比特币与以太坊历史价格数据集(2014.1-2024.5)
  • 文件工具类 - C#小函数类推荐
  • Docker容器:Docker-harbor 私有仓库的部署与管理
  • 科研绘图系列:R语言柱状图(histogram)
  • linux基础-学习笔记
  • 深度学习中一些好的博客
  • grafana failed to load dashboard from file= ... json error=EOF
  • 获取每个页面的元素,并写入json
  • Spring Boot框架:图书进销存管理的高效工具
  • 使用 cmake 在 x86 系统中为 arm 系统交叉编译程序
  • JS通过递归函数来剔除树结构特定节点