diff --git a/.idea/editor.xml b/.idea/editor.xml
index 373c50f..fde5348 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -201,7 +201,7 @@
-
+
@@ -215,7 +215,7 @@
-
+
diff --git a/include/omath/utility/pattern_scan.hpp b/include/omath/utility/pattern_scan.hpp
index 35d9314..ae7c714 100644
--- a/include/omath/utility/pattern_scan.hpp
+++ b/include/omath/utility/pattern_scan.hpp
@@ -36,11 +36,11 @@ namespace omath
public:
[[nodiscard]]
- static std::span::const_iterator scan_for_pattern(const std::span& range,
+ static std::span::iterator scan_for_pattern(const std::span& range,
const std::string_view& pattern);
[[nodiscard]]
- static std::span::const_iterator scan_for_pattern(std::span&& range,
+ static std::span::iterator scan_for_pattern(std::span&& range,
const std::string_view& pattern) = delete;
template
diff --git a/include/omath/utility/pe_pattern_scan.hpp b/include/omath/utility/pe_pattern_scan.hpp
index dd03627..bb83bb6 100644
--- a/include/omath/utility/pe_pattern_scan.hpp
+++ b/include/omath/utility/pe_pattern_scan.hpp
@@ -7,6 +7,8 @@
#include
#include
#include
+#include
+
namespace omath
{
class PePatternScanner final
diff --git a/source/utility/pattern_scan.cpp b/source/utility/pattern_scan.cpp
index 2c0e328..b644347 100644
--- a/source/utility/pattern_scan.cpp
+++ b/source/utility/pattern_scan.cpp
@@ -4,13 +4,30 @@
#include "omath/utility/pattern_scan.hpp"
#include
#include
+#include
+
+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::const_iterator
+ std::span::iterator
PatternScanner::scan_for_pattern(const std::span& 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>, 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);
diff --git a/source/utility/pe_pattern_scan.cpp b/source/utility/pe_pattern_scan.cpp
index f9d62e9..380814a 100644
--- a/source/utility/pe_pattern_scan.cpp
+++ b/source/utility/pe_pattern_scan.cpp
@@ -15,8 +15,8 @@ namespace omath
{
std::optional
- 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(GetModuleHandleA(module_name.data()));
@@ -59,9 +59,10 @@ namespace omath
return std::distance(pe_section->begin(), pe_section->end());
}
std::optional>
- 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
\ No newline at end of file
diff --git a/tests/general/unit_test_pattern_scan.cpp b/tests/general/unit_test_pattern_scan.cpp
index 248ab88..59c873a 100644
--- a/tests/general/unit_test_pattern_scan.cpp
+++ b/tests/general/unit_test_pattern_scan.cpp
@@ -48,10 +48,7 @@ TEST(unit_test_pattern_scan, corner_case_3)
TEST(unit_test_pattern_scan, corner_case_4)
{
- const auto result = omath::PatternScanner::parse_pattern("X ? ?? E9 ");
- const auto result2 = omath::PePatternScanner::scan_for_pattern_in_file(
- std::filesystem::path{
- "C:\\Users\\Vlad\\CLionProjects\\l4bhop\\cmake-build\\build\\windows-release\\l4bhop.dll"},
- "4C 8B D1 B8 ? ? ? ? F6 04 25 ? ? ? ? ? 75 ? 0F 05 C3");
+ const auto result = omath::PatternScanner::parse_pattern("XZ");
+
EXPECT_FALSE(result.has_value());
}
\ No newline at end of file