feat: Added fixed-point row to data inspector

This commit is contained in:
WerWolv
2025-08-28 19:57:51 +02:00
parent a7c37bfb93
commit 8a04d2f477
2 changed files with 40 additions and 3 deletions

View File

@@ -83,6 +83,9 @@
"hex.builtin.inspector.dos_date": "DOS Date",
"hex.builtin.inspector.dos_time": "DOS Time",
"hex.builtin.inspector.double": "double",
"hex.builtin.inspector.fixed_point": "Fixed Point",
"hex.builtin.inspector.fixed_point.total": "Total: {0} bits",
"hex.builtin.inspector.fixed_point.fraction": "Fraction: {0} bits",
"hex.builtin.inspector.float": "float",
"hex.builtin.inspector.float16": "half float",
"hex.builtin.inspector.fp24": "fp24",

View File

@@ -310,6 +310,42 @@ namespace hex::plugin::builtin {
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.fixed_point", 1, [totalBits = int(16), fractionBits = int(8)](const std::vector<u8> &, std::endian endian, Style style) mutable {
std::string value;
const auto currSelection = ImHexApi::HexEditor::getSelection();
const u32 sizeBytes = (totalBits + 7) / 8;
if (currSelection.has_value() && currSelection->size >= sizeBytes) {
u64 fixedPointValue = 0x00;
ImHexApi::Provider::get()->read(currSelection->address, &fixedPointValue, std::min(sizeof(fixedPointValue), currSelection->size));
fixedPointValue = changeEndianness(fixedPointValue, sizeBytes, endian);
fixedPointValue &= hex::bitmask(totalBits);
const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";
value = fmt::format(fmt::runtime(formatString), double(fixedPointValue) / double(1ULL << fractionBits));
} else {
value = "???";
}
return [&, value, totalBitsCopy = totalBits, fractionBitsCopy = fractionBits]() mutable -> std::string {
ContentRegistry::DataInspector::drawMenuItems([&] {
ImGui::SliderInt("##total_bits", &totalBits, 1, 64, fmt::format("hex.builtin.inspector.fixed_point.total"_lang, totalBits).c_str(), ImGuiSliderFlags_AlwaysClamp);
ImGui::SliderInt("##fractional_bits", &fractionBits, 0, totalBits - 1, fmt::format("hex.builtin.inspector.fixed_point.fraction"_lang, fractionBits).c_str(), ImGuiSliderFlags_AlwaysClamp);
if (fractionBits >= totalBits) {
fractionBits = totalBits - 1;
}
});
ImGui::TextUnformatted(value.c_str());
ImGui::SameLine();
ImGui::TextDisabled("(fp%d.%d)", totalBitsCopy - fractionBitsCopy, fractionBitsCopy);
return value;
};
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.sleb128", 1, (16 * 8 / 7) + 1,
[](auto buffer, auto endian, auto style) {
std::ignore = endian;
@@ -496,11 +532,9 @@ namespace hex::plugin::builtin {
std::ignore = endian;
std::ignore = style;
auto currSelection = ImHexApi::HexEditor::getSelection();
std::string value, copyValue;
auto currSelection = ImHexApi::HexEditor::getSelection();
if (currSelection.has_value()) {
std::vector<u8> stringBuffer(std::min<size_t>(currSelection->size, 0x1000), 0x00);
ImHexApi::Provider::get()->read(currSelection->address, stringBuffer.data(), stringBuffer.size());