mirror of
https://github.com/WerWolv/ImHex.git
synced 2026-04-02 05:27:41 -05:00
Fixed data inspector not updating properly in all cases
This commit is contained in:
@@ -13,6 +13,16 @@ namespace hex {
|
||||
View::subscribeEvent(Events::RegionSelected, [this](const void* userData){
|
||||
Region region = *static_cast<const Region*>(userData);
|
||||
|
||||
if (this->m_dataProvider == nullptr) {
|
||||
this->m_validBytes = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (region.address == (size_t)-1) {
|
||||
this->m_validBytes = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
this->m_validBytes = std::min(u64(this->m_dataProvider->getSize() - region.address), u64(sizeof(PreviewData)));
|
||||
std::memset(&this->m_previewData, 0x00, sizeof(PreviewData));
|
||||
this->m_dataProvider->read(region.address, &this->m_previewData, this->m_validBytes);
|
||||
@@ -35,20 +45,20 @@ namespace hex {
|
||||
std::string binary;
|
||||
for (u8 i = 0; i < 8; i++)
|
||||
binary += ((this->m_previewData.unsigned8 << i) & 0x80) == 0 ? '0' : '1';
|
||||
this->m_cachedData.emplace_back("Binary (8 bit)", binary);
|
||||
this->m_cachedData.emplace_back("Binary (8 bit)", binary, sizeof(u8));
|
||||
}
|
||||
|
||||
this->m_cachedData.emplace_back("uint8_t", hex::format("%u", hex::changeEndianess(this->m_previewData.unsigned8, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("int8_t", hex::format("%d", hex::changeEndianess(this->m_previewData.signed8, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("uint16_t", hex::format("%u", hex::changeEndianess(this->m_previewData.unsigned16, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("int16_t", hex::format("%d", hex::changeEndianess(this->m_previewData.signed16, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("uint32_t", hex::format("%lu", hex::changeEndianess(this->m_previewData.unsigned32, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("int32_t", hex::format("%ld", hex::changeEndianess(this->m_previewData.signed32, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("uint64_t", hex::format("%llu", hex::changeEndianess(this->m_previewData.unsigned64, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("int64_t", hex::format("%lld", hex::changeEndianess(this->m_previewData.signed64, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("uint8_t", hex::format("%u", hex::changeEndianess(this->m_previewData.unsigned8, this->m_endianess)), sizeof(u8));
|
||||
this->m_cachedData.emplace_back("int8_t", hex::format("%d", hex::changeEndianess(this->m_previewData.signed8, this->m_endianess)), sizeof(s8));
|
||||
this->m_cachedData.emplace_back("uint16_t", hex::format("%u", hex::changeEndianess(this->m_previewData.unsigned16, this->m_endianess)), sizeof(u16));
|
||||
this->m_cachedData.emplace_back("int16_t", hex::format("%d", hex::changeEndianess(this->m_previewData.signed16, this->m_endianess)), sizeof(s16));
|
||||
this->m_cachedData.emplace_back("uint32_t", hex::format("%lu", hex::changeEndianess(this->m_previewData.unsigned32, this->m_endianess)), sizeof(u32));
|
||||
this->m_cachedData.emplace_back("int32_t", hex::format("%ld", hex::changeEndianess(this->m_previewData.signed32, this->m_endianess)), sizeof(s32));
|
||||
this->m_cachedData.emplace_back("uint64_t", hex::format("%llu", hex::changeEndianess(this->m_previewData.unsigned64, this->m_endianess)), sizeof(u64));
|
||||
this->m_cachedData.emplace_back("int64_t", hex::format("%lld", hex::changeEndianess(this->m_previewData.signed64, this->m_endianess)), sizeof(s64));
|
||||
|
||||
this->m_cachedData.emplace_back("ASCII Character", hex::format("'%s'", makePrintable(this->m_previewData.ansiChar).c_str()));
|
||||
this->m_cachedData.emplace_back("Wide Character", hex::format("'%lc'", this->m_previewData.wideChar == 0 ? '\x01' : hex::changeEndianess(this->m_previewData.wideChar, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("ASCII Character", hex::format("'%s'", makePrintable(this->m_previewData.ansiChar).c_str()), sizeof(char));
|
||||
this->m_cachedData.emplace_back("Wide Character", hex::format("'%lc'", this->m_previewData.wideChar == 0 ? '\x01' : hex::changeEndianess(this->m_previewData.wideChar, this->m_endianess)), sizeof(wchar_t));
|
||||
{
|
||||
char buffer[5] = { 0 };
|
||||
char codepointString[5] = { 0 };
|
||||
@@ -58,11 +68,11 @@ namespace hex {
|
||||
u8 codepointSize = ImTextCharFromUtf8(&codepoint, buffer, buffer + 4);
|
||||
|
||||
std::memcpy(codepointString, &codepoint, std::min(codepointSize, u8(4)));
|
||||
this->m_cachedData.emplace_back("UTF-8 code point", hex::format("'%s' (U+%04lx)", codepoint == 0xFFFD ? "Invalid" : codepointString, codepoint));
|
||||
this->m_cachedData.emplace_back("UTF-8 code point", hex::format("'%s' (U+%04lx)", codepoint == 0xFFFD ? "Invalid" : codepointString, codepoint), sizeof(char8_t));
|
||||
}
|
||||
|
||||
this->m_cachedData.emplace_back("float (32 bit)", hex::format("%e", hex::changeEndianess(this->m_previewData.float32, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("double (64 bit)", hex::format("%e", hex::changeEndianess(this->m_previewData.float64, this->m_endianess)));
|
||||
this->m_cachedData.emplace_back("float (32 bit)", hex::format("%e", hex::changeEndianess(this->m_previewData.float32, this->m_endianess)), sizeof(float));
|
||||
this->m_cachedData.emplace_back("double (64 bit)", hex::format("%e", hex::changeEndianess(this->m_previewData.float64, this->m_endianess)), sizeof(double));
|
||||
|
||||
#if defined(_WIN64)
|
||||
{
|
||||
@@ -70,9 +80,9 @@ namespace hex {
|
||||
std::tm * ptm = _localtime32(&endianAdjustedTime);
|
||||
char buffer[32];
|
||||
if (ptm != nullptr && std::strftime(buffer, 32, "%a, %d.%m.%Y %H:%M:%S", ptm))
|
||||
this->m_cachedData.emplace_back("__time32_t", buffer);
|
||||
this->m_cachedData.emplace_back("__time32_t", buffer, sizeof(__time32_t));
|
||||
else
|
||||
this->m_cachedData.emplace_back("__time32_t", "Invalid");
|
||||
this->m_cachedData.emplace_back("__time32_t", "Invalid", sizeof(__time32_t));
|
||||
}
|
||||
|
||||
{
|
||||
@@ -80,9 +90,9 @@ namespace hex {
|
||||
std::tm * ptm = _localtime64(&endianAdjustedTime);
|
||||
char buffer[64];
|
||||
if (ptm != nullptr && std::strftime(buffer, 64, "%a, %d.%m.%Y %H:%M:%S", ptm) != 0)
|
||||
this->m_cachedData.emplace_back("__time64_t", buffer);
|
||||
this->m_cachedData.emplace_back("__time64_t", buffer, sizeof(__time64_t));
|
||||
else
|
||||
this->m_cachedData.emplace_back("__time64_t", "Invalid");
|
||||
this->m_cachedData.emplace_back("__time64_t", "Invalid", sizeof(__time64_t));
|
||||
}
|
||||
#else
|
||||
{
|
||||
@@ -90,9 +100,9 @@ namespace hex {
|
||||
std::tm * ptm = localtime(&endianAdjustedTime);
|
||||
char buffer[64];
|
||||
if (ptm != nullptr && std::strftime(buffer, 64, "%a, %d.%m.%Y %H:%M:%S", ptm) != 0)
|
||||
this->m_cachedData.emplace_back("time_t", buffer);
|
||||
this->m_cachedData.emplace_back("time_t", buffer, sizeof(time_t));
|
||||
else
|
||||
this->m_cachedData.emplace_back("time_t", "Invalid");
|
||||
this->m_cachedData.emplace_back("time_t", "Invalid", sizeof(time_t));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -102,7 +112,8 @@ namespace hex {
|
||||
hex::changeEndianess(this->m_previewData.guid.data2, this->m_endianess),
|
||||
hex::changeEndianess(this->m_previewData.guid.data3, this->m_endianess),
|
||||
this->m_previewData.guid.data4[0], this->m_previewData.guid.data4[1], this->m_previewData.guid.data4[2], this->m_previewData.guid.data4[3],
|
||||
this->m_previewData.guid.data4[4], this->m_previewData.guid.data4[5], this->m_previewData.guid.data4[6], this->m_previewData.guid.data4[7]));
|
||||
this->m_previewData.guid.data4[4], this->m_previewData.guid.data4[5], this->m_previewData.guid.data4[6], this->m_previewData.guid.data4[7]),
|
||||
sizeof(GUID));
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +126,9 @@ namespace hex {
|
||||
|
||||
ImGui::TableHeadersRow();
|
||||
|
||||
for (const auto &[name, value] : this->m_cachedData) {
|
||||
for (const auto &[name, value, size] : this->m_cachedData) {
|
||||
if (this->m_validBytes < size) continue;
|
||||
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted(name.c_str());
|
||||
@@ -123,7 +136,7 @@ namespace hex {
|
||||
ImGui::TextUnformatted(value.c_str());
|
||||
}
|
||||
|
||||
{
|
||||
if (this->m_validBytes >= 4) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::TextUnformatted("RGBA Color");
|
||||
|
||||
Reference in New Issue
Block a user