mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-01 21:17:44 -05:00
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:
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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" },
|
||||
|
||||
@@ -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", "宽字符" },
|
||||
|
||||
@@ -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", "框字元" },
|
||||
|
||||
Reference in New Issue
Block a user