From 803ebe34ed349067464f906561ab5e25aa208c92 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Wed, 29 Jan 2025 21:37:41 +0100 Subject: [PATCH] build: Update for software defined 128 bit types --- lib/external/libwolv | 2 +- lib/external/pattern_language | 2 +- lib/libimhex/include/hex/helpers/fmt.hpp | 1 + lib/libimhex/include/hex/helpers/types.hpp | 13 ++--- lib/libimhex/include/hex/helpers/utils.hpp | 4 +- lib/libimhex/source/helpers/crypto.cpp | 2 +- lib/libimhex/source/helpers/utils.cpp | 4 +- lib/libimhex/source/providers/provider.cpp | 6 +-- .../include/content/views/view_hex_editor.hpp | 2 +- .../content/command_palette_commands.cpp | 36 ++++++------- .../builtin/source/content/data_inspector.cpp | 4 +- .../data_processor_nodes/math_nodes.cpp | 2 +- .../data_processor_nodes/other_nodes.cpp | 16 +++--- .../data_processor_nodes/visual_nodes.cpp | 2 +- .../content/pl_visualizers/chunk_entropy.cpp | 2 +- .../source/content/tools/color_picker.cpp | 2 +- .../source/content/tools/euclidean_alg.cpp | 4 +- .../source/content/tools/ieee_decoder.cpp | 14 ++--- .../content/views/view_data_inspector.cpp | 2 +- .../source/content/views/view_find.cpp | 2 +- .../source/content/views/view_hex_editor.cpp | 2 +- .../content/views/view_pattern_editor.cpp | 6 +-- .../source/content/pl_functions.cpp | 52 +++++++++---------- .../source/content/pl_builtin_types.cpp | 5 +- .../content/pl_visualizers/disassembler.cpp | 2 +- plugins/ui/include/ui/hex_editor.hpp | 8 +-- .../source/content/pl_visualizers/image.cpp | 16 +++--- .../source/content/pl_visualizers/sound.cpp | 4 +- .../source/content/pl_visualizers/table.cpp | 10 ++-- .../content/pl_visualizers/timestamp.cpp | 2 +- 30 files changed, 112 insertions(+), 117 deletions(-) diff --git a/lib/external/libwolv b/lib/external/libwolv index 44b442a72..fadfefca5 160000 --- a/lib/external/libwolv +++ b/lib/external/libwolv @@ -1 +1 @@ -Subproject commit 44b442a72dad9763711d2584c9497da3cd001974 +Subproject commit fadfefca534d57b0479ee387e13816c682bb9fbf diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 2e65b47be..43ddef609 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 2e65b47bee668c6b8cb63618925d97fc96cb9a03 +Subproject commit 43ddef609393cabc49c061996f9e56bc67f368f6 diff --git a/lib/libimhex/include/hex/helpers/fmt.hpp b/lib/libimhex/include/hex/helpers/fmt.hpp index 314b3561e..f222315ac 100644 --- a/lib/libimhex/include/hex/helpers/fmt.hpp +++ b/lib/libimhex/include/hex/helpers/fmt.hpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace hex { diff --git a/lib/libimhex/include/hex/helpers/types.hpp b/lib/libimhex/include/hex/helpers/types.hpp index 88f0d6c3c..a17573303 100644 --- a/lib/libimhex/include/hex/helpers/types.hpp +++ b/lib/libimhex/include/hex/helpers/types.hpp @@ -6,17 +6,10 @@ #include #include -using u8 = std::uint8_t; -using u16 = std::uint16_t; -using u32 = std::uint32_t; -using u64 = std::uint64_t; -using u128 = __uint128_t; +#include -using i8 = std::int8_t; -using i16 = std::int16_t; -using i32 = std::int32_t; -using i64 = std::int64_t; -using i128 = __int128_t; +using namespace wolv::unsigned_integers; +using namespace wolv::signed_integers; using color_t = u32; diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index b9a579624..2808078be 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -109,13 +109,13 @@ namespace hex { [[nodiscard]] std::wstring utf8ToUtf16(const std::string& utf8); [[nodiscard]] std::string utf16ToUtf8(const std::wstring& utf16); - [[nodiscard]] constexpr u64 extract(u8 from, u8 to, const std::unsigned_integral auto &value) { + [[nodiscard]] constexpr u64 extract(u8 from, u8 to, const auto &value) { if (from < to) std::swap(from, to); using ValueType = std::remove_cvref_t; ValueType mask = (std::numeric_limits::max() >> (((sizeof(value) * 8) - 1) - (from - to))) << to; - return (value & mask) >> to; + return u64((value & mask) >> to); } [[nodiscard]] inline u64 extract(u32 from, u32 to, const std::vector &bytes) { diff --git a/lib/libimhex/source/helpers/crypto.cpp b/lib/libimhex/source/helpers/crypto.cpp index a5d4b41f9..d1bb714e2 100644 --- a/lib/libimhex/source/helpers/crypto.cpp +++ b/lib/libimhex/source/helpers/crypto.cpp @@ -470,7 +470,7 @@ namespace hex::crypt { std::vector bytes; u8 byte; while (true) { - byte = value & 0x7F; + byte = u8(value & 0x7F); value >>= 7; if constexpr(std::signed_integral) { if (value == 0 && (byte & 0x40) == 0) { diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index 6245096de..2746fc2ae 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -52,7 +52,7 @@ namespace hex { u8 index = sizeof(data) - 2; while (value != 0 && index != 0) { - data[index] = '0' + value % 10; + data[index] = static_cast('0' + (value % 10)); value /= 10; index--; } @@ -67,7 +67,7 @@ namespace hex { u8 index = sizeof(data) - 2; while (unsignedValue != 0 && index != 0) { - data[index] = '0' + unsignedValue % 10; + data[index] = static_cast('0' + (unsignedValue % 10)); unsignedValue /= 10; index--; } diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index 82a029c1a..10a6370b5 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -154,10 +154,10 @@ namespace hex::prv { auto overlayOffset = overlay->getAddress(); auto overlaySize = overlay->getSize(); - i128 overlapMin = std::max(offset, overlayOffset); - i128 overlapMax = std::min(offset + size, overlayOffset + overlaySize); + u64 overlapMin = std::max(offset, overlayOffset); + u64 overlapMax = std::min(offset + size, overlayOffset + overlaySize); if (overlapMax > overlapMin) - std::memcpy(static_cast(buffer) + std::max(0, overlapMin - offset), overlay->getData().data() + std::max(0, overlapMin - overlayOffset), overlapMax - overlapMin); + std::memcpy(static_cast(buffer) + std::max(0, overlapMin - offset), overlay->getData().data() + std::max(0, overlapMin - overlayOffset), overlapMax - overlapMin); } } diff --git a/plugins/builtin/include/content/views/view_hex_editor.hpp b/plugins/builtin/include/content/views/view_hex_editor.hpp index 2dd996390..dbc0e7aaf 100644 --- a/plugins/builtin/include/content/views/view_hex_editor.hpp +++ b/plugins/builtin/include/content/views/view_hex_editor.hpp @@ -61,7 +61,7 @@ namespace hex::plugin::builtin { m_hexEditor.setSelection(region); } - void setSelection(u128 start, u128 end) { + void setSelection(u64 start, u64 end) { m_hexEditor.setSelection(start, end); } diff --git a/plugins/builtin/source/content/command_palette_commands.cpp b/plugins/builtin/source/content/command_palette_commands.cpp index 4260b9597..33f46e276 100644 --- a/plugins/builtin/source/content/command_palette_commands.cpp +++ b/plugins/builtin/source/content/command_palette_commands.cpp @@ -77,17 +77,17 @@ namespace hex::plugin::builtin { case Unit::Unitless: case Unit::Decimal: if (isInteger) - return hex::format("{0}", value / multipler); + return hex::format("{0}", i64(value / multipler)); else - return hex::format("{0:.3f}", value / multipler); + return hex::format("{0:.3f}", double(value / multipler)); case Unit::Hexadecimal: - return hex::format("0x{0:x}", u128(value / multipler)); + return hex::format("0x{0:x}", u64(value / multipler)); case Unit::Binary: - return hex::format("0b{0:b}", u128(value / multipler)); + return hex::format("0b{0:b}", u64(value / multipler)); case Unit::Octal: - return hex::format("0o{0:o}", u128(value / multipler)); + return hex::format("0o{0:o}", u64(value / multipler)); case Unit::Bytes: - return hex::format("{0}", u128(value / multipler)); + return hex::format("{0}", u64(value / multipler)); default: return "hex.builtin.command.convert.invalid_conversion"_lang; } @@ -100,17 +100,17 @@ namespace hex::plugin::builtin { case Unit::Bits: case Unit::Decimal: if (isInteger) - return hex::format("{0}", value / multipler); + return hex::format("{0}", i64(value / multipler)); else - return hex::format("{0:.3f}", value / multipler); + return hex::format("{0:.3f}", double(value / multipler)); case Unit::Hexadecimal: - return hex::format("0x{0:x}", u128(value / multipler)); + return hex::format("0x{0:x}", u64(value / multipler)); case Unit::Binary: - return hex::format("0b{0:b}", u128(value / multipler)); + return hex::format("0b{0:b}", u64(value / multipler)); case Unit::Octal: - return hex::format("0o{0:o}", u128(value / multipler)); + return hex::format("0o{0:o}", u64(value / multipler)); case Unit::Bytes: - return hex::format("{0}", u128((value / multipler) / 8)); + return hex::format("{0}", u64((value / multipler) / 8)); default: return "hex.builtin.command.convert.invalid_conversion"_lang; } @@ -123,17 +123,17 @@ namespace hex::plugin::builtin { case Unit::Bytes: case Unit::Decimal: if (isInteger) - return hex::format("{0}", value / multipler); + return hex::format("{0}", i64(value / multipler)); else - return hex::format("{0:.3f}", value / multipler); + return hex::format("{0:.3f}", double(value / multipler)); case Unit::Hexadecimal: - return hex::format("0x{0:x}", u128(value / multipler)); + return hex::format("0x{0:x}", u64(value / multipler)); case Unit::Binary: - return hex::format("0b{0:b}", u128(value / multipler)); + return hex::format("0b{0:b}", u64(value / multipler)); case Unit::Octal: - return hex::format("0o{0:o}", u128(value / multipler)); + return hex::format("0o{0:o}", u64(value / multipler)); case Unit::Bits: - return hex::format("{0}", u128((value / multipler) * 8)); + return hex::format("{0}", u64((value / multipler) * 8)); default: return "hex.builtin.command.convert.invalid_conversion"_lang; } diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index c33605ab0..c3b6667c6 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -92,7 +92,7 @@ namespace hex::plugin::builtin { std::memcpy(&value, buffer.data(), std::min(sizeof(T), Size)); value = hex::changeEndianness(value, Size, endian); if (Size != sizeof(T)) - value = hex::signExtend(Size * 8, value); + value = T(hex::signExtend(Size * 8, value)); return value; } @@ -280,7 +280,7 @@ namespace hex::plugin::builtin { stringToFloat ); - ContentRegistry::DataInspector::add("hex.builtin.inspector.sleb128", 1, (sizeof(i128) * 8 / 7) + 1, + ContentRegistry::DataInspector::add("hex.builtin.inspector.sleb128", 1, (16 * 8 / 7) + 1, [](auto buffer, auto endian, auto style) { std::ignore = endian; diff --git a/plugins/builtin/source/content/data_processor_nodes/math_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes/math_nodes.cpp index 7e5b41116..36337716d 100644 --- a/plugins/builtin/source/content/data_processor_nodes/math_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes/math_nodes.cpp @@ -114,7 +114,7 @@ namespace hex::plugin::builtin { median = input[medianIndex]; } - this->setFloatOnOutput(1, median); + this->setFloatOnOutput(1, double(median)); } }; diff --git a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp index dc625cb4a..99cf53323 100644 --- a/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes/other_nodes.cpp @@ -18,8 +18,8 @@ namespace hex::plugin::builtin { NodeReadData() : Node("hex.builtin.nodes.data_access.read.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.address"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.read.size"), dp::Attribute(dp::Attribute::IOType::Out, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.read.data") }) { } void process() override { - const auto &address = this->getIntegerOnInput(0); - const auto &size = this->getIntegerOnInput(1); + const auto &address = u64(this->getIntegerOnInput(0)); + const auto &size = u64(this->getIntegerOnInput(1)); std::vector data; data.resize(size); @@ -35,7 +35,7 @@ namespace hex::plugin::builtin { NodeWriteData() : Node("hex.builtin.nodes.data_access.write.header", { dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Integer, "hex.builtin.nodes.data_access.write.address"), dp::Attribute(dp::Attribute::IOType::In, dp::Attribute::Type::Buffer, "hex.builtin.nodes.data_access.write.data") }) { } void process() override { - const auto &address = this->getIntegerOnInput(0); + const auto &address = u64(this->getIntegerOnInput(0)); const auto &data = this->getBufferOnInput(1); if (!data.empty()) { @@ -86,7 +86,7 @@ namespace hex::plugin::builtin { void process() override { const auto &input = this->getIntegerOnInput(0); - auto size = this->getIntegerOnInput(1); + auto size = u64(this->getIntegerOnInput(1)); if (size == 0) { for (u32 i = 0; i < sizeof(input); i++) { @@ -198,7 +198,7 @@ namespace hex::plugin::builtin { void process() override { const auto &buffer = this->getBufferOnInput(0); - const auto &count = this->getIntegerOnInput(1); + const auto &count = u64(this->getIntegerOnInput(1)); std::vector output; output.resize(buffer.size() * count); @@ -217,7 +217,7 @@ namespace hex::plugin::builtin { void process() override { auto buffer = this->getBufferOnInput(0); const auto &patch = this->getBufferOnInput(1); - const auto &address = this->getIntegerOnInput(2); + const auto &address = i64(this->getIntegerOnInput(2)); if (address < 0 || static_cast(address) >= buffer.size()) throwNodeError("Address out of range"); @@ -335,8 +335,8 @@ namespace hex::plugin::builtin { m_texture.reset(); const auto &rawData = this->getBufferOnInput(0); - const auto &width = this->getIntegerOnInput(1); - const auto &height = this->getIntegerOnInput(2); + const auto &width = u64(this->getIntegerOnInput(1)); + const auto &height = u64(this->getIntegerOnInput(2)); const size_t requiredBytes = width * height * 4; if (requiredBytes > rawData.size()) diff --git a/plugins/builtin/source/content/data_processor_nodes/visual_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes/visual_nodes.cpp index cb295eb1f..2faf74a97 100644 --- a/plugins/builtin/source/content/data_processor_nodes/visual_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes/visual_nodes.cpp @@ -28,7 +28,7 @@ namespace hex::plugin::builtin { } void process() override { - m_value = this->getIntegerOnInput(0); + m_value = u64(this->getIntegerOnInput(0)); } private: diff --git a/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp b/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp index a77d9fd86..773c11aa0 100644 --- a/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp +++ b/plugins/builtin/source/content/pl_visualizers/chunk_entropy.cpp @@ -15,7 +15,7 @@ namespace hex::plugin::builtin { // Compute data if (shouldReset) { auto pattern = arguments[0].toPattern(); - auto chunkSize = arguments[1].toUnsigned(); + auto chunkSize = u64(arguments[1].toUnsigned()); analyzer.process(pattern->getBytes(), chunkSize); } diff --git a/plugins/builtin/source/content/tools/color_picker.cpp b/plugins/builtin/source/content/tools/color_picker.cpp index aeabd2370..981ada27d 100644 --- a/plugins/builtin/source/content/tools/color_picker.cpp +++ b/plugins/builtin/source/content/tools/color_picker.cpp @@ -162,7 +162,7 @@ namespace hex::plugin::builtin { u64 hexValue = 0; for (u32 index = 0; auto &bitValue : bitValues) { hexValue <<= bitValue.bits; - hexValue |= u64(intColor[index]) & hex::bitmask(bitValue.bits); + hexValue |= u64(intColor[index]) & u64(hex::bitmask(bitValue.bits)); index += 1; } diff --git a/plugins/builtin/source/content/tools/euclidean_alg.cpp b/plugins/builtin/source/content/tools/euclidean_alg.cpp index 6c567cdf6..dafc69a3e 100644 --- a/plugins/builtin/source/content/tools/euclidean_alg.cpp +++ b/plugins/builtin/source/content/tools/euclidean_alg.cpp @@ -54,8 +54,8 @@ namespace hex::plugin::builtin { overflow = true; } else { - gcdResult = std::gcd(a, b); - lcmResult = std::lcm(a, b); + gcdResult = std::gcd(a, b); + lcmResult = std::lcm(a, b); std::tie(p, q) = extendedGcd(a, b); overflow = false; diff --git a/plugins/builtin/source/content/tools/ieee_decoder.cpp b/plugins/builtin/source/content/tools/ieee_decoder.cpp index ee83a0b46..6139c5915 100644 --- a/plugins/builtin/source/content/tools/ieee_decoder.cpp +++ b/plugins/builtin/source/content/tools/ieee_decoder.cpp @@ -412,7 +412,7 @@ namespace hex::plugin::builtin { ieee754statics.resultFloat = std::numeric_limits::infinity(); ieee754.numberType = NumberType::Infinity; ieee754.valueType = ieee754.signBits == 1 ? ValueType::NegativeInfinity : ValueType::PositiveInfinity; - ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1; + ieee754.exponentBits = i64((u128(1) << ieee754statics.exponentBitCount) - 1); ieee754.mantissaBits = 0; } else if (-std::rint(log2Result) > ieee754.exponentBias + ieee754statics.mantissaBitCount - 1) { @@ -434,7 +434,7 @@ namespace hex::plugin::builtin { ieee754statics.resultFloat = std::numeric_limits::signaling_NaN(); ieee754.valueType = ValueType::SignalingNaN; ieee754.numberType = NumberType::NaN; - ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1; + ieee754.exponentBits = i64((u128(1) << ieee754statics.exponentBitCount) - 1); ieee754.mantissaBits = 1; } else if (inputType == InputType::QuietNotANumber || inputType == InputType::NotANumber ) { @@ -442,8 +442,8 @@ namespace hex::plugin::builtin { ieee754statics.resultFloat = std::numeric_limits::quiet_NaN(); ieee754.valueType = ValueType::QuietNaN; ieee754.numberType = NumberType::NaN; - ieee754.exponentBits = (u128(1) << ieee754statics.exponentBitCount) - 1; - ieee754.mantissaBits = (u128(1) << (ieee754statics.mantissaBitCount - 1)); + ieee754.exponentBits = i64((u128(1) << ieee754statics.exponentBitCount) - 1); + ieee754.mantissaBits = i64((u128(1) << (ieee754statics.mantissaBitCount - 1))); } else if (static_cast(std::floor(log2Result)) + ieee754.exponentBias <= 0) { @@ -645,7 +645,7 @@ namespace hex::plugin::builtin { // Result. ImGui::TableNextColumn(); - u64 mask = hex::bitmask(totalBitCount+1); + const auto mask = u64(hex::bitmask(totalBitCount + 1)); std::string maskString = hex::format("0x{:X} ", mask); auto style = ImGui::GetStyle(); @@ -653,7 +653,7 @@ namespace hex::plugin::builtin { ImGui::CalcTextSize(maskString.c_str()).x + style.FramePadding.x * 2.0F); ImGui::PushItemWidth(inputFieldWidth); - u64 newValue = ieee754statics.value & mask; + u64 newValue = u64(ieee754statics.value & mask); if (ImGuiExt::InputHexadecimal("##hex", &newValue, flags)) ieee754statics.value = newValue; ImGui::PopItemWidth(); @@ -668,7 +668,7 @@ namespace hex::plugin::builtin { ImGui::TableNextRow(); ImGui::TableNextColumn(); - ieee754.exponentBias = (u128(1) << (ieee754statics.exponentBitCount - 1)) - 1; + ieee754.exponentBias = u64((u128(1) << (ieee754statics.exponentBitCount - 1)) - 1); ieee754.signValue = ieee754.signBits == 0 ? 1.0 : -1.0; diff --git a/plugins/builtin/source/content/views/view_data_inspector.cpp b/plugins/builtin/source/content/views/view_data_inspector.cpp index 7dbd0d061..5b831d7e3 100644 --- a/plugins/builtin/source/content/views/view_data_inspector.cpp +++ b/plugins/builtin/source/content/views/view_data_inspector.cpp @@ -115,7 +115,7 @@ namespace hex::plugin::builtin { void ViewDataInspector::executeInspectors() { // Decode bytes using custom inspectors defined using the pattern language const std::map inVariables = { - { "numberDisplayStyle", u128(m_numberDisplayStyle) } + { "numberDisplayStyle", u128(u64(m_numberDisplayStyle)) } }; // Setup a new pattern language runtime diff --git a/plugins/builtin/source/content/views/view_find.cpp b/plugins/builtin/source/content/views/view_find.cpp index 07eba16fa..9bf92cb8d 100644 --- a/plugins/builtin/source/content/views/view_find.cpp +++ b/plugins/builtin/source/content/views/view_find.cpp @@ -165,7 +165,7 @@ namespace hex::plugin::builtin { value = hex::changeEndianness(value, bytes.size(), endian); if (std::signed_integral) - value = hex::signExtend(bytes.size() * 8, value); + value = T(hex::signExtend(bytes.size() * 8, value)); return hex::format("{}", value); } diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index 4e50889f4..f1c6ab966 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -67,7 +67,7 @@ namespace hex::plugin::builtin { } if (ImGuiExt::InputTextIcon("##input", ICON_VS_SYMBOL_OPERATOR, m_input)) { if (auto result = m_evaluator.evaluate(m_input); result.has_value()) { - const auto inputResult = result.value(); + const auto inputResult = u64(result.value()); auto provider = ImHexApi::Provider::get(); switch (m_mode) { diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 561417c27..a87e53f0a 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -1137,7 +1137,7 @@ namespace hex::plugin::builtin { using enum EnvVarType; case Integer: { - i64 displayValue = hex::get_or(value, 0); + i64 displayValue = i64(hex::get_or(value, 0)); ImGui::InputScalar("###value", ImGuiDataType_S64, &displayValue); value = i128(displayValue); break; @@ -1221,12 +1221,12 @@ namespace hex::plugin::builtin { const std::string label { "##" + name }; if (pl::core::Token::isSigned(variable.type)) { - i64 value = hex::get_or(variable.value, 0); + i64 value = i64(hex::get_or(variable.value, 0)); if (ImGui::InputScalar(label.c_str(), ImGuiDataType_S64, &value)) m_hasUnevaluatedChanges = true; variable.value = i128(value); } else if (pl::core::Token::isUnsigned(variable.type)) { - u64 value = hex::get_or(variable.value, 0); + u64 value = u64(hex::get_or(variable.value, 0)); if (ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value)) m_hasUnevaluatedChanges = true; variable.value = u128(value); diff --git a/plugins/decompress/source/content/pl_functions.cpp b/plugins/decompress/source/content/pl_functions.cpp index 0e5c9e362..2fc87ae77 100644 --- a/plugins/decompress/source/content/pl_functions.cpp +++ b/plugins/decompress/source/content/pl_functions.cpp @@ -54,12 +54,12 @@ namespace hex::plugin::decompress { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zlib_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional { #if IMHEX_FEATURE_ENABLED(ZLIB) auto compressedData = getCompressedData(evaluator, params[0]); - auto §ion = evaluator->getSection(params[1].toUnsigned()); - auto windowSize = params[2].toUnsigned(); + auto §ion = evaluator->getSection(u64(params[1].toUnsigned())); + auto windowSize = u64(params[2].toUnsigned()); z_stream stream = { }; if (inflateInit2(&stream, windowSize) != Z_OK) { - return 0; + return u128(0); } section.resize(100); @@ -81,7 +81,7 @@ namespace hex::plugin::decompress { } if (res != Z_OK) { section.resize(section.size() - stream.avail_out); - return stream.next_in - compressedData.data(); + return u128(stream.next_in - compressedData.data()); } if (stream.avail_out != 0) @@ -93,7 +93,7 @@ namespace hex::plugin::decompress { stream.avail_out = prevSectionSize; } - return stream.next_in - compressedData.data(); + return u128(stream.next_in - compressedData.data()); #else std::ignore = evaluator; std::ignore = params; @@ -105,11 +105,11 @@ namespace hex::plugin::decompress { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "bzip_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional { #if IMHEX_FEATURE_ENABLED(BZIP2) auto compressedData = getCompressedData(evaluator, params[0]); - auto §ion = evaluator->getSection(params[1].toUnsigned()); + auto §ion = evaluator->getSection(u64(params[1].toUnsigned())); bz_stream stream = { }; if (BZ2_bzDecompressInit(&stream, 0, 1) != Z_OK) { - return 0; + return u128(0); } section.resize(100); @@ -131,7 +131,7 @@ namespace hex::plugin::decompress { } if (res != BZ_OK) { section.resize(section.size() - stream.avail_out); - return reinterpret_cast(stream.next_in) - compressedData.data(); + return u128(reinterpret_cast(stream.next_in) - compressedData.data()); } if (stream.avail_out != 0) @@ -143,7 +143,7 @@ namespace hex::plugin::decompress { stream.avail_out = prevSectionSize; } - return reinterpret_cast(stream.next_in) - compressedData.data(); + return u128(reinterpret_cast(stream.next_in) - compressedData.data()); #else std::ignore = evaluator; std::ignore = params; @@ -156,12 +156,12 @@ namespace hex::plugin::decompress { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lzma_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional { #if IMHEX_FEATURE_ENABLED(LIBLZMA) auto compressedData = getCompressedData(evaluator, params[0]); - auto §ion = evaluator->getSection(params[1].toUnsigned()); + auto §ion = evaluator->getSection(u64(params[1].toUnsigned())); lzma_stream stream = LZMA_STREAM_INIT; - constexpr int64_t memlimit = 0x40000000; // 1GiB - if (lzma_auto_decoder(&stream, memlimit, LZMA_IGNORE_CHECK) != LZMA_OK) { - return 0; + constexpr static i64 MemoryLimit = 0x40000000; // 1GiB + if (lzma_auto_decoder(&stream, MemoryLimit, LZMA_IGNORE_CHECK) != LZMA_OK) { + return u128(0); } section.resize(100); @@ -184,15 +184,15 @@ namespace hex::plugin::decompress { if (res == LZMA_MEMLIMIT_ERROR) { auto usage = lzma_memusage(&stream); - evaluator->getConsole().log(pl::core::LogConsole::Level::Warning, fmt::format("lzma_decompress memory usage {} bytes would exceed the limit ({} bytes), aborting", usage, memlimit)); + evaluator->getConsole().log(pl::core::LogConsole::Level::Warning, fmt::format("lzma_decompress memory usage {} bytes would exceed the limit ({} bytes), aborting", usage, MemoryLimit)); section.resize(section.size() - stream.avail_out); - return stream.next_in - compressedData.data(); + return u128(stream.next_in - compressedData.data()); } if (res != LZMA_OK) { section.resize(section.size() - stream.avail_out); - return stream.next_in - compressedData.data(); + return u128(stream.next_in - compressedData.data()); } if (stream.avail_out != 0) @@ -204,7 +204,7 @@ namespace hex::plugin::decompress { stream.avail_out = prevSectionSize; } - return stream.next_in - compressedData.data(); + return u128(stream.next_in - compressedData.data()); #else std::ignore = evaluator; std::ignore = params; @@ -216,11 +216,11 @@ namespace hex::plugin::decompress { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zstd_decompress", FunctionParameterCount::exactly(2), [](Evaluator *evaluator, auto params) -> std::optional { #if IMHEX_FEATURE_ENABLED(ZSTD) auto compressedData = getCompressedData(evaluator, params[0]); - auto §ion = evaluator->getSection(params[1].toUnsigned()); + auto §ion = evaluator->getSection(i64(params[1].toUnsigned())); ZSTD_DCtx* dctx = ZSTD_createDCtx(); if (dctx == nullptr) { - return 0; + return u128(0); } ON_SCOPE_EXIT { @@ -233,7 +233,7 @@ namespace hex::plugin::decompress { size_t blockSize = ZSTD_getFrameContentSize(source, sourceSize); if (blockSize == ZSTD_CONTENTSIZE_ERROR) { - return 0; + return u128(0); } if (blockSize == ZSTD_CONTENTSIZE_UNKNOWN) { @@ -270,7 +270,7 @@ namespace hex::plugin::decompress { size_t ret = ZSTD_decompressDCtx(dctx, section.data() + section.size() - blockSize, blockSize, source, sourceSize); if (ZSTD_isError(ret)) { - return 0; + return u128(0); } } @@ -286,14 +286,14 @@ namespace hex::plugin::decompress { ContentRegistry::PatternLanguage::addFunction(nsHexDec, "lz4_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional { #if IMHEX_FEATURE_ENABLED(LZ4) auto compressedData = getCompressedData(evaluator, params[0]); - auto §ion = evaluator->getSection(params[1].toUnsigned()); + auto §ion = evaluator->getSection(u64(params[1].toUnsigned())); bool frame = params[2].toBoolean(); if (frame) { LZ4F_decompressionContext_t dctx; LZ4F_errorCode_t err = LZ4F_createDecompressionContext(&dctx, LZ4F_VERSION); if (LZ4F_isError(err)) { - return 0; + return u128(0); } std::vector outBuffer(1024 * 1024); @@ -308,7 +308,7 @@ namespace hex::plugin::decompress { size_t ret = LZ4F_decompress(dctx, dstPtr, &dstCapacity, sourcePointer, &srcSize, nullptr); if (LZ4F_isError(ret)) { LZ4F_freeDecompressionContext(dctx); - return sourcePointer - compressedData.data(); + return u128(sourcePointer - compressedData.data()); } section.insert(section.end(), outBuffer.begin(), outBuffer.begin() + dstCapacity); @@ -317,7 +317,7 @@ namespace hex::plugin::decompress { LZ4F_freeDecompressionContext(dctx); - return sourcePointer - compressedData.data(); + return u128(sourcePointer - compressedData.data()); } else { section.resize(1024 * 1024); @@ -325,7 +325,7 @@ namespace hex::plugin::decompress { auto decompressedSize = LZ4_decompress_safe(reinterpret_cast(compressedData.data()), reinterpret_cast(section.data()), compressedData.size(), static_cast(section.size())); if (decompressedSize < 0) { - return 0; + return u128(0); } else if (decompressedSize > 0) { // Successful decompression section.resize(decompressedSize); diff --git a/plugins/disassembler/source/content/pl_builtin_types.cpp b/plugins/disassembler/source/content/pl_builtin_types.cpp index f50614bb1..04dd77f48 100644 --- a/plugins/disassembler/source/content/pl_builtin_types.cpp +++ b/plugins/disassembler/source/content/pl_builtin_types.cpp @@ -73,9 +73,10 @@ namespace hex::plugin::disasm { } catch (const std::exception &e) { err::E0012.throwError(e.what()); } + const auto syntaxString = params[1].toString(); - const auto imageBaseAddress = params[2].toUnsigned(); - const auto imageLoadAddress = params[3].toUnsigned(); + const auto imageBaseAddress = u64(params[2].toUnsigned()); + const auto imageLoadAddress = u64(params[3].toUnsigned()); const auto address = evaluator->getReadOffset(); diff --git a/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp b/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp index 93fa7a93f..480c4bcb1 100644 --- a/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp +++ b/plugins/disassembler/source/content/pl_visualizers/disassembler.cpp @@ -35,7 +35,7 @@ namespace hex::plugin::disasm { auto data = pattern->getBytes(); cs_insn *instructions = nullptr; - size_t instructionCount = cs_disasm(capstone, data.data(), data.size(), baseAddress, 0, &instructions); + size_t instructionCount = cs_disasm(capstone, data.data(), data.size(), u64(baseAddress), 0, &instructions); for (size_t i = 0; i < instructionCount; i++) { disassembly.push_back({ instructions[i].address, { instructions[i].bytes, instructions[i].bytes + instructions[i].size }, hex::format("{} {}", instructions[i].mnemonic, instructions[i].op_str) }); } diff --git a/plugins/ui/include/ui/hex_editor.hpp b/plugins/ui/include/ui/hex_editor.hpp index 662c79e84..f7641ba51 100644 --- a/plugins/ui/include/ui/hex_editor.hpp +++ b/plugins/ui/include/ui/hex_editor.hpp @@ -120,7 +120,7 @@ namespace hex::ui { m_cursorPosition = end; } void setSelection(const Region ®ion) { this->setSelection(region.getStartAddress(), region.getEndAddress()); } - void setSelection(u128 start, u128 end) { + void setSelection(u64 start, u64 end) { if (!ImHexApi::Provider::isValid() || m_provider == nullptr) return; @@ -135,7 +135,7 @@ namespace hex::ui { const size_t maxAddress = m_provider->getActualSize() + m_provider->getBaseAddress() - 1; - constexpr static auto alignDown = [](u128 value, u128 alignment) { + constexpr static auto alignDown = [](u64 value, u64 alignment) { return value & ~(alignment - 1); }; @@ -154,8 +154,8 @@ namespace hex::ui { } } - m_selectionStart = std::clamp(start, 0, maxAddress); - m_selectionEnd = std::clamp(end, 0, maxAddress); + m_selectionStart = std::clamp(start, 0, maxAddress); + m_selectionEnd = std::clamp(end, 0, maxAddress); m_cursorPosition = m_selectionEnd; if (m_selectionChanged) { diff --git a/plugins/visualizers/source/content/pl_visualizers/image.cpp b/plugins/visualizers/source/content/pl_visualizers/image.cpp index 8aa6c1438..0389fc1d3 100644 --- a/plugins/visualizers/source/content/pl_visualizers/image.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/image.cpp @@ -8,8 +8,8 @@ #include namespace hex::plugin::visualizers { - std::vector getIndices(pl::ptrn::Pattern *colorTablePattern, u128 width, u128 height); - ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u128 width, u128 height); + std::vector getIndices(pl::ptrn::Pattern *colorTablePattern, u64 width, u64 height); + ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u64 width, u64 height); void drawImageVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { @@ -42,8 +42,8 @@ namespace hex::plugin::visualizers { if (shouldReset) { auto pattern = arguments[0].toPattern(); - auto width = arguments[1].toUnsigned(); - auto height = arguments[2].toUnsigned(); + auto width = u64(arguments[1].toUnsigned()); + auto height = u64(arguments[2].toUnsigned()); bool hasColorTable = false; if (arguments.size() == 4) { @@ -58,7 +58,7 @@ namespace hex::plugin::visualizers { if (!hasColorTable) { auto data = pattern->getBytes(); - texture = ImGuiExt::Texture::fromBitmap(data.data(), data.size(), width, height,ImGuiExt::Texture::Filter::Nearest); + texture = ImGuiExt::Texture::fromBitmap(data.data(), data.size(), width, height, ImGuiExt::Texture::Filter::Nearest); } } @@ -75,7 +75,7 @@ namespace hex::plugin::visualizers { } } - template ImGuiExt::Texture unmapColors(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u128 width, u128 height) { + template ImGuiExt::Texture unmapColors(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u64 width, u64 height) { std::vector colorTable = patternToArray(colorTablePattern); auto colorCount = colorTable.size(); auto indexCount = indices.size(); @@ -94,7 +94,7 @@ namespace hex::plugin::visualizers { return texture; } - std::vector getIndices(pl::ptrn::Pattern *pattern, u128 width, u128 height) { + std::vector getIndices(pl::ptrn::Pattern *pattern, u64 width, u64 height) { auto indexCount = 2 * width * height / pattern->getSize(); std::vector indices; auto *iterable = dynamic_cast(pattern); @@ -138,7 +138,7 @@ namespace hex::plugin::visualizers { return indices; } - ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u128 width, u128 height) { + ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector& indices, u64 width, u64 height) { ImGuiExt::Texture texture; auto iterable = dynamic_cast(colorTablePattern); diff --git a/plugins/visualizers/source/content/pl_visualizers/sound.cpp b/plugins/visualizers/source/content/pl_visualizers/sound.cpp index 57e978fcb..557460235 100644 --- a/plugins/visualizers/source/content/pl_visualizers/sound.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/sound.cpp @@ -14,8 +14,8 @@ namespace hex::plugin::visualizers { void drawSoundVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { auto wavePattern = arguments[0].toPattern(); - auto channels = arguments[1].toUnsigned(); - auto sampleRate = arguments[2].toUnsigned(); + auto channels = u64(arguments[1].toUnsigned()); + auto sampleRate = u64(arguments[2].toUnsigned()); u32 downSampling = wavePattern->getSize() / 300_scaled / 8 / channels; static std::vector waveData; diff --git a/plugins/visualizers/source/content/pl_visualizers/table.cpp b/plugins/visualizers/source/content/pl_visualizers/table.cpp index 8a06336e3..eb3dea771 100644 --- a/plugins/visualizers/source/content/pl_visualizers/table.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/table.cpp @@ -15,7 +15,7 @@ namespace hex::plugin::visualizers { void drawTableVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span arguments) { static std::vector tableContent; - static u128 width = 0, height = 0; + static u64 width = 0, height = 0; if (shouldReset) { tableContent.clear(); @@ -29,8 +29,8 @@ namespace hex::plugin::visualizers { throw std::logic_error("Table visualizer requires an array pattern as the first argument."); } - width = arguments[1].toUnsigned(); - height = arguments[2].toUnsigned(); + width = u64(arguments[1].toUnsigned()); + height = u64(arguments[2].toUnsigned()); auto iterable = dynamic_cast(pattern.get()); iterable->forEachEntry(0, iterable->getEntryCount(), [&](u64, pl::ptrn::Pattern *entry) { @@ -42,9 +42,9 @@ namespace hex::plugin::visualizers { throw std::logic_error(hex::format("Table visualizer cannot have more than {} columns.", IMGUI_TABLE_MAX_COLUMNS)); if (ImGui::BeginTable("##visualizer_table", width, ImGuiTableFlags_Borders | ImGuiTableFlags_RowBg)) { - for (u128 i = 0; i < height; i += 1) { + for (u64 i = 0; i < height; i += 1) { ImGui::TableNextRow(); - for (u128 j = 0; j < width; j += 1) { + for (u64 j = 0; j < width; j += 1) { ImGui::TableSetColumnIndex(j); if (i * width + j < tableContent.size()) ImGui::TextUnformatted(tableContent[(i * width) + j].c_str()); diff --git a/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp b/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp index 50fddfaf7..9be992786 100644 --- a/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp +++ b/plugins/visualizers/source/content/pl_visualizers/timestamp.cpp @@ -15,7 +15,7 @@ namespace hex::plugin::visualizers { void drawTimestampVisualizer(pl::ptrn::Pattern &, bool, std::span arguments) { - time_t timestamp = arguments[0].toUnsigned(); + time_t timestamp = u64(arguments[0].toUnsigned()); auto tm = fmt::gmtime(timestamp); auto date = std::chrono::year_month_day(std::chrono::year(tm.tm_year + 1900), std::chrono::month(tm.tm_mon + 1), std::chrono::day(tm.tm_mday));