mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-12 22:53:27 +00:00
fixed for mac improved readability
This commit is contained in:
4
.idea/editor.xml
generated
4
.idea/editor.xml
generated
@@ -201,7 +201,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticDataMemberInUnnamedStruct/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStaticSpecifierOnAnonymousNamespaceMember/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppStringLiteralToCharPointerConversion/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTabsAreDisallowed/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateArgumentsCanBeDeduced/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterNeverUsed/@EntryIndexedValue" value="HINT" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppTemplateParameterShadowing/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
@@ -215,7 +215,7 @@
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaEndRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnmatchedPragmaRegionDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnamedNamespaceInHeaderFile/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnnecessaryWhitespace/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnsignedZeroComparison/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUnusedIncludeDirective/@EntryIndexedValue" value="WARNING" type="string" />
|
||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CppUseAlgorithmWithCount/@EntryIndexedValue" value="SUGGESTION" type="string" />
|
||||
|
||||
@@ -36,11 +36,11 @@ namespace omath
|
||||
|
||||
public:
|
||||
[[nodiscard]]
|
||||
static std::span<std::byte>::const_iterator scan_for_pattern(const std::span<std::byte>& range,
|
||||
static std::span<std::byte>::iterator scan_for_pattern(const std::span<std::byte>& range,
|
||||
const std::string_view& pattern);
|
||||
|
||||
[[nodiscard]]
|
||||
static std::span<std::byte>::const_iterator scan_for_pattern(std::span<std::byte>&& range,
|
||||
static std::span<std::byte>::iterator scan_for_pattern(std::span<std::byte>&& range,
|
||||
const std::string_view& pattern) = delete;
|
||||
|
||||
template<class IteratorType>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
#include <filesystem>
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace omath
|
||||
{
|
||||
class PePatternScanner final
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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());
|
||||
}
|
||||
Reference in New Issue
Block a user