1
0
mirror of synced 2024-11-12 02:00:52 +01:00

Actually display signed and floating point data in the right format

This commit is contained in:
WerWolv 2020-11-13 12:07:05 +01:00
parent 15b91c1cac
commit 0dcf02f891
5 changed files with 52 additions and 21 deletions

View File

@ -5,14 +5,19 @@
namespace hex {
struct VariableType {
size_t size;
enum class Kind { Unsigned, Signed, FloatingPoint } kind;
};
struct Highlight {
Highlight(u64 offset, size_t size, u32 color, std::string name)
: offset(offset), size(size), color(color), name(name) {
Highlight(u64 offset, VariableType type, u32 color, std::string name)
: offset(offset), type(type), color(color), name(name) {
}
u64 offset;
size_t size;
VariableType type;
u32 color;
std::string name;
};

View File

@ -31,7 +31,7 @@ namespace hex {
ImGui::FileBrowser m_fileBrowser;
void setHighlight(u64 offset, size_t size, std::string name, u32 color = 0);
void setHighlight(u64 offset, std::string name, lang::Token::TypeToken::Type type, size_t size = 0, u32 color = 0);
void parsePattern(char *buffer);
s32 highlightUsingDecls(std::vector<lang::ASTNode*> &ast, lang::ASTNodeTypeDecl* currTypeDeclNode, lang::ASTNodeVariableDecl* currVarDec, u64 offset, std::string name);

View File

@ -35,12 +35,12 @@ namespace hex {
this->m_memoryEditor.HighlightFn = [](const ImU8 *data, size_t off, bool next) -> bool {
ViewHexEditor *_this = (ViewHexEditor *) data;
for (auto&[offset, size, color, name] : _this->m_highlights) {
if (next && off == (offset + size)) {
for (auto&[offset, type, color, name] : _this->m_highlights) {
if (next && off == (offset + type.size)) {
return false;
}
if (off >= offset && off < (offset + size)) {
if (off >= offset && off < (offset + type.size)) {
_this->m_memoryEditor.HighlightColor = color;
return true;
}

View File

@ -75,14 +75,25 @@ namespace hex {
}
void ViewPattern::setHighlight(u64 offset, size_t size, std::string name, u32 color) {
void ViewPattern::setHighlight(u64 offset, std::string name, lang::Token::TypeToken::Type type, size_t size, u32 color) {
if (color == 0)
color = std::mt19937(std::random_device()())();
color &= ~0xFF00'0000;
color |= 0x5000'0000;
this->m_highlights.emplace_back(offset, size, color, name);
VariableType varType = { 0 };
switch (static_cast<u32>(type) & 0x0F) {
default:
case 0: varType.kind = VariableType::Kind::Unsigned; break;
case 1: varType.kind = VariableType::Kind::Signed; break;
case 2: varType.kind = VariableType::Kind::FloatingPoint; break;
}
varType.size = size;
this->m_highlights.emplace_back(offset, varType, color, name);
}
template<std::derived_from<lang::ASTNode> T>
@ -120,7 +131,8 @@ namespace hex {
u64 offset = varNode->getOffset().value();
if (varNode->getVariableType() != lang::Token::TypeToken::Type::CustomType) {
this->setHighlight(offset, (static_cast<u32>(varNode->getVariableType()) >> 4) * varNode->getArraySize(), varNode->getVariableName());
size_t size = static_cast<u32>(varNode->getVariableType()) >> 4 * varNode->getArraySize();
this->setHighlight(offset, varNode->getVariableName(), varNode->getVariableType(), size);
} else {
for (auto &structNode : findNodes<lang::ASTNodeStruct>(lang::ASTNode::Type::Struct, ast))
if (varNode->getCustomVariableTypeName() == structNode->getName()) {
@ -163,7 +175,7 @@ namespace hex {
if (currTypeDeclNode->getAssignedType() != lang::Token::TypeToken::Type::CustomType) {
size_t size = (static_cast<u32>(currTypeDeclNode->getAssignedType()) >> 4);
this->setHighlight(offset, size, name);
this->setHighlight(offset, name, currTypeDeclNode->getAssignedType(), size);
offset += size;
} else {
bool foundType = false;
@ -218,7 +230,7 @@ namespace hex {
if (var->getArraySize() > 1)
memberName += "[" + std::to_string(i) + "]";
this->setHighlight(offset, size, memberName);
this->setHighlight(offset, memberName, var->getVariableType(), size);
offset += size;
}
} else {

View File

@ -36,20 +36,34 @@ namespace hex {
if (this->m_dataProvider != nullptr && this->m_dataProvider->isReadable()) {
for (auto&[offset, size, color, name] : this->m_highlights) {
std::vector<u8> buffer(size + 1, 0x00);
for (auto&[offset, type, color, name] : this->m_highlights) {
std::vector<u8> buffer(type.size + 1, 0x00);
this->m_dataProvider->read(offset, buffer.data(), size);
this->m_dataProvider->read(offset, buffer.data(), type.size);
if (size <= 8) {
if (type.size <= 8) {
u64 data = 0;
std::memcpy(&data, buffer.data(), size);
std::memcpy(&data, buffer.data(), type.size);
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %lu (0x%08lx) \"%s\"", offset,
offset + size, data, data,
makeDisplayable(buffer.data(), buffer.size()).c_str());
switch (type.kind) {
case VariableType::Kind::Unsigned:
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %lu (0x%08lx) \"%s\"", offset,
offset + type.size, data, data,
makeDisplayable(buffer.data(), buffer.size()).c_str());
break;
case VariableType::Kind::Signed:
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %ld (0x%08lx) \"%s\"", offset,
offset + type.size, data, data,
makeDisplayable(buffer.data(), buffer.size()).c_str());
break;
case VariableType::Kind::FloatingPoint:
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] %f (0x%08lx) \"%s\"", offset,
offset + type.size, data, data,
makeDisplayable(buffer.data(), buffer.size()).c_str());
break;
}
} else
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] [ ARRAY ] \"%s\"", offset, offset + size,
ImGui::LabelText(name.c_str(), "[0x%08lx:0x%08lx] [ ARRAY ] \"%s\"", offset, offset + type.size,
makeDisplayable(buffer.data(), buffer.size()).c_str());
}
}