From 3db0eacc92d2c9ee8ff483aa79aaf55d5e449fe9 Mon Sep 17 00:00:00 2001 From: ahm3dgg Date: Tue, 13 Jan 2026 19:41:12 +0200 Subject: [PATCH] Better names and Fixing a Potential Race condition while reading File --- src/windows-emulator/process_context.cpp | 50 ++++++++++++++---------- src/windows-emulator/process_context.hpp | 2 +- 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/src/windows-emulator/process_context.cpp b/src/windows-emulator/process_context.cpp index e354a27a..84b3a460 100644 --- a/src/windows-emulator/process_context.cpp +++ b/src/windows-emulator/process_context.cpp @@ -846,17 +846,21 @@ void process_context::build_knowndlls_section_table(registry_manager& registry, continue; } - auto file = utils::io::read_file(local_known_dll_path); + std::vector file; + + if (!utils::io::read_file(local_known_dll_path, &file)) { - section s; - s.file_name = known_dll_path.u16string(); - s.maximum_size = 0; - s.allocation_attributes = SEC_IMAGE; - s.section_page_protection = PAGE_EXECUTE; - s.cache_image_info_from_filedata(file); - this->add_knowndll_section(known_dll_name, s, is_32bit); + continue; } + section knowndll_section; + knowndll_section.file_name = known_dll_path.u16string(); + knowndll_section.maximum_size = 0; + knowndll_section.allocation_attributes = SEC_IMAGE; + knowndll_section.section_page_protection = PAGE_EXECUTE; + knowndll_section.cache_image_info_from_filedata(file); + this->add_knowndll_section(known_dll_name, knowndll_section, is_32bit); + utils::safe_buffer_accessor buffer{file}; const auto dos_header = buffer.as(0).get(); @@ -900,29 +904,33 @@ void process_context::build_knowndlls_section_table(registry_manager& registry, } } - if (is_knowndll_section_exists(known_dll_dep_name, is_32bit)) + if (has_knowndll_section(known_dll_dep_name, is_32bit)) { continue; } - { - auto known_dll_dep_path = system_root_path / known_dll_dep_name; - auto local_known_dll_dep_path = file_system.translate(system_root_path / known_dll_dep_name); - auto known_dll_dep_file = utils::io::read_file(local_known_dll_dep_path); + auto known_dll_dep_path = system_root_path / known_dll_dep_name; + auto local_known_dll_dep_path = file_system.translate(system_root_path / known_dll_dep_name); - section s; - s.file_name = known_dll_dep_path.u16string(); - s.maximum_size = 0; - s.allocation_attributes = SEC_IMAGE; - s.section_page_protection = PAGE_EXECUTE; - s.cache_image_info_from_filedata(known_dll_dep_file); - this->add_knowndll_section(known_dll_dep_name, s, is_32bit); + std::vector known_dll_dep_file; + + if (!utils::io::read_file(local_known_dll_dep_path, &known_dll_dep_file)) + { + continue; } + + section knowndll_dep_section; + knowndll_dep_section.file_name = known_dll_dep_path.u16string(); + knowndll_dep_section.maximum_size = 0; + knowndll_dep_section.allocation_attributes = SEC_IMAGE; + knowndll_dep_section.section_page_protection = PAGE_EXECUTE; + knowndll_dep_section.cache_image_info_from_filedata(known_dll_dep_file); + this->add_knowndll_section(known_dll_dep_name, knowndll_dep_section, is_32bit); } } } -bool process_context::is_knowndll_section_exists(const std::u16string& name, bool is_32bit) const +bool process_context::has_knowndll_section(const std::u16string& name, bool is_32bit) const { auto lname = utils::string::to_lower(name); diff --git a/src/windows-emulator/process_context.hpp b/src/windows-emulator/process_context.hpp index 7de9bae1..6ed09d0b 100644 --- a/src/windows-emulator/process_context.hpp +++ b/src/windows-emulator/process_context.hpp @@ -94,7 +94,7 @@ struct process_context std::optional
get_knowndll_section_by_name(const std::u16string& name, bool is_32bit) const; void add_knowndll_section(const std::u16string& name, const section& section, bool is_32bit); - bool is_knowndll_section_exists(const std::u16string& name, bool is_32bit) const; + bool has_knowndll_section(const std::u16string& name, bool is_32bit) const; void serialize(utils::buffer_serializer& buffer) const; void deserialize(utils::buffer_deserializer& buffer);