2021-08-29 14:18:45 +02:00
|
|
|
#include <hex/api/content_registry.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
#include <hex/helpers/utils.hpp>
|
2021-08-29 22:15:18 +02:00
|
|
|
#include <hex/helpers/fmt.hpp>
|
2021-09-01 02:01:50 +02:00
|
|
|
#include <hex/api/event.hpp>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-01 18:09:40 +01:00
|
|
|
#include <hex/providers/provider.hpp>
|
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
#include <cstring>
|
2021-08-30 19:12:46 +02:00
|
|
|
#include <codecvt>
|
|
|
|
#include <locale>
|
2021-09-01 02:01:50 +02:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
#include <imgui_internal.h>
|
2022-02-17 14:43:04 +01:00
|
|
|
#include <hex/ui/imgui_imhex_extensions.h>
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
namespace hex::plugin::builtin {
|
|
|
|
|
|
|
|
struct GUID {
|
|
|
|
u32 data1;
|
|
|
|
u16 data2;
|
|
|
|
u16 data3;
|
2022-01-24 20:53:17 +01:00
|
|
|
u8 data4[8];
|
2021-01-22 18:01:39 +01:00
|
|
|
};
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
template<std::integral T>
|
2022-02-15 21:53:39 +01:00
|
|
|
static std::vector<u8> stringToUnsigned(const std::string &value, std::endian endian) requires(sizeof(T) <= sizeof(u64)) {
|
2022-02-15 21:50:27 +01:00
|
|
|
u64 result = std::strtoull(value.c_str(), nullptr, 0);
|
|
|
|
if (result > std::numeric_limits<T>::max()) return {};
|
|
|
|
|
|
|
|
std::vector<u8> bytes(sizeof(T), 0x00);
|
|
|
|
std::memcpy(bytes.data(), &result, bytes.size());
|
|
|
|
|
|
|
|
if (endian != std::endian::native)
|
|
|
|
std::reverse(bytes.begin(), bytes.end());
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::integral T>
|
2022-02-15 21:53:39 +01:00
|
|
|
static std::vector<u8> stringToSigned(const std::string &value, std::endian endian) requires(sizeof(T) <= sizeof(u64)) {
|
2022-02-17 14:43:04 +01:00
|
|
|
i64 result = std::strtoll(value.c_str(), nullptr, 0);
|
2022-02-15 21:50:27 +01:00
|
|
|
if (result > std::numeric_limits<T>::max() || result < std::numeric_limits<T>::min()) return {};
|
|
|
|
|
|
|
|
std::vector<u8> bytes(sizeof(T), 0x00);
|
|
|
|
std::memcpy(bytes.data(), &result, bytes.size());
|
|
|
|
|
|
|
|
if (endian != std::endian::native)
|
|
|
|
std::reverse(bytes.begin(), bytes.end());
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::floating_point T>
|
2022-02-15 21:53:39 +01:00
|
|
|
static std::vector<u8> stringToFloat(const std::string &value, std::endian endian) requires(sizeof(T) <= sizeof(long double)) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto result = std::strtold(value.c_str(), nullptr);
|
|
|
|
|
|
|
|
std::vector<u8> bytes(sizeof(T), 0x00);
|
|
|
|
std::memcpy(bytes.data(), &result, bytes.size());
|
|
|
|
|
|
|
|
if (endian != std::endian::native)
|
|
|
|
std::reverse(bytes.begin(), bytes.end());
|
|
|
|
|
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<std::integral T>
|
2022-02-15 21:53:39 +01:00
|
|
|
static std::vector<u8> stringToInteger(const std::string &value, std::endian endian) requires(sizeof(T) <= sizeof(u64)) {
|
2022-02-15 21:50:27 +01:00
|
|
|
if constexpr (std::is_unsigned_v<T>)
|
|
|
|
return stringToUnsigned<T>(value, endian);
|
|
|
|
else if constexpr (std::is_signed_v<T>)
|
|
|
|
return stringToSigned<T>(value, endian);
|
|
|
|
else
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
// clang-format off
|
2021-01-22 18:01:39 +01:00
|
|
|
void registerDataInspectorEntries() {
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
using Style = ContentRegistry::DataInspector::NumberDisplayStyle;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.binary", sizeof(u8),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian, style);
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
std::string binary = "0b";
|
|
|
|
for (u8 i = 0; i < 8; i++)
|
|
|
|
binary += ((buffer[0] << i) & 0x80) == 0 ? '0' : '1';
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [binary] {
|
|
|
|
ImGui::TextUnformatted(binary.c_str());
|
|
|
|
return binary;
|
2022-02-17 14:43:04 +01:00
|
|
|
};
|
|
|
|
}, [](std::string value, std::endian endian) -> std::vector<u8> {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian);
|
2022-02-15 21:50:27 +01:00
|
|
|
if (value.starts_with("0b"))
|
|
|
|
value = value.substr(2);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
if (value.size() > 8) return { };
|
|
|
|
u8 byte = 0x00;
|
|
|
|
for (char c : value) {
|
|
|
|
byte <<= 1;
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
if (c == '1')
|
|
|
|
byte |= 0b01;
|
|
|
|
else if (c == '0')
|
|
|
|
byte |= 0b00;
|
|
|
|
else
|
|
|
|
return { };
|
|
|
|
}
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return { byte };
|
|
|
|
}
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.u8", sizeof(u8),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian);
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:02X}" : "0o{0:03o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format(format, *reinterpret_cast<u8 *>(buffer.data()));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<u8>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.i8", sizeof(i8),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:02X}" : "{0}0o{1:03o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto number = hex::changeEndianess(*reinterpret_cast<i8 *>(buffer.data()), endian);
|
|
|
|
bool negative = number < 0;
|
|
|
|
auto value = hex::format(format, negative ? "-" : "", std::abs(number));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<i8>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.u16", sizeof(u16),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:04X}" : "0o{0:06o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format(format, hex::changeEndianess(*reinterpret_cast<u16 *>(buffer.data()), endian));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<u16>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.i16", sizeof(i16),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:04X}" : "{0}0o{1:06o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto number = hex::changeEndianess(*reinterpret_cast<i16 *>(buffer.data()), endian);
|
|
|
|
bool negative = number < 0;
|
|
|
|
auto value = hex::format(format, negative ? "-" : "", std::abs(number));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<i16>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.u32", sizeof(u32),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:08X}" : "0o{0:011o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format(format, hex::changeEndianess(*reinterpret_cast<u32 *>(buffer.data()), endian));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<u32>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.i32", sizeof(i32),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:08X}" : "{0}0o{1:011o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto number = hex::changeEndianess(*reinterpret_cast<i32 *>(buffer.data()), endian);
|
|
|
|
bool negative = number < 0;
|
|
|
|
auto value = hex::format(format, negative ? "-" : "", std::abs(number));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<i32>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.u64", sizeof(u64),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:016X}" : "0o{0:022o}");
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format(format, hex::changeEndianess(*reinterpret_cast<u64 *>(buffer.data()), endian));
|
2022-01-15 15:15:25 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<u64>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.i64", sizeof(i64),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-02-15 21:50:27 +01:00
|
|
|
auto format = (style == Style::Decimal) ? "{0}{1:d}" : ((style == Style::Hexadecimal) ? "{0}0x{1:016X}" : "{0}0o{1:022o}");
|
2021-09-01 00:23:45 +02:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto number = hex::changeEndianess(*reinterpret_cast<i64 *>(buffer.data()), endian);
|
|
|
|
bool negative = number < 0;
|
|
|
|
auto value = hex::format(format, negative ? "-" : "", std::abs(number));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToInteger<i64>
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.float16", sizeof(u16),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
2022-02-17 14:43:04 +01:00
|
|
|
auto value = hex::format("{0:G}", hex::changeEndianess(float16ToFloat32(*reinterpret_cast<u16 *>(buffer.data())), endian));
|
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
}
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.float", sizeof(float),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<float *>(buffer.data()), endian));
|
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToFloat<float>
|
|
|
|
);
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.double", sizeof(double),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
|
|
|
double result = 0;
|
|
|
|
std::memcpy(&result, buffer.data(), sizeof(double));
|
|
|
|
|
|
|
|
auto value = hex::format("{0:G}", hex::changeEndianess(result, endian));
|
2022-02-15 21:50:27 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToFloat<double>
|
|
|
|
);
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.long_double", sizeof(long double),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-02-15 21:50:27 +01:00
|
|
|
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<long double *>(buffer.data()), endian));
|
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
},
|
2022-02-17 14:43:04 +01:00
|
|
|
stringToFloat<long double>
|
|
|
|
);
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.ascii", sizeof(char8_t),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian, style);
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
auto value = makePrintable(*reinterpret_cast<char8_t *>(buffer.data()));
|
|
|
|
return [value] { ImGui::TextFormatted("'{0}'", value.c_str()); return value; };
|
|
|
|
},
|
|
|
|
[](const std::string &value, std::endian endian) -> std::vector<u8> {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian);
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
if (value.length() > 1) return { };
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return { u8(value[0]) };
|
|
|
|
}
|
|
|
|
);
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.wide", sizeof(wchar_t),
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
wchar_t wideChar = '\x00';
|
|
|
|
std::memcpy(&wideChar, buffer.data(), std::min(sizeof(wchar_t), buffer.size()));
|
2022-02-15 21:50:27 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
auto c = hex::changeEndianess(wideChar, endian);
|
2022-01-15 14:14:53 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("Invalid");
|
2021-08-30 19:12:46 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
auto value = hex::format("{0}", c <= 255 ? makePrintable(c) : converter.to_bytes(c));
|
|
|
|
return [value] { ImGui::TextFormatted("'{0}'", value.c_str()); return value; };
|
|
|
|
},
|
|
|
|
[](const std::string &value, std::endian endian) -> std::vector<u8> {
|
|
|
|
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter("");
|
2021-08-30 19:12:46 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
std::vector<u8> bytes;
|
|
|
|
auto wideString = converter.from_bytes(value.c_str());
|
|
|
|
std::copy(wideString.begin(), wideString.end(), std::back_inserter(bytes));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
if (endian != std::endian::native)
|
|
|
|
std::reverse(bytes.begin(), bytes.end());
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return bytes;
|
|
|
|
}
|
|
|
|
);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.utf8", sizeof(char8_t) * 4,
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian, style);
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
char utf8Buffer[5] = { 0 };
|
|
|
|
char codepointString[5] = { 0 };
|
|
|
|
u32 codepoint = 0;
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
std::memcpy(utf8Buffer, reinterpret_cast<char8_t *>(buffer.data()), 4);
|
|
|
|
u8 codepointSize = ImTextCharFromUtf8(&codepoint, utf8Buffer, utf8Buffer + 4);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
std::memcpy(codepointString, utf8Buffer, std::min(codepointSize, u8(4)));
|
|
|
|
auto value = hex::format("'{0}' (U+0x{1:04X})",
|
|
|
|
codepoint == 0xFFFD ? "Invalid" : (codepointSize == 1 ? makePrintable(codepointString[0]) : codepointString),
|
|
|
|
codepoint);
|
|
|
|
|
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
}
|
|
|
|
);
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1,
|
|
|
|
[](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian, style);
|
|
|
|
|
|
|
|
Region currSelection = { 0, 0 };
|
2022-02-17 14:43:04 +01:00
|
|
|
EventManager::post<QuerySelection>(currSelection);
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
constexpr static auto MaxStringLength = 32;
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-03-27 00:01:28 +01:00
|
|
|
std::vector<u8> stringBuffer(std::min<size_t>(MaxStringLength, currSelection.size), 0x00);
|
2022-02-17 14:43:04 +01:00
|
|
|
ImHexApi::Provider::get()->read(currSelection.address, stringBuffer.data(), stringBuffer.size());
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
auto value = hex::encodeByteString(stringBuffer);
|
|
|
|
auto copyValue = hex::encodeByteString(buffer);
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
if (currSelection.size > MaxStringLength)
|
|
|
|
value += "...";
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return [value, copyValue] { ImGui::TextFormatted("\"{0}\"", value.c_str()); return copyValue; };
|
|
|
|
},
|
|
|
|
[](const std::string &value, std::endian endian) -> std::vector<u8> {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(endian);
|
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return hex::decodeByteString(value);
|
|
|
|
}
|
|
|
|
);
|
2021-09-01 02:01:50 +02:00
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
#if defined(OS_WINDOWS) && defined(ARCH_64_BIT)
|
|
|
|
|
2022-01-15 15:03:15 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(u32), [](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<u32 *>(buffer.data()), endian);
|
2022-01-15 14:14:53 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::string value;
|
|
|
|
try {
|
|
|
|
value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", fmt::localtime(endianAdjustedTime));
|
|
|
|
} catch (fmt::format_error &e) {
|
|
|
|
value = "Invalid";
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
});
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.time64", sizeof(u64), [](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<u64 *>(buffer.data()), endian);
|
2022-01-15 14:14:53 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
std::string value;
|
|
|
|
try {
|
|
|
|
value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", fmt::localtime(endianAdjustedTime));
|
|
|
|
} catch (fmt::format_error &e) {
|
|
|
|
value = "Invalid";
|
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
|
|
|
});
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
#else
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.time", sizeof(time_t), [](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast<time_t *>(buffer.data()), endian);
|
2022-01-15 15:03:15 +01:00
|
|
|
|
2021-01-22 18:01:39 +01:00
|
|
|
std::string value;
|
2022-01-15 15:03:15 +01:00
|
|
|
try {
|
|
|
|
value = hex::format("{0:%a, %d.%m.%Y %H:%M:%S}", fmt::localtime(endianAdjustedTime));
|
|
|
|
} catch (fmt::format_error &e) {
|
2021-01-22 18:01:39 +01:00
|
|
|
value = "Invalid";
|
2022-01-15 15:03:15 +01:00
|
|
|
}
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-03-02 23:15:15 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
2021-01-22 18:01:39 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.guid", sizeof(GUID), [](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
|
|
|
GUID guid = { };
|
2021-01-22 18:01:39 +01:00
|
|
|
std::memcpy(&guid, buffer.data(), sizeof(GUID));
|
2021-03-03 19:58:22 +01:00
|
|
|
auto value = hex::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}",
|
2022-02-01 22:09:44 +01:00
|
|
|
(hex::changeEndianess(guid.data3, endian) >> 12) <= 5 && ((guid.data4[0] >> 4) >= 8 || (guid.data4[0] >> 4) == 0) ? "" : "Invalid ",
|
|
|
|
hex::changeEndianess(guid.data1, endian),
|
|
|
|
hex::changeEndianess(guid.data2, endian),
|
|
|
|
hex::changeEndianess(guid.data3, endian),
|
|
|
|
guid.data4[0],
|
|
|
|
guid.data4[1],
|
|
|
|
guid.data4[2],
|
|
|
|
guid.data4[3],
|
|
|
|
guid.data4[4],
|
|
|
|
guid.data4[5],
|
|
|
|
guid.data4[6],
|
|
|
|
guid.data4[7]);
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2021-03-02 22:09:38 +01:00
|
|
|
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
|
2021-01-22 18:01:39 +01:00
|
|
|
});
|
|
|
|
|
2021-08-29 14:18:45 +02:00
|
|
|
ContentRegistry::DataInspector::add("hex.builtin.inspector.rgba8", sizeof(u32), [](auto buffer, auto endian, auto style) {
|
2022-03-27 00:01:28 +01:00
|
|
|
hex::unused(style);
|
|
|
|
|
2022-01-24 20:53:17 +01:00
|
|
|
ImColor value(hex::changeEndianess(*reinterpret_cast<u32 *>(buffer.data()), endian));
|
2021-01-22 18:01:39 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
auto copyValue = hex::format("#{:02X}{:02X}{:02X}{:02X}", u8(0xFF * (value.Value.x)), u8(0xFF * (value.Value.y)), u8(0xFF * (value.Value.z)), u8(0xFF * (value.Value.w)));
|
2021-03-02 22:09:38 +01:00
|
|
|
|
2022-02-17 14:43:04 +01:00
|
|
|
return [value, copyValue] {
|
2022-02-15 21:50:27 +01:00
|
|
|
ImGui::ColorButton("##inspectorColor", value, ImGuiColorEditFlags_None, ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetTextLineHeight()));
|
2022-02-17 14:43:04 +01:00
|
|
|
return copyValue;
|
2021-01-22 18:01:39 +01:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
2022-02-17 14:43:04 +01:00
|
|
|
// clang-format on
|
2021-01-22 18:01:39 +01:00
|
|
|
|
|
|
|
}
|