Compare commits

..

13 Commits

Author SHA1 Message Date
WerWolv
7866e3fc2a build: Bumped version to 1.16.2 2022-03-03 14:32:30 +01:00
WerWolv
2abf89cd16 tests: Fixed build 2022-03-03 13:35:12 +01:00
WerWolv
8b2dcf976f patterns: Fixed auto parameter crash 2022-03-03 13:34:05 +01:00
WerWolv
559b86efe1 patterns: Display actual type name of types declared with using 2022-03-03 13:33:45 +01:00
WerWolv
949a26ca0e patterns: Fixed memory leak when using format attribute 2022-03-03 12:11:47 +01:00
WerWolv
2880ca00da patterns: Fixed crash when using attributes 2022-03-03 11:19:46 +01:00
WerWolv
39da62532b fix: Trailing zero at end of string input buffers 2022-03-03 09:27:27 +01:00
WerWolv
483ba95d80 fix: Some text boxes not being writable 2022-03-03 09:24:09 +01:00
WerWolv
2300b0c692 fix: Searching not working at all 2022-03-03 09:06:10 +01:00
WerWolv
cc59b36c54 patterns: Properly reset back current control flow type in arrays
Fixes issue mentioned in #460
2022-03-01 20:57:21 +01:00
WerWolv
61d9918dae patterns: Evaluate return value before setting control flow type
Fixes another issue mentioned in #460
2022-03-01 20:37:27 +01:00
WerWolv
2c361f9b0a build: Don't bundle yara rules anymore because Microsoft Defender is a little cry baby 2022-03-01 20:27:19 +01:00
WerWolv
775b3e8c52 patterns: Fixed crash when using control flow statements without value
Fixes #460
2022-03-01 20:17:03 +01:00
32 changed files with 111 additions and 92 deletions

View File

@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.16)
# Updating the version here will update it throughout ImHex as well
set(IMHEX_VERSION "1.16.1")
set(IMHEX_VERSION "1.16.2")
project(imhex VERSION ${IMHEX_VERSION})
set(CMAKE_CXX_STANDARD 20)

View File

@@ -292,7 +292,7 @@ function(downloadImHexPatternsFiles)
FetchContent_Populate(imhex_patterns)
set(PATTERNS_FOLDERS_TO_INSTALL constants encodings includes patterns yara magic)
set(PATTERNS_FOLDERS_TO_INSTALL constants encodings includes patterns magic)
foreach (FOLDER ${PATTERNS_FOLDERS_TO_INSTALL})
install(DIRECTORY "${imhex_patterns_SOURCE_DIR}/${FOLDER}" DESTINATION "./")
endforeach()

View File

@@ -49,7 +49,7 @@ namespace hex::pl {
evaluator->dataOffset() = std::visit(overloaded {
[this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); },
[this](Pattern *) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); },
[](auto &&offset) -> u64 { return offset; } },
offset->getValue());
}
@@ -101,7 +101,7 @@ namespace hex::pl {
if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) {
entryCount = std::visit(overloaded {
[this](const std::string &) -> i128 { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) -> i128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[this](Pattern *) -> i128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[](auto &&size) -> i128 { return size; } },
literal->getValue());
} else if (auto whileStatement = dynamic_cast<ASTNodeWhileStatement *>(sizeNode.get())) {
@@ -197,7 +197,7 @@ namespace hex::pl {
if (auto literal = dynamic_cast<ASTNodeLiteral *>(sizeNode.get())) {
auto entryCount = std::visit(overloaded {
[this](const std::string &) -> u128 { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) -> u128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[this](Pattern *) -> u128 { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[](auto &&size) -> u128 { return size; } },
literal->getValue());
@@ -215,6 +215,7 @@ namespace hex::pl {
addEntries(std::move(patterns));
auto ctrlFlow = evaluator->getCurrentControlFlowStatement();
evaluator->setCurrentControlFlowStatement(ControlFlowStatement::None);
if (ctrlFlow == ControlFlowStatement::Break)
break;
else if (ctrlFlow == ControlFlowStatement::Continue) {
@@ -238,6 +239,7 @@ namespace hex::pl {
addEntries(std::move(patterns));
auto ctrlFlow = evaluator->getCurrentControlFlowStatement();
evaluator->setCurrentControlFlowStatement(ControlFlowStatement::None);
if (ctrlFlow == ControlFlowStatement::Break)
break;
else if (ctrlFlow == ControlFlowStatement::Continue) {
@@ -284,6 +286,7 @@ namespace hex::pl {
}
auto ctrlFlow = evaluator->getCurrentControlFlowStatement();
evaluator->setCurrentControlFlowStatement(ControlFlowStatement::None);
if (ctrlFlow == ControlFlowStatement::Break)
break;
else if (ctrlFlow == ControlFlowStatement::Continue) {

View File

@@ -44,8 +44,10 @@ namespace hex::pl {
Attributable(const Attributable &other) {
for (auto &attribute : other.m_attributes) {
auto copy = attribute->clone();
if (auto node = dynamic_cast<ASTNodeAttribute *>(copy.get()))
if (auto node = dynamic_cast<ASTNodeAttribute *>(copy.get())) {
this->m_attributes.push_back(std::unique_ptr<ASTNodeAttribute>(node));
(void)copy.release();
}
}
}

View File

@@ -53,7 +53,7 @@ namespace hex::pl {
u8 bitSize = std::visit(overloaded {
[this](const std::string &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a custom type", this); },
[this](Pattern *) -> u8 { LogConsole::abortEvaluation("bitfield field size cannot be a custom type", this); },
[](auto &&offset) -> u8 { return static_cast<u8>(offset); } },
dynamic_cast<ASTNodeLiteral *>(literal.get())->getValue());

View File

@@ -30,7 +30,7 @@ namespace hex::pl {
auto &typePattern = typePatterns.front();
return std::unique_ptr<ASTNode>(std::visit(overloaded {
[&, this](const std::shared_ptr<Pattern> &value) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast custom type '{}' to '{}'", value->getTypeName(), Token::getTypeName(type)), this); },
[&, this](Pattern *value) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast custom type '{}' to '{}'", value->getTypeName(), Token::getTypeName(type)), this); },
[&, this](const std::string &) -> ASTNode * { LogConsole::abortEvaluation(hex::format("cannot cast string to '{}'", Token::getTypeName(type)), this); },
[&, this](auto &&value) -> ASTNode * {
auto endianAdjustedValue = hex::changeEndianess(value, typePattern->getSize(), typePattern->getEndian());

View File

@@ -34,16 +34,20 @@ namespace hex::pl {
}
FunctionResult execute(Evaluator *evaluator) const override {
auto returnValue = this->m_rvalue->evaluate(evaluator);
auto literal = dynamic_cast<ASTNodeLiteral *>(returnValue.get());
evaluator->setCurrentControlFlowStatement(this->m_type);
if (literal == nullptr)
if (this->m_rvalue == nullptr) {
evaluator->setCurrentControlFlowStatement(this->m_type);
return std::nullopt;
else
return literal->getValue();
} else {
auto returnValue = this->m_rvalue->evaluate(evaluator);
auto literal = dynamic_cast<ASTNodeLiteral *>(returnValue.get());
evaluator->setCurrentControlFlowStatement(this->m_type);
if (literal == nullptr)
return std::nullopt;
else
return literal->getValue();
}
}
private:

View File

@@ -76,19 +76,19 @@ namespace hex::pl {
return std::unique_ptr<ASTNode>(std::visit(overloaded {
// TODO: :notlikethis:
[this](u128 left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](i128 left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](double left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](char left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](bool left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::string &left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, u128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, i128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, double right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, char right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, bool right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::shared_ptr<Pattern> &left, const std::shared_ptr<Pattern> &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](u128 left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](i128 left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](double left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](char left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](bool left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::string &left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, u128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, i128 right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, double right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, char right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, bool right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](Pattern *const &left, Pattern *const &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](auto &&left, const std::string &right) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); },
[this](const std::string &left, auto &&right) -> ASTNode * {

View File

@@ -119,7 +119,7 @@ namespace hex::pl {
readVariable(evaluator, value, pattern.get());
literal = u128(hex::extract(bitfieldFieldPattern->getBitOffset() + (bitfieldFieldPattern->getBitSize() - 1), bitfieldFieldPattern->getBitOffset(), value));
} else {
literal = pattern->clone();
literal = pattern.get();
}
if (auto transformFunc = pattern->getTransformFunction(); transformFunc.has_value()) {
@@ -205,7 +205,7 @@ namespace hex::pl {
std::visit(overloaded {
[this](const std::string &) { LogConsole::abortEvaluation("cannot use string to index array", this); },
[this](const std::shared_ptr<Pattern> &) { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[this](Pattern *) { LogConsole::abortEvaluation("cannot use custom type to index array", this); },
[&, this](auto &&index) {
if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(currPattern.get())) {
if (index >= searchScope.size() || index < 0)
@@ -231,25 +231,25 @@ namespace hex::pl {
currPattern = pointerPattern->getPointedAtPattern()->clone();
}
std::shared_ptr<Pattern> indexPattern;
Pattern *indexPattern;
if (currPattern->isLocal()) {
auto stackLiteral = evaluator->getStack()[currPattern->getOffset()];
if (auto stackPattern = std::get_if<std::shared_ptr<Pattern>>(&stackLiteral); stackPattern != nullptr)
if (auto stackPattern = std::get_if<Pattern *>(&stackLiteral); stackPattern != nullptr)
indexPattern = *stackPattern;
else
return hex::moveToVector<std::unique_ptr<Pattern>>(std::move(currPattern));
} else
indexPattern = currPattern->clone();
indexPattern = currPattern.get();
if (auto structPattern = dynamic_cast<PatternStruct *>(indexPattern.get()))
if (auto structPattern = dynamic_cast<PatternStruct *>(indexPattern))
searchScope = structPattern->getMembers();
else if (auto unionPattern = dynamic_cast<PatternUnion *>(indexPattern.get()))
else if (auto unionPattern = dynamic_cast<PatternUnion *>(indexPattern))
searchScope = unionPattern->getMembers();
else if (auto bitfieldPattern = dynamic_cast<PatternBitfield *>(indexPattern.get()))
else if (auto bitfieldPattern = dynamic_cast<PatternBitfield *>(indexPattern))
searchScope = bitfieldPattern->getFields();
else if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(indexPattern.get()))
else if (auto dynamicArrayPattern = dynamic_cast<PatternArrayDynamic *>(indexPattern))
searchScope = dynamicArrayPattern->getEntries();
else if (auto staticArrayPattern = dynamic_cast<PatternArrayStatic *>(indexPattern.get()))
else if (auto staticArrayPattern = dynamic_cast<PatternArrayStatic *>(indexPattern))
searchScope = { staticArrayPattern->getTemplate() };
}
@@ -272,7 +272,7 @@ namespace hex::pl {
[&](std::string &assignmentValue) {
if constexpr (isString) value = assignmentValue;
},
[&](std::shared_ptr<Pattern> &assignmentValue) { readVariable(evaluator, value, assignmentValue.get()); },
[&](Pattern *assignmentValue) { readVariable(evaluator, value, assignmentValue); },
[&](auto &&assignmentValue) { value = assignmentValue; } },
literal);
} else {

View File

@@ -45,7 +45,7 @@ namespace hex::pl {
evaluator->dataOffset() = std::visit(overloaded {
[this](const std::string &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a string", this); },
[this](const std::shared_ptr<Pattern> &) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); },
[this](Pattern *) -> u64 { LogConsole::abortEvaluation("placement offset cannot be a custom type", this); },
[](auto &&offset) -> u64 { return offset; } },
offset->getValue());
}

View File

@@ -233,7 +233,7 @@ namespace hex::pl {
}
protected:
void createDefaultEntry(const std::string &value, const Token::Literal &literal) const {
void createDefaultEntry(const std::string &value, Token::Literal &&literal) const {
ImGui::TableNextRow();
ImGui::TreeNodeEx(this->getDisplayName().c_str(), ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen | ImGuiTreeNodeFlags_SpanFullWidth | ImGuiTreeNodeFlags_AllowItemOverlap);
ImGui::TableNextColumn();
@@ -256,9 +256,9 @@ namespace hex::pl {
ImGui::TableNextColumn();
ImGui::TextFormatted("0x{0:04X}", this->getSize());
ImGui::TableNextColumn();
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getFormattedName());
ImGui::TextFormattedColored(ImColor(0xFF9BC64D), "{}", this->getTypeName().empty() ? this->getFormattedName() : this->getTypeName());
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", formatDisplayValue(value, literal));
ImGui::TextFormatted("{}", formatDisplayValue(value, std::move(literal)));
}
void drawCommentTooltip() const {

View File

@@ -58,7 +58,7 @@ namespace hex::pl {
ImGui::TextUnformatted("]");
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
}
if (open) {

View File

@@ -49,7 +49,7 @@ namespace hex::pl {
ImGui::TextUnformatted("]");
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
}
if (open) {

View File

@@ -43,7 +43,7 @@ namespace hex::pl {
u8 numBytes = (this->m_bitSize / 8) + 1;
u64 extractedValue = hex::extract(this->m_bitOffset + (this->m_bitSize - 1), this->m_bitOffset, value);
ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{0} (0x{1:X})", extractedValue, extractedValue), this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{0} (0x{1:X})", extractedValue, extractedValue), this));
}
}
@@ -120,7 +120,7 @@ namespace hex::pl {
valueString += hex::format("{0:02X} ", i);
valueString += "}";
ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue(valueString, this));
}
if (open) {

View File

@@ -34,7 +34,7 @@ namespace hex::pl {
return false;
},
[](std::string &) { return false; },
[](std::shared_ptr<Pattern> &) { return false; } },
[](Pattern *) { return false; } },
entryValueLiteral);
if (matches)
break;
@@ -63,7 +63,7 @@ namespace hex::pl {
ImGui::SameLine();
ImGui::TextUnformatted(Pattern::getTypeName().c_str());
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2), this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue(hex::format("{} (0x{:0{}X})", valueString.c_str(), value, this->getSize() * 2), this));
}
[[nodiscard]] std::string getFormattedName() const override {

View File

@@ -61,7 +61,7 @@ namespace hex::pl {
}
[[nodiscard]] std::string getFormattedName() const override {
std::string result = this->m_pointedAt->getFormattedName() + "* : ";
std::string result = this->getTypeName().empty() ? this->getFormattedName() : this->getTypeName() + "* : ";
switch (this->getSize()) {
case 1:
result += "u8";

View File

@@ -45,7 +45,7 @@ namespace hex::pl {
ImGui::SameLine();
ImGui::TextUnformatted(this->getTypeName().c_str());
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
}
if (open) {

View File

@@ -46,7 +46,7 @@ namespace hex::pl {
ImGui::TextUnformatted(Pattern::getTypeName().c_str());
ImGui::TableNextColumn();
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this->clone()));
ImGui::TextFormatted("{}", this->formatDisplayValue("{ ... }", this));
}
if (open) {

View File

@@ -139,7 +139,7 @@ namespace hex::pl {
std::string m_identifier;
};
using Literal = std::variant<char, bool, u128, i128, double, std::string, std::shared_ptr<Pattern>>;
using Literal = std::variant<char, bool, u128, i128, double, std::string, Pattern *>;
using ValueTypes = std::variant<Keyword, Identifier, Operator, Literal, ValueType, Separator>;
Token(Type type, auto value, u32 lineNumber) : type(type), value(value), lineNumber(lineNumber) {
@@ -164,7 +164,7 @@ namespace hex::pl {
static u128 literalToUnsigned(const pl::Token::Literal &literal) {
return std::visit(overloaded {
[](const std::string &) -> u128 { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](Pattern *) -> u128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> u128 { return result; } },
literal);
}
@@ -172,7 +172,7 @@ namespace hex::pl {
static i128 literalToSigned(const pl::Token::Literal &literal) {
return std::visit(overloaded {
[](const std::string &) -> i128 { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](Pattern *) -> i128 { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> i128 { return result; } },
literal);
}
@@ -180,7 +180,7 @@ namespace hex::pl {
static double literalToFloatingPoint(const pl::Token::Literal &literal) {
return std::visit(overloaded {
[](const std::string &) -> double { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::shared_ptr<Pattern> &) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](Pattern *) -> double { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> double { return result; } },
literal);
}
@@ -188,7 +188,7 @@ namespace hex::pl {
static bool literalToBoolean(const pl::Token::Literal &literal) {
return std::visit(overloaded {
[](const std::string &) -> bool { LogConsole::abortEvaluation("expected integral type, got string"); },
[](const std::unique_ptr<Pattern> &) -> bool { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](Pattern *) -> bool { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> bool { return result != 0; } },
literal);
}
@@ -203,7 +203,7 @@ namespace hex::pl {
[](i128 result) -> std::string { return hex::to_string(result); },
[](bool result) -> std::string { return result ? "true" : "false"; },
[](char result) -> std::string { return { 1, result }; },
[](const std::shared_ptr<Pattern> &) -> std::string { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](Pattern *) -> std::string { LogConsole::abortEvaluation("expected integral type, got custom type"); },
[](auto &&result) -> std::string { return std::to_string(result); } },
literal);
}

View File

@@ -3,6 +3,7 @@
#include <hex.hpp>
#include <functional>
#include <string>
#define IMGUI_DEFINE_MATH_OPERATORS
#include <imgui.h>
@@ -127,4 +128,7 @@ namespace ImGui {
ImGui::TextFormattedWrapped("{}", text);
ImGui::PopTextWrapPos();
}
bool InputText(const char* label, std::string &buffer, ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
bool InputTextMultiline(const char* label, std::string &buffer, const ImVec2& size = ImVec2(0, 0), ImGuiInputTextFlags flags = ImGuiInputTextFlags_None);
}

View File

@@ -15,6 +15,8 @@
#include <hex/pattern_language/patterns/pattern_string.hpp>
#include <hex/pattern_language/patterns/pattern_enum.hpp>
#include <hex/helpers/logger.hpp>
namespace hex::pl {
void Evaluator::createParameterPack(const std::string &name, const std::vector<Token::Literal> &values) {
@@ -39,7 +41,9 @@ namespace hex::pl {
bool referenceType = false;
if (type == nullptr) {
auto typePattern = type->createPatterns(this);
if (typePattern.empty()) {
// Handle auto variables
if (!value.has_value())
LogConsole::abortEvaluation("cannot determine type of auto variable", type);
@@ -56,13 +60,13 @@ namespace hex::pl {
pattern = std::unique_ptr<Pattern>(new PatternCharacter(this, 0));
else if (std::get_if<std::string>(&value.value()) != nullptr)
pattern = std::unique_ptr<Pattern>(new PatternString(this, 0, 1));
else if (auto patternValue = std::get_if<std::shared_ptr<Pattern>>(&value.value()); patternValue != nullptr) {
else if (auto patternValue = std::get_if<Pattern *>(&value.value()); patternValue != nullptr) {
pattern = (*patternValue)->clone();
referenceType = true;
} else
LogConsole::abortEvaluation("cannot determine type of auto variable", type);
} else {
pattern = std::move(type->createPatterns(this).front());
pattern = std::move(typePattern.front());
}
pattern->setVariableName(name);
@@ -127,7 +131,7 @@ namespace hex::pl {
else
LogConsole::abortEvaluation(hex::format("cannot cast type 'string' to type '{}'", pattern->getTypeName()));
},
[&](const std::shared_ptr<Pattern> &value) -> Token::Literal {
[&](Pattern *value) -> Token::Literal {
if (value->getTypeName() == pattern->getTypeName())
return value;
else

View File

@@ -558,4 +558,12 @@ namespace ImGui {
RenderRectFilledRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), 0.0f, fraction, style.FrameRounding);
}
bool InputText(const char *label, std::string &buffer, ImGuiInputTextFlags flags) {
return ImGui::InputText(label, buffer.data(), buffer.size(), ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
}
bool InputTextMultiline(const char *label, std::string &buffer, const ImVec2 &size, ImGuiInputTextFlags flags) {
return ImGui::InputTextMultiline(label, buffer.data(), buffer.size(), size, ImGuiInputTextFlags_CallbackResize | flags, ImGui::UpdateStringSizeCallback, &buffer);
}
}

View File

@@ -25,7 +25,7 @@ namespace hex::plugin::builtin {
auto &param = params[i];
std::visit(overloaded {
[&](const std::shared_ptr<pl::Pattern> &value) {
[&](pl::Pattern *value) {
formatArgs.push_back(value->toString(ctx->getProvider()));
},
[&](auto &&value) {

View File

@@ -314,7 +314,7 @@ namespace hex::plugin::builtin::prv {
#else
if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer.data(), this->m_pathBuffer.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &this->m_pathBuffer))
if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer))
this->m_path = this->m_pathBuffer;
#endif

View File

@@ -297,7 +297,7 @@ namespace hex::plugin::builtin::prv {
void GDBProvider::drawLoadInterface() {
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress.data(), this->m_ipAddress.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &this->m_ipAddress);
ImGui::InputText("hex.builtin.provider.gdb.ip"_lang, this->m_ipAddress);
ImGui::InputInt("hex.builtin.provider.gdb.port"_lang, &this->m_port, 0, 0);
ImGui::Separator();

View File

@@ -230,7 +230,7 @@ namespace hex::plugin::builtin {
"hex.builtin.setting.font", "hex.builtin.setting.font.font_path", "", [](auto name, nlohmann::json &setting) {
fontPath = static_cast<std::string>(setting);
if (ImGui::InputText("##font_path", fontPath.data(), fontPath.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &fontPath)) {
if (ImGui::InputText("##font_path", fontPath)) {
setting = fontPath;
return true;
}

View File

@@ -106,9 +106,9 @@ namespace hex::plugin::builtin {
static auto replacePattern = [] { std::string s; s.reserve(0xFFF); return s; }();
static auto regexOutput = [] { std::string s; s.reserve(0xFFF); return s; }();
bool changed1 = ImGui::InputText("hex.builtin.tools.regex_replacer.pattern"_lang, regexPattern.data(), regexPattern.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexPattern);
bool changed2 = ImGui::InputText("hex.builtin.tools.regex_replacer.replace"_lang, replacePattern.data(), replacePattern.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &replacePattern);
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput.data(), regexInput.size(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &regexInput);
bool changed1 = ImGui::InputText("hex.builtin.tools.regex_replacer.pattern"_lang, regexPattern);
bool changed2 = ImGui::InputText("hex.builtin.tools.regex_replacer.replace"_lang, replacePattern);
bool changed3 = ImGui::InputTextMultiline("hex.builtin.tools.regex_replacer.input"_lang, regexInput, ImVec2(0, 0));
if (changed1 || changed2 || changed3) {
try {
@@ -131,13 +131,7 @@ namespace hex::plugin::builtin {
void drawMathEvaluator() {
static std::vector<long double> mathHistory;
static std::string lastMathError;
static auto mathInput = [] {
std::string s;
s.reserve(0xFFFF);
std::memset(s.data(), 0x00, s.capacity());
return s;
}();
static std::string mathInput;
bool evaluate = false;
static MathEvaluator mathEvaluator = [&] {
@@ -415,7 +409,7 @@ namespace hex::plugin::builtin {
}
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
if (ImGui::InputText("##input", mathInput.data(), mathInput.size(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &mathInput)) {
if (ImGui::InputText("##input", mathInput, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
ImGui::SetKeyboardFocusHere();
evaluate = true;
}
@@ -681,7 +675,7 @@ namespace hex::plugin::builtin {
bool startSearch;
startSearch = ImGui::InputText("##search", searchString.data(), searchString.size(), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &searchString);
startSearch = ImGui::InputText("##search", searchString, ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::SameLine();
ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready || searchString.empty());
@@ -747,7 +741,7 @@ namespace hex::plugin::builtin {
{
ImGui::TextUnformatted("hex.builtin.tools.file_tools.shredder.input"_lang);
ImGui::SameLine();
ImGui::InputText("##path", selectedFile.data(), selectedFile.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::InputText("##path", selectedFile);
ImGui::SameLine();
if (ImGui::Button("...")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.shredder.picker"_lang, DialogMode::Open, {}, [](const auto &path) {
@@ -889,7 +883,7 @@ namespace hex::plugin::builtin {
if (ImGui::BeginChild("split_settings", { 0, ImGui::GetTextLineHeightWithSpacing() * 7 }, true, ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse)) {
ImGui::BeginDisabled(splitting);
{
ImGui::InputText("##path", selectedFile.data(), selectedFile.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &selectedFile);
ImGui::InputText("##path", selectedFile);
ImGui::SameLine();
if (ImGui::Button("...##input")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.input"_lang, DialogMode::Open, {}, [](const auto &path) {
@@ -899,7 +893,7 @@ namespace hex::plugin::builtin {
ImGui::SameLine();
ImGui::TextUnformatted("hex.builtin.tools.file_tools.splitter.input"_lang);
ImGui::InputText("##base_path", baseOutputPath.data(), baseOutputPath.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &baseOutputPath);
ImGui::InputText("##base_path", baseOutputPath);
ImGui::SameLine();
if (ImGui::Button("...##output")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.output"_lang, DialogMode::Save, {}, [](const auto &path) {
@@ -1052,7 +1046,7 @@ namespace hex::plugin::builtin {
ImGui::BeginDisabled(combining);
{
ImGui::InputText("##output_path", outputPath.data(), outputPath.size(), ImGuiInputTextFlags_CallbackEdit, ImGui::UpdateStringSizeCallback, &outputPath);
ImGui::InputText("##output_path", outputPath);
ImGui::SameLine();
if (ImGui::Button("...")) {
hex::openFileBrowser("hex.builtin.tools.file_tools.combiner.output.picker"_lang, DialogMode::Save, {}, [](const auto &path) {

View File

@@ -148,7 +148,7 @@ namespace hex::plugin::builtin {
if (locked)
ImGui::TextUnformatted(name.data());
else
ImGui::InputText("##nameInput", name.data(), name.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::InputText("##nameInput", name);
ImGui::NewLine();
ImGui::TextUnformatted("hex.builtin.view.bookmarks.header.comment"_lang);
@@ -157,7 +157,7 @@ namespace hex::plugin::builtin {
if (locked)
ImGui::TextFormattedWrapped("{}", comment.data());
else
ImGui::InputTextMultiline("##commentInput", comment.data(), comment.size(), ImVec2(0, 0), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &comment);
ImGui::InputTextMultiline("##commentInput", comment);
ImGui::NewLine();
}

View File

@@ -85,7 +85,7 @@ namespace hex::plugin::builtin {
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::SetKeyboardFocusHere();
if (ImGui::InputText("##InspectorLineEditing", this->m_editingValue.data(), this->m_editingValue.size(), ImGuiInputTextFlags_CallbackResize | ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll, ImGui::UpdateStringSizeCallback, &this->m_editingValue)) {
if (ImGui::InputText("##InspectorLineEditing", this->m_editingValue, ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
auto bytes = (*editingFunction)(this->m_editingValue, this->m_endian);
provider->write(this->m_startAddress, bytes.data(), bytes.size());

View File

@@ -503,7 +503,7 @@ namespace hex::plugin::builtin {
std::vector<u8> buffer(1024, 0x00);
size_t dataSize = provider->getSize();
for (u64 offset = 0; offset < dataSize; offset += 1024) {
size_t usedBufferSize = std::min<size_t>({ buffer.size(), dataSize - offset, string.size() });
size_t usedBufferSize = std::min<size_t>(buffer.size(), dataSize - offset);
provider->read(offset + provider->getBaseAddress() + provider->getCurrentPageAddress(), buffer.data(), usedBufferSize);
for (u64 i = 0; i < usedBufferSize; i++) {
@@ -544,7 +544,7 @@ namespace hex::plugin::builtin {
std::vector<u8> buffer(1024, 0x00);
size_t dataSize = provider->getSize();
for (u64 offset = 0; offset < dataSize; offset += 1024) {
size_t usedBufferSize = std::min<size_t>({ buffer.size(), dataSize - offset, hex.size() });
size_t usedBufferSize = std::min<size_t>(buffer.size(), dataSize - offset);
provider->read(offset + provider->getBaseAddress() + provider->getCurrentPageAddress(), buffer.data(), usedBufferSize);
for (u64 i = 0; i < usedBufferSize; i++) {

View File

@@ -421,7 +421,7 @@ namespace hex::plugin::builtin {
ImGui::TableNextColumn();
ImGui::PushItemWidth(ImGui::GetContentRegionAvailWidth());
ImGui::InputText("###name", name.data(), name.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &name);
ImGui::InputText("###name", name);
ImGui::PopItemWidth();
ImGui::TableNextColumn();
@@ -452,7 +452,7 @@ namespace hex::plugin::builtin {
case EnvVarType::String:
{
auto displayValue = hex::get_or<std::string>(value, "");
ImGui::InputText("###value", displayValue.data(), displayValue.size(), ImGuiInputTextFlags_CallbackResize, ImGui::UpdateStringSizeCallback, &displayValue);
ImGui::InputText("###value", displayValue);
value = displayValue;
break;
}

View File

@@ -28,7 +28,7 @@ static std::string format(hex::pl::Evaluator *ctx, const auto &params) {
auto &param = params[i];
std::visit(hex::overloaded {
[&](const std::shared_ptr<hex::pl::Pattern> &value) {
[&](hex::pl::Pattern *value) {
formatArgs.push_back(value->toString(ctx->getProvider()));
},
[&](auto &&value) {