feat: Added LEB128 in data inspector (#615)

* feat: Added LEB128 in data inspector

* feat: Added support for editing LEB128 values

* Moved LEB functions from utils.cpp to crypto.cpp

* Added placeholders for translations

* Made DataInspector::impl::Entry.maxSize mandatory

* Fixed undefined leftshifting behaviour
This commit is contained in:
gudzpoz
2022-08-01 19:20:20 +08:00
committed by GitHub
parent 64f962dbb2
commit eca5fb894f
16 changed files with 200 additions and 3 deletions

View File

@@ -2,6 +2,7 @@
#include <hex/helpers/utils.hpp>
#include <hex/helpers/fmt.hpp>
#include <hex/helpers/crypto.hpp>
#include <hex/api/event.hpp>
#include <hex/providers/provider.hpp>
@@ -264,6 +265,42 @@ namespace hex::plugin::builtin {
stringToFloat<long double>
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.sleb128", 1, (sizeof(i128) * 8 / 7) + 1,
[](auto buffer, auto endian, auto style) {
hex::unused(endian);
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:X}" : "{0}0o{1:o}");
auto number = hex::crypt::decodeSleb128(buffer);
bool negative = number < 0;
auto value = hex::format(format, negative ? "-" : "", std::abs(number));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
return hex::crypt::encodeSleb128(std::strtoll(value.c_str(), nullptr, 0));
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.uleb128", 1, (sizeof(u128) * 8 / 7) + 1,
[](auto buffer, auto endian, auto style) {
hex::unused(endian);
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:X}" : "0o{0:o}");
auto value = hex::format(format, hex::crypt::decodeUleb128(buffer));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
[](const std::string &value, std::endian endian) -> std::vector<u8> {
hex::unused(endian);
return hex::crypt::encodeUleb128(std::strtoull(value.c_str(), nullptr, 0));
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.bool", sizeof(bool),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);

View File

@@ -39,7 +39,7 @@ namespace hex::plugin::builtin {
if (this->m_validBytes < entry.requiredSize)
continue;
std::vector<u8> buffer(entry.requiredSize);
std::vector<u8> buffer(this->m_validBytes > entry.maxSize ? entry.maxSize : this->m_validBytes);
provider->read(this->m_startAddress, buffer.data(), buffer.size());
if (this->m_invert) {