From 9419e390dad96f9dbeabd6c346a5d3aa5d058d08 Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 9 Oct 2025 20:42:03 +0300 Subject: [PATCH] Allows specifying target section for file scan Enables users to specify the target section name when scanning a PE file for a pattern. This provides more flexibility in locating patterns within a PE file, as it's not limited to the ".text" section. --- include/omath/utility/pe_pattern_scan.hpp | 10 ++++++---- source/utility/pe_pattern_scan.cpp | 5 +++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/include/omath/utility/pe_pattern_scan.hpp b/include/omath/utility/pe_pattern_scan.hpp index ef06739..8d58274 100644 --- a/include/omath/utility/pe_pattern_scan.hpp +++ b/include/omath/utility/pe_pattern_scan.hpp @@ -25,17 +25,19 @@ namespace omath std::uint64_t raw_base_addr; std::vector data; }; + public: [[nodiscard]] static std::optional scan_for_pattern_in_loaded_module(const std::string_view& module_name, const std::string_view& pattern); [[nodiscard]] - static std::optional scan_for_pattern_in_file(const std::filesystem::path& path_to_file, - const std::string_view& pattern); + static std::optional + scan_for_pattern_in_file(const std::filesystem::path& path_to_file, const std::string_view& pattern, + const std::string_view& target_section_name = ".text"); [[nodiscard]] - static std::optional
- extract_section_from_pe_file(const std::filesystem::path& path_to_file, const std::string_view& section_name); + static std::optional
extract_section_from_pe_file(const std::filesystem::path& path_to_file, + const std::string_view& section_name); }; } // namespace omath \ No newline at end of file diff --git a/source/utility/pe_pattern_scan.cpp b/source/utility/pe_pattern_scan.cpp index 920979b..9a63bd9 100644 --- a/source/utility/pe_pattern_scan.cpp +++ b/source/utility/pe_pattern_scan.cpp @@ -84,9 +84,10 @@ namespace omath } std::optional PePatternScanner::scan_for_pattern_in_file(const std::filesystem::path& path_to_file, - const std::string_view& pattern) + const std::string_view& pattern, + const std::string_view& target_section_name) { - const auto pe_section = extract_section_from_pe_file(path_to_file, ".text"); + const auto pe_section = extract_section_from_pe_file(path_to_file, target_section_name); if (!pe_section.has_value()) return std::nullopt;