mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
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.
This commit is contained in:
@@ -25,17 +25,19 @@ namespace omath
|
|||||||
std::uint64_t raw_base_addr;
|
std::uint64_t raw_base_addr;
|
||||||
std::vector<std::byte> data;
|
std::vector<std::byte> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static std::optional<std::uintptr_t> scan_for_pattern_in_loaded_module(const std::string_view& module_name,
|
static std::optional<std::uintptr_t> scan_for_pattern_in_loaded_module(const std::string_view& module_name,
|
||||||
const std::string_view& pattern);
|
const std::string_view& pattern);
|
||||||
|
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
static std::optional<PeSectionScanResult> scan_for_pattern_in_file(const std::filesystem::path& path_to_file,
|
static std::optional<PeSectionScanResult>
|
||||||
const std::string_view& pattern);
|
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]]
|
[[nodiscard]]
|
||||||
static std::optional<Section>
|
static std::optional<Section> extract_section_from_pe_file(const std::filesystem::path& path_to_file,
|
||||||
extract_section_from_pe_file(const std::filesystem::path& path_to_file, const std::string_view& section_name);
|
const std::string_view& section_name);
|
||||||
};
|
};
|
||||||
} // namespace omath
|
} // namespace omath
|
||||||
@@ -84,9 +84,10 @@ namespace omath
|
|||||||
}
|
}
|
||||||
std::optional<PeSectionScanResult>
|
std::optional<PeSectionScanResult>
|
||||||
PePatternScanner::scan_for_pattern_in_file(const std::filesystem::path& path_to_file,
|
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())
|
if (!pe_section.has_value())
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
Reference in New Issue
Block a user