1
0
mirror of synced 2025-01-31 03:53:44 +01:00

feature: Added bool, DOS Date and DOS Time data inspector line

This commit is contained in:
WerWolv 2022-05-27 20:49:38 +02:00
parent ffb9a8b7ed
commit b8bbbd5489
6 changed files with 91 additions and 12 deletions

View File

@ -84,9 +84,7 @@ namespace hex::plugin::builtin {
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::string binary = "0b";
for (u8 i = 0; i < 8; i++)
binary += ((buffer[0] << i) & 0x80) == 0 ? '0' : '1';
std::string binary = hex::format("0b{:b}", buffer[0]);
return [binary] {
ImGui::TextUnformatted(binary.c_str());
@ -216,17 +214,25 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.float16", sizeof(u16),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
auto value = hex::format("{0:G}", hex::changeEndianess(float16ToFloat32(*reinterpret_cast<u16 *>(buffer.data())), endian));
u16 result = 0;
std::memcpy(&result, buffer.data(), sizeof(u16));
const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";
auto value = hex::format(formatString, float16ToFloat32(hex::changeEndianess(result, endian)));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.float", sizeof(float),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
float result = 0;
std::memcpy(&result, buffer.data(), sizeof(float));
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<float *>(buffer.data()), endian));
const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";
auto value = hex::format(formatString, hex::changeEndianess(result, endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
stringToFloat<float>
@ -234,12 +240,12 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.double", sizeof(double),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
double result = 0;
std::memcpy(&result, buffer.data(), sizeof(double));
auto value = hex::format("{0:G}", hex::changeEndianess(result, endian));
const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";
auto value = hex::format(formatString, hex::changeEndianess(result, endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
stringToFloat<double>
@ -247,14 +253,36 @@ namespace hex::plugin::builtin {
ContentRegistry::DataInspector::add("hex.builtin.inspector.long_double", sizeof(long double),
[](auto buffer, auto endian, auto style) {
hex::unused(style);
long double result = 0;
std::memcpy(&result, buffer.data(), sizeof(long double));
auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<long double *>(buffer.data()), endian));
const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";
auto value = hex::format(formatString, hex::changeEndianess(result, endian));
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
},
stringToFloat<long double>
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.bool", sizeof(bool),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
std::string value = [buffer] {
switch (buffer[0]) {
case false:
return "false";
case true:
return "true";
default:
return "Invalid";
}
}();
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
}
);
ContentRegistry::DataInspector::add("hex.builtin.inspector.ascii", sizeof(char8_t),
[](auto buffer, auto endian, auto style) {
hex::unused(endian, style);
@ -403,6 +431,42 @@ namespace hex::plugin::builtin {
#endif
struct DOSDate {
unsigned day : 5;
unsigned month : 4;
unsigned year : 7;
};
struct DOSTime {
unsigned seconds : 5;
unsigned minutes : 6;
unsigned hours : 5;
};
ContentRegistry::DataInspector::add("hex.builtin.inspector.dos_date", sizeof(DOSDate), [](auto buffer, auto endian, auto style) {
hex::unused(style);
DOSDate date = { };
std::memcpy(&date, buffer.data(), sizeof(DOSDate));
date = hex::changeEndianess(date, endian);
auto value = hex::format("{}/{}/{}", date.day, date.month, date.year + 1980);
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.dos_time", sizeof(DOSTime), [](auto buffer, auto endian, auto style) {
hex::unused(style);
DOSTime time = { };
std::memcpy(&time, buffer.data(), sizeof(DOSTime));
time = hex::changeEndianess(time, endian);
auto value = hex::format("{:02}:{:02}:{:02}", time.hours, time.minutes, time.seconds * 2);
return [value] { ImGui::TextUnformatted(value.c_str()); return value; };
});
ContentRegistry::DataInspector::add("hex.builtin.inspector.guid", sizeof(GUID), [](auto buffer, auto endian, auto style) {
hex::unused(style);

View File

@ -404,6 +404,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Zeichen" },
{ "hex.builtin.inspector.wide", "Wide Zeichen" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
@ -411,6 +412,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },
{ "hex.builtin.inspector.dos_date", "DOS Date" },
{ "hex.builtin.inspector.dos_time", "DOS Time" },
{ "hex.builtin.inspector.guid", "GUID" },
{ "hex.builtin.inspector.rgba8", "RGBA8 Farbe" },

View File

@ -409,6 +409,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Character" },
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
@ -416,6 +417,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },
{ "hex.builtin.inspector.dos_date", "DOS Date" },
{ "hex.builtin.inspector.dos_time", "DOS Time" },
{ "hex.builtin.inspector.guid", "GUID" },
{ "hex.builtin.inspector.rgba8", "RGBA8 color" },

View File

@ -404,6 +404,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII Character" },
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
@ -411,6 +412,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },
//{ "hex.builtin.inspector.dos_date", "DOS Date" },
//{ "hex.builtin.inspector.dos_time", "DOS Time" },
{ "hex.builtin.inspector.guid", "GUID" },
{ "hex.builtin.inspector.rgba8", "Colori RGBA8" },

View File

@ -411,6 +411,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float (32 bit)" },
{ "hex.builtin.inspector.double", "double (64 bit)" },
{ "hex.builtin.inspector.long_double", "long double (128 bit)" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII文字" },
{ "hex.builtin.inspector.wide", "Wide Character" },
{ "hex.builtin.inspector.utf8", "UTF-8 code point" },
@ -418,6 +419,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },
//{ "hex.builtin.inspector.dos_date", "DOS Date" },
//{ "hex.builtin.inspector.dos_time", "DOS Time" },
{ "hex.builtin.inspector.guid", "GUID" },
{ "hex.builtin.inspector.rgba8", "RGBA8 color" },

View File

@ -404,6 +404,7 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.float", "float(32位单精度浮点)" },
{ "hex.builtin.inspector.double", "double(64位双精度浮点)" },
{ "hex.builtin.inspector.long_double", "long double(128位双精度浮点)" },
{ "hex.builtin.inspector.bool", "bool" },
{ "hex.builtin.inspector.ascii", "ASCII字符" },
{ "hex.builtin.inspector.wide", "宽字符" },
{ "hex.builtin.inspector.utf8", "UTF-8代码点" },
@ -411,6 +412,8 @@ namespace hex::plugin::builtin {
{ "hex.builtin.inspector.time32", "time32_t" },
{ "hex.builtin.inspector.time64", "time64_t" },
{ "hex.builtin.inspector.time", "time_t" },
//{ "hex.builtin.inspector.dos_date", "DOS Date" },
//{ "hex.builtin.inspector.dos_time", "DOS Time" },
{ "hex.builtin.inspector.guid", "GUID" },
{ "hex.builtin.inspector.rgba8", "RGBA8颜色" },