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) {

View File

@@ -426,6 +426,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Zeichen" },
{ "hex.builtin.inspector.wide", "Wide Zeichen" },

View File

@@ -431,6 +431,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Character" },
{ "hex.builtin.inspector.wide", "Wide Character" },

View File

@@ -429,6 +429,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Character" },
{ "hex.builtin.inspector.wide", "Wide Character" },

View File

@@ -430,6 +430,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII文字" },
{ "hex.builtin.inspector.wide", "Wide Character" },

View File

@@ -427,6 +427,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Character" },
{ "hex.builtin.inspector.wide", "Wide Character" },

View File

@@ -431,6 +431,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float(32位单精度)" },
{ "hex.builtin.inspector.double", "double(64位双精度)" },
{ "hex.builtin.inspector.long_double", "long double(128位四精度)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII 字符" },
{ "hex.builtin.inspector.wide", "宽字符" },

View File

@@ -428,6 +428,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 位元)" },
{ "hex.builtin.inspector.double", "double (64 位元)" },
{ "hex.builtin.inspector.long_double", "long double (128 位元)" },
//{ "hex.builtin.inspector.sleb128", "Signed LEB128" },
//{ "hex.builtin.inspector.uleb128", "Unsigned LEB128" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII 字元" },
{ "hex.builtin.inspector.wide", "框字元" },