fixed for mac improved readability

This commit is contained in:
2025-10-08 07:26:23 +03:00
parent d84259fdcc
commit e1b4375621
6 changed files with 37 additions and 17 deletions

View File

@@ -4,13 +4,30 @@
#include "omath/utility/pattern_scan.hpp"
#include <charconv>
#include <cstdint>
#include <algorithm>
namespace
{
[[nodiscard]]
constexpr bool is_wildcard(const std::string_view& byte_str)
{
return byte_str == "?" || byte_str == "??";
}
[[nodiscard]]
constexpr bool invalid_byte_str_size(const std::string_view& byte_str)
{
return byte_str.empty() || byte_str.size() >= 3;
}
}
namespace omath
{
std::span<std::byte>::const_iterator
std::span<std::byte>::iterator
PatternScanner::scan_for_pattern(const std::span<std::byte>& range, const std::string_view& pattern)
{
return scan_for_pattern(range.cbegin(), range.cend(), pattern);
return scan_for_pattern(range.begin(), range.end(), pattern);
}
std::expected<std::vector<std::optional<std::byte>>, PatternScanError>
PatternScanner::parse_pattern(const std::string_view& pattern_string)
@@ -28,13 +45,13 @@ namespace omath
const std::string_view byte_str = pattern_string.substr(sting_view_start, sting_view_end);
if (byte_str.empty()) [[unlikely]]
if (invalid_byte_str_size(byte_str)) [[unlikely]]
{
start = end != pattern_string.end() ? std::next(end) : end;
continue;
}
if (byte_str == "?" || byte_str == "??")
if (is_wildcard(byte_str))
{
pattern.emplace_back(std::nullopt);

View File

@@ -15,8 +15,8 @@ namespace omath
{
std::optional<std::uintptr_t>
PePatternScanner::scan_for_pattern_in_loaded_module(const std::string_view& module_name,
const std::string_view& pattern)
PePatternScanner::scan_for_pattern_in_loaded_module([[maybe_unused]] const std::string_view& module_name,
[[maybe_unused]] const std::string_view& pattern)
{
#ifdef _WIN32
const auto base_address = reinterpret_cast<std::uintptr_t>(GetModuleHandleA(module_name.data()));
@@ -59,9 +59,10 @@ namespace omath
return std::distance(pe_section->begin(), pe_section->end());
}
std::optional<std::vector<std::byte>>
PePatternScanner::extract_section_from_pe_file(const std::filesystem::path& path_to_file,
const std::string_view& section_name)
PePatternScanner::extract_section_from_pe_file([[maybe_unused]] const std::filesystem::path& path_to_file,
[[maybe_unused]] const std::string_view& section_name)
{
#ifdef _WIN32
std::fstream file(path_to_file, std::ios::binary | std::ios::in);
if (!file.is_open()) [[unlikely]]
@@ -103,5 +104,8 @@ namespace omath
return section_data;
}
return std::nullopt;
#else
throw std::runtime_error("Pattern scan for loaded modules is only for windows platform");
#endif
}
} // namespace omath