build: Update for software defined 128 bit types
This commit is contained in:
parent
e981eff1e6
commit
803ebe34ed
2
lib/external/libwolv
vendored
2
lib/external/libwolv
vendored
@ -1 +1 @@
|
||||
Subproject commit 44b442a72dad9763711d2584c9497da3cd001974
|
||||
Subproject commit fadfefca534d57b0479ee387e13816c682bb9fbf
|
2
lib/external/pattern_language
vendored
2
lib/external/pattern_language
vendored
@ -1 +1 @@
|
||||
Subproject commit 2e65b47bee668c6b8cb63618925d97fc96cb9a03
|
||||
Subproject commit 43ddef609393cabc49c061996f9e56bc67f368f6
|
@ -3,6 +3,7 @@
|
||||
#include <string_view>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ranges.h>
|
||||
#include <fmt/ostream.h>
|
||||
|
||||
namespace hex {
|
||||
|
||||
|
@ -6,17 +6,10 @@
|
||||
#include <concepts>
|
||||
#include <type_traits>
|
||||
|
||||
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 <wolv/types.hpp>
|
||||
|
||||
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;
|
||||
|
||||
|
@ -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<decltype(value)>;
|
||||
ValueType mask = (std::numeric_limits<ValueType>::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<u8> &bytes) {
|
||||
|
@ -470,7 +470,7 @@ namespace hex::crypt {
|
||||
std::vector<u8> bytes;
|
||||
u8 byte;
|
||||
while (true) {
|
||||
byte = value & 0x7F;
|
||||
byte = u8(value & 0x7F);
|
||||
value >>= 7;
|
||||
if constexpr(std::signed_integral<T>) {
|
||||
if (value == 0 && (byte & 0x40) == 0) {
|
||||
|
@ -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<char>('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<char>('0' + (unsignedValue % 10));
|
||||
unsignedValue /= 10;
|
||||
index--;
|
||||
}
|
||||
|
@ -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<u8 *>(buffer) + std::max<i128>(0, overlapMin - offset), overlay->getData().data() + std::max<i128>(0, overlapMin - overlayOffset), overlapMax - overlapMin);
|
||||
std::memcpy(static_cast<u8 *>(buffer) + std::max<u64>(0, overlapMin - offset), overlay->getData().data() + std::max<u64>(0, overlapMin - overlayOffset), overlapMax - overlapMin);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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<long double>
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
|
@ -114,7 +114,7 @@ namespace hex::plugin::builtin {
|
||||
median = input[medianIndex];
|
||||
}
|
||||
|
||||
this->setFloatOnOutput(1, median);
|
||||
this->setFloatOnOutput(1, double(median));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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<u8> 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<u8> 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<u128>(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())
|
||||
|
@ -28,7 +28,7 @@ namespace hex::plugin::builtin {
|
||||
}
|
||||
|
||||
void process() override {
|
||||
m_value = this->getIntegerOnInput(0);
|
||||
m_value = u64(this->getIntegerOnInput(0));
|
||||
}
|
||||
|
||||
private:
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -54,8 +54,8 @@ namespace hex::plugin::builtin {
|
||||
|
||||
overflow = true;
|
||||
} else {
|
||||
gcdResult = std::gcd<i128, i128>(a, b);
|
||||
lcmResult = std::lcm<i128, i128>(a, b);
|
||||
gcdResult = std::gcd<i64, i64>(a, b);
|
||||
lcmResult = std::lcm<i64, i64>(a, b);
|
||||
std::tie(p, q) = extendedGcd(a, b);
|
||||
|
||||
overflow = false;
|
||||
|
@ -412,7 +412,7 @@ namespace hex::plugin::builtin {
|
||||
ieee754statics.resultFloat = std::numeric_limits<long double>::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<long double>::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<long double>::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<i64>(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;
|
||||
|
||||
|
@ -115,7 +115,7 @@ namespace hex::plugin::builtin {
|
||||
void ViewDataInspector::executeInspectors() {
|
||||
// Decode bytes using custom inspectors defined using the pattern language
|
||||
const std::map<std::string, pl::core::Token::Literal> inVariables = {
|
||||
{ "numberDisplayStyle", u128(m_numberDisplayStyle) }
|
||||
{ "numberDisplayStyle", u128(u64(m_numberDisplayStyle)) }
|
||||
};
|
||||
|
||||
// Setup a new pattern language runtime
|
||||
|
@ -165,7 +165,7 @@ namespace hex::plugin::builtin {
|
||||
value = hex::changeEndianness(value, bytes.size(), endian);
|
||||
|
||||
if (std::signed_integral<T>)
|
||||
value = hex::signExtend(bytes.size() * 8, value);
|
||||
value = T(hex::signExtend(bytes.size() * 8, value));
|
||||
|
||||
return hex::format("{}", value);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -1137,7 +1137,7 @@ namespace hex::plugin::builtin {
|
||||
using enum EnvVarType;
|
||||
case Integer:
|
||||
{
|
||||
i64 displayValue = hex::get_or<i128>(value, 0);
|
||||
i64 displayValue = i64(hex::get_or<i128>(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<i128>(variable.value, 0);
|
||||
i64 value = i64(hex::get_or<i128>(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<u128>(variable.value, 0);
|
||||
u64 value = u64(hex::get_or<u128>(variable.value, 0));
|
||||
if (ImGui::InputScalar(label.c_str(), ImGuiDataType_U64, &value))
|
||||
m_hasUnevaluatedChanges = true;
|
||||
variable.value = u128(value);
|
||||
|
@ -54,12 +54,12 @@ namespace hex::plugin::decompress {
|
||||
ContentRegistry::PatternLanguage::addFunction(nsHexDec, "zlib_decompress", FunctionParameterCount::exactly(3), [](Evaluator *evaluator, auto params) -> std::optional<Token::Literal> {
|
||||
#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<Token::Literal> {
|
||||
#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<const u8*>(stream.next_in) - compressedData.data();
|
||||
return u128(reinterpret_cast<const u8*>(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<const u8*>(stream.next_in) - compressedData.data();
|
||||
return u128(reinterpret_cast<const u8*>(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<Token::Literal> {
|
||||
#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<Token::Literal> {
|
||||
#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<Token::Literal> {
|
||||
#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<u8> 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<const char*>(compressedData.data()), reinterpret_cast<char *>(section.data()), compressedData.size(), static_cast<int>(section.size()));
|
||||
|
||||
if (decompressedSize < 0) {
|
||||
return 0;
|
||||
return u128(0);
|
||||
} else if (decompressedSize > 0) {
|
||||
// Successful decompression
|
||||
section.resize(decompressedSize);
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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) });
|
||||
}
|
||||
|
@ -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<u128>(start, 0, maxAddress);
|
||||
m_selectionEnd = std::clamp<u128>(end, 0, maxAddress);
|
||||
m_selectionStart = std::clamp<u64>(start, 0, maxAddress);
|
||||
m_selectionEnd = std::clamp<u64>(end, 0, maxAddress);
|
||||
m_cursorPosition = m_selectionEnd;
|
||||
|
||||
if (m_selectionChanged) {
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include <hex/ui/imgui_imhex_extensions.h>
|
||||
|
||||
namespace hex::plugin::visualizers {
|
||||
std::vector<u32> getIndices(pl::ptrn::Pattern *colorTablePattern, u128 width, u128 height);
|
||||
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u128 width, u128 height);
|
||||
std::vector<u32> getIndices(pl::ptrn::Pattern *colorTablePattern, u64 width, u64 height);
|
||||
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u64 width, u64 height);
|
||||
|
||||
|
||||
void drawImageVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span<const pl::core::Token::Literal> 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) {
|
||||
@ -75,7 +75,7 @@ namespace hex::plugin::visualizers {
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T> ImGuiExt::Texture unmapColors(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u128 width, u128 height) {
|
||||
template <typename T> ImGuiExt::Texture unmapColors(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u64 width, u64 height) {
|
||||
std::vector<T> colorTable = patternToArray<T>(colorTablePattern);
|
||||
auto colorCount = colorTable.size();
|
||||
auto indexCount = indices.size();
|
||||
@ -94,7 +94,7 @@ namespace hex::plugin::visualizers {
|
||||
return texture;
|
||||
}
|
||||
|
||||
std::vector<u32> getIndices(pl::ptrn::Pattern *pattern, u128 width, u128 height) {
|
||||
std::vector<u32> getIndices(pl::ptrn::Pattern *pattern, u64 width, u64 height) {
|
||||
auto indexCount = 2 * width * height / pattern->getSize();
|
||||
std::vector<u32> indices;
|
||||
auto *iterable = dynamic_cast<pl::ptrn::IIterable *>(pattern);
|
||||
@ -138,7 +138,7 @@ namespace hex::plugin::visualizers {
|
||||
return indices;
|
||||
}
|
||||
|
||||
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u128 width, u128 height) {
|
||||
ImGuiExt::Texture getTexture(pl::ptrn::Pattern *colorTablePattern, std::vector<u32>& indices, u64 width, u64 height) {
|
||||
ImGuiExt::Texture texture;
|
||||
auto iterable = dynamic_cast<pl::ptrn::IIterable *>(colorTablePattern);
|
||||
|
||||
|
@ -14,8 +14,8 @@ namespace hex::plugin::visualizers {
|
||||
|
||||
void drawSoundVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span<const pl::core::Token::Literal> 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<i16> waveData;
|
||||
|
@ -15,7 +15,7 @@ namespace hex::plugin::visualizers {
|
||||
|
||||
void drawTableVisualizer(pl::ptrn::Pattern &, bool shouldReset, std::span<const pl::core::Token::Literal> arguments) {
|
||||
static std::vector<std::string> 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<pl::ptrn::IIterable*>(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());
|
||||
|
@ -15,7 +15,7 @@
|
||||
namespace hex::plugin::visualizers {
|
||||
|
||||
void drawTimestampVisualizer(pl::ptrn::Pattern &, bool, std::span<const pl::core::Token::Literal> 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));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user