1
0
mirror of synced 2025-01-11 05:42:15 +01:00

feat: Allow #pragma magic to index from the end of the data with negative addresses

Closes #2047
This commit is contained in:
WerWolv 2025-01-04 12:49:14 +01:00
parent 1c30533d19
commit bbffdbf56f

View File

@ -1573,13 +1573,13 @@ namespace hex::plugin::builtin {
if (end == std::string::npos) if (end == std::string::npos)
return std::nullopt; return std::nullopt;
value.resize(end); value.resize(end);
//value = value.substr(0, end);
value = wolv::util::trim(value); value = wolv::util::trim(value);
return BinaryPattern(value); return BinaryPattern(value);
}(); }();
const auto address = [value = value] mutable -> std::optional<u64> { const auto address = [value = value, provider] mutable -> std::optional<u64> {
value = wolv::util::trim(value); value = wolv::util::trim(value);
if (value.empty()) if (value.empty())
@ -1593,11 +1593,20 @@ namespace hex::plugin::builtin {
value = wolv::util::trim(value); value = wolv::util::trim(value);
size_t end = 0; size_t end = 0;
auto result = std::stoull(value, &end, 0); auto result = std::stoll(value, &end, 0);
if (end != value.length()) if (end != value.length())
return std::nullopt; return std::nullopt;
if (result < 0) {
const auto size = provider->getActualSize();
if (-result > size) {
return std::nullopt;
}
return size + result;
} else {
return result; return result;
}
}(); }();
if (!address) if (!address)