From bbffdbf56f6f58e3e78b96eab8fd9eb46f28bfe4 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sat, 4 Jan 2025 12:49:14 +0100 Subject: [PATCH] feat: Allow #pragma magic to index from the end of the data with negative addresses Closes #2047 --- .../content/views/view_pattern_editor.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index d2593cb3a..a4cc8c395 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1573,13 +1573,13 @@ namespace hex::plugin::builtin { if (end == std::string::npos) return std::nullopt; value.resize(end); - //value = value.substr(0, end); + value = wolv::util::trim(value); return BinaryPattern(value); }(); - const auto address = [value = value] mutable -> std::optional { + const auto address = [value = value, provider] mutable -> std::optional { value = wolv::util::trim(value); if (value.empty()) @@ -1593,11 +1593,20 @@ namespace hex::plugin::builtin { value = wolv::util::trim(value); size_t end = 0; - auto result = std::stoull(value, &end, 0); + auto result = std::stoll(value, &end, 0); if (end != value.length()) return std::nullopt; - return result; + if (result < 0) { + const auto size = provider->getActualSize(); + if (-result > size) { + return std::nullopt; + } + + return size + result; + } else { + return result; + } }(); if (!address)