Skip to content

Commit

Permalink
feature: Added bool, DOS Date and DOS Time data inspector line
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed May 27, 2022
1 parent ffb9a8b commit b8bbbd5
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 12 deletions.
88 changes: 76 additions & 12 deletions plugins/builtin/source/content/data_inspector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -216,45 +214,75 @@ 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>
);

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>
);

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));

const auto formatString = style == Style::Hexadecimal ? "{0:a}" : "{0:G}";

auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast<long double *>(buffer.data()), endian));
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);
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 3 additions & 0 deletions plugins/builtin/source/lang/de_DE.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,16 @@ 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" },
{ "hex.builtin.inspector.string", "String" },
{ "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" },

Expand Down
3 changes: 3 additions & 0 deletions plugins/builtin/source/lang/en_US.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,16 @@ 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" },
{ "hex.builtin.inspector.string", "String" },
{ "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" },

Expand Down
3 changes: 3 additions & 0 deletions plugins/builtin/source/lang/it_IT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,16 @@ 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" },
{ "hex.builtin.inspector.string", "String" },
{ "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" },

Expand Down
3 changes: 3 additions & 0 deletions plugins/builtin/source/lang/ja_JP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,16 @@ 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" },
{ "hex.builtin.inspector.string", "String" },
{ "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" },

Expand Down
3 changes: 3 additions & 0 deletions plugins/builtin/source/lang/zh_CN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,16 @@ 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代码点" },
{ "hex.builtin.inspector.string", "字符串" },
{ "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颜色" },

Expand Down

0 comments on commit b8bbbd5

Please sign in to comment.