From 0462cc3d0c821fa009cd19569f6333268e37001f Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 27 Mar 2022 00:01:28 +0100 Subject: [PATCH] sys: Enable -Wall, -Wextra, -Werror and fix all warnings on all Platforms (#483) * sys: Make ImHex compile with -Wall -Wextra -Werror * sys: Fixed various build errors on Linux * sys: Explicitly ignore return value of `system` function * sys: More fixes for the warnings GitHub Actions enables somehow * sys: More fixes * sys: Remove -Werror again to see all GitHub Actions warnings * sys: Hopefully fixed all remaining warnings * sys: Added back -Werror * git: Change windows icon in GitHub Actions --- .github/workflows/build.yml | 2 +- .../imgui/include/imgui_memory_editor.h | 6 +- lib/libimhex/CMakeLists.txt | 1 + lib/libimhex/include/hex.hpp | 2 + lib/libimhex/include/hex/api/event.hpp | 2 +- lib/libimhex/include/hex/api/keybinding.hpp | 2 +- .../include/hex/data_processor/node.hpp | 9 +- lib/libimhex/include/hex/helpers/fs.hpp | 9 +- .../include/hex/helpers/intrinsics.hpp | 6 +- lib/libimhex/include/hex/helpers/logger.hpp | 30 ++--- lib/libimhex/include/hex/helpers/utils.hpp | 9 +- .../hex/pattern_language/ast/ast_node.hpp | 18 ++- .../ast/ast_node_array_variable_decl.hpp | 2 +- .../pattern_language/ast/ast_node_cast.hpp | 2 - .../ast/ast_node_mathematical_expression.hpp | 54 +++++---- .../pattern_language/ast/ast_node_rvalue.hpp | 8 +- .../ast/ast_node_ternary_expression.hpp | 2 +- .../hex/pattern_language/evaluator.hpp | 13 ++- .../hex/pattern_language/pattern_drawer.hpp | 13 ++- .../hex/pattern_language/patterns/pattern.hpp | 6 +- .../patterns/pattern_bitfield.hpp | 2 - .../patterns/pattern_float.hpp | 10 +- .../include/hex/pattern_language/token.hpp | 1 - lib/libimhex/source/data_processor/node.cpp | 10 +- lib/libimhex/source/helpers/crypto.cpp | 104 +++++++++--------- lib/libimhex/source/helpers/file.cpp | 3 +- lib/libimhex/source/helpers/fs.cpp | 3 +- .../source/helpers/loader_script_handler.cpp | 11 ++ lib/libimhex/source/helpers/net.cpp | 11 +- lib/libimhex/source/helpers/socket.cpp | 2 +- lib/libimhex/source/helpers/utils.cpp | 21 ++-- .../source/pattern_language/lexer.cpp | 3 +- .../source/pattern_language/preprocessor.cpp | 2 +- lib/libimhex/source/providers/provider.cpp | 18 ++- .../source/ui/imgui_imhex_extensions.cpp | 3 - lib/libimhex/source/ui/view.cpp | 4 +- main/CMakeLists.txt | 5 + main/source/window/win_window.cpp | 7 +- main/source/window/window.cpp | 23 ++-- plugins/builtin/CMakeLists.txt | 1 + .../content/providers/file_provider.hpp | 2 +- .../include/content/views/view_diff.hpp | 2 +- plugins/builtin/include/math_evaluator.hpp | 9 +- .../source/content/data_formatters.cpp | 8 +- .../builtin/source/content/data_inspector.cpp | 45 +++++++- .../source/content/data_processor_nodes.cpp | 4 +- .../source/content/pl_builtin_functions.cpp | 86 ++++++++------- .../content/providers/disk_provider.cpp | 24 ++-- .../content/providers/file_provider.cpp | 4 +- .../source/content/providers/gdb_provider.cpp | 1 + .../source/content/settings_entries.cpp | 8 +- .../builtin/source/content/tools_entries.cpp | 47 ++++---- plugins/builtin/source/content/ui_items.cpp | 6 +- .../source/content/views/view_constants.cpp | 2 +- .../content/views/view_data_processor.cpp | 17 +-- .../source/content/views/view_diff.cpp | 16 ++- .../content/views/view_disassembler.cpp | 12 +- .../source/content/views/view_hashes.cpp | 6 +- .../source/content/views/view_hex_editor.cpp | 38 ++++--- .../source/content/views/view_information.cpp | 3 +- .../content/views/view_pattern_editor.cpp | 10 +- .../source/content/views/view_strings.cpp | 4 +- .../source/content/views/view_yara.cpp | 18 +-- .../builtin/source/content/welcome_screen.cpp | 4 +- plugins/builtin/source/math_evaluator.cpp | 10 +- plugins/example_cpp/CMakeLists.txt | 3 +- plugins/windows/CMakeLists.txt | 1 + plugins/windows/source/content/ui_items.cpp | 27 ++--- .../windows/source/views/view_tty_console.cpp | 15 ++- 69 files changed, 502 insertions(+), 370 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 29ee96ccc..6e3dbba00 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,7 +12,7 @@ jobs: # Windows build win: runs-on: windows-2022 - name: 🟦 Windows MINGW64 + name: 🪟 Windows MINGW64 defaults: run: shell: msys2 {0} diff --git a/lib/external/imgui/include/imgui_memory_editor.h b/lib/external/imgui/include/imgui_memory_editor.h index adee7d0ff..a2517567b 100644 --- a/lib/external/imgui/include/imgui_memory_editor.h +++ b/lib/external/imgui/include/imgui_memory_editor.h @@ -50,6 +50,7 @@ #include #include #include +#include #include @@ -278,7 +279,7 @@ struct MemoryEditor if (OptMidColsCount > 0) byte_pos_x += (float)(i / OptMidColsCount) * s.SpacingBetweenMidCols; ImGui::SameLine(byte_pos_x); - ImGui::Text("%02llX", i + (base_display_addr % Cols)); + ImGui::TextFormatted("{:02X}", i + (base_display_addr % Cols)); } ImGui::EndChild(); @@ -324,7 +325,7 @@ struct MemoryEditor else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_PageDown)) && DataEditingAddr < mem_size - 1) { data_editing_addr_next = std::min(mem_size - 1, DataEditingAddr + visible_count); DataEditingTakeFocus = true; } else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_Home)) && DataEditingAddr > 0) { data_editing_addr_next = 0; DataEditingTakeFocus = true; } else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_End)) && DataEditingAddr < mem_size - 1) { data_editing_addr_next = mem_size - 1; DataEditingTakeFocus = true; } - } else if (DataPreviewAddr != -1) { + } else if (DataPreviewAddr != (size_t)-1) { if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_UpArrow)) && DataPreviewAddr >= (size_t)Cols) { DataPreviewAddr = data_preview_addr_next = DataPreviewAddr - Cols; if (!ImGui::GetIO().KeyShift) DataPreviewAddrEnd = DataPreviewAddr; } else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_DownArrow)) && DataPreviewAddr < mem_size - Cols) { DataPreviewAddr = data_preview_addr_next = DataPreviewAddr + Cols; if (!ImGui::GetIO().KeyShift) DataPreviewAddrEnd = DataPreviewAddr; } else if (ImGui::IsKeyPressed(ImGui::GetKeyIndex(ImGuiKey_LeftArrow)) && DataPreviewAddr > 0) { DataPreviewAddr = data_preview_addr_next = DataPreviewAddr - 1; if (!ImGui::GetIO().KeyShift) DataPreviewAddrEnd = DataPreviewAddr; } @@ -717,7 +718,6 @@ struct MemoryEditor void DrawOptionsLine(const Sizes& s, void* mem_data, size_t mem_size, size_t base_display_addr) { IM_UNUSED(mem_data); - ImGuiStyle& style = ImGui::GetStyle(); const char* format_range = OptUpperCaseHex ? "Range 0x%0*" _PRISizeT "X..0x%0*" _PRISizeT "X" : "Range 0x%0*" _PRISizeT "x..0x%0*" _PRISizeT "x"; const char* format_selection = OptUpperCaseHex ? "Selection 0x%0*" _PRISizeT "X..0x%0*" _PRISizeT "X (%ld [0x%lX] %s)" : "Range 0x%0*" _PRISizeT "x..0x%0*" _PRISizeT "x (%ld [0x%lX] %s)"; diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 681a5b545..6f2f80060 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -156,6 +156,7 @@ add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") add_library(libimhex SHARED ${LIBIMHEX_SOURCES}) set_target_properties(libimhex PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_options(libimhex PRIVATE -Wall -Wextra -Werror) target_include_directories(libimhex PUBLIC include ${XDGPP_INCLUDE_DIRS} ${MBEDTLS_INCLUDE_DIRS} ${CAPSTONE_INCLUDE_DIRS} ${MAGIC_INCLUDE_DIRS} ${Python_INCLUDE_DIRS} ${LLVM_INCLUDE_DIRS} ${FMT_INCLUDE_DIRS} ${CURL_INCLUDE_DIRS} ${YARA_INCLUDE_DIRS}) target_link_directories(libimhex PUBLIC ${MBEDTLS_LIBRARY_DIR} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS}) diff --git a/lib/libimhex/include/hex.hpp b/lib/libimhex/include/hex.hpp index 0f4c0ce06..8e3294bc6 100644 --- a/lib/libimhex/include/hex.hpp +++ b/lib/libimhex/include/hex.hpp @@ -3,6 +3,8 @@ #include #include +#include + constexpr static const auto ImHexApiURL = "https://api.werwolv.net/imhex"; constexpr static const auto GitHubApiURL = "https://api.github.com/repos/WerWolv/ImHex"; diff --git a/lib/libimhex/include/hex/api/event.hpp b/lib/libimhex/include/hex/api/event.hpp index d9c8508ac..be323ee7c 100644 --- a/lib/libimhex/include/hex/api/event.hpp +++ b/lib/libimhex/include/hex/api/event.hpp @@ -16,7 +16,7 @@ explicit event_name(Callback func) noexcept : Event(std::move(func)) { } \ } -class GLFWwindow; +struct GLFWwindow; namespace hex { diff --git a/lib/libimhex/include/hex/api/keybinding.hpp b/lib/libimhex/include/hex/api/keybinding.hpp index a53b8e988..359c53642 100644 --- a/lib/libimhex/include/hex/api/keybinding.hpp +++ b/lib/libimhex/include/hex/api/keybinding.hpp @@ -11,7 +11,7 @@ struct ImGuiWindow; namespace hex { - struct View; + class View; enum class Keys { diff --git a/lib/libimhex/include/hex/data_processor/node.hpp b/lib/libimhex/include/hex/data_processor/node.hpp index c2e87c451..abb08a1c9 100644 --- a/lib/libimhex/include/hex/data_processor/node.hpp +++ b/lib/libimhex/include/hex/data_processor/node.hpp @@ -1,6 +1,7 @@ #pragma once #include +#include #include #include @@ -38,8 +39,8 @@ namespace hex::dp { virtual void drawNode() { } virtual void process() = 0; - virtual void store(nlohmann::json &j) { } - virtual void load(nlohmann::json &j) { } + virtual void store(nlohmann::json &j) { hex::unused(j); } + virtual void load(nlohmann::json &j) { hex::unused(j); } using NodeError = std::pair; @@ -90,11 +91,11 @@ namespace hex::dp { } std::vector getBufferOnInput(u32 index); - u64 getIntegerOnInput(u32 index); + i64 getIntegerOnInput(u32 index); float getFloatOnInput(u32 index); void setBufferOnOutput(u32 index, const std::vector &data); - void setIntegerOnOutput(u32 index, u64 integer); + void setIntegerOnOutput(u32 index, i64 integer); void setFloatOnOutput(u32 index, float floatingPoint); void setOverlayData(u64 address, const std::vector &data); diff --git a/lib/libimhex/include/hex/helpers/fs.hpp b/lib/libimhex/include/hex/helpers/fs.hpp index f899f53ce..d72d27807 100644 --- a/lib/libimhex/include/hex/helpers/fs.hpp +++ b/lib/libimhex/include/hex/helpers/fs.hpp @@ -14,36 +14,43 @@ namespace std::fs { namespace hex::fs { + [[maybe_unused]] static inline bool exists(const std::fs::path &path) { std::error_code error; return std::filesystem::exists(path, error) && !error; } + [[maybe_unused]] static inline bool createDirectories(const std::fs::path &path) { std::error_code error; return std::filesystem::create_directories(path, error) && !error; } + [[maybe_unused]] static inline bool isRegularFile(const std::fs::path &path) { std::error_code error; return std::filesystem::is_regular_file(path, error) && !error; } + [[maybe_unused]] static inline bool copyFile(const std::fs::path &from, const std::fs::path &to, std::fs::copy_options = std::fs::copy_options::none) { std::error_code error; return std::filesystem::copy_file(from, to, error) && !error; } + [[maybe_unused]] static inline bool isDirectory(const std::fs::path &path) { std::error_code error; return std::filesystem::is_directory(path, error) && !error; } + [[maybe_unused]] static inline bool remove(const std::fs::path &path) { std::error_code error; return std::filesystem::remove(path, error) && !error; } + [[maybe_unused]] static inline uintmax_t getFileSize(const std::fs::path &path) { std::error_code error; auto size = std::filesystem::file_size(path, error); @@ -61,7 +68,7 @@ namespace hex::fs { Folder }; - bool openFileBrowser(const std::string &title, DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath = {}); + bool openFileBrowser(DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath = {}); enum class ImHexPath { diff --git a/lib/libimhex/include/hex/helpers/intrinsics.hpp b/lib/libimhex/include/hex/helpers/intrinsics.hpp index 97d5f82d5..b1a49a3fb 100644 --- a/lib/libimhex/include/hex/helpers/intrinsics.hpp +++ b/lib/libimhex/include/hex/helpers/intrinsics.hpp @@ -1,11 +1,13 @@ #pragma once -#include - namespace hex { [[noreturn]] inline void unreachable() { __builtin_unreachable(); } + inline void unused(auto && ... x) { + ((void)x, ...); + } + } \ No newline at end of file diff --git a/lib/libimhex/include/hex/helpers/logger.hpp b/lib/libimhex/include/hex/helpers/logger.hpp index 79cece46c..69b0f6a56 100644 --- a/lib/libimhex/include/hex/helpers/logger.hpp +++ b/lib/libimhex/include/hex/helpers/logger.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include #include @@ -13,7 +15,7 @@ namespace hex::log { namespace { - void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { + [[maybe_unused]] void printPrefix(FILE *dest, const fmt::text_style &ts, const std::string &level) { const auto now = fmt::localtime(std::chrono::system_clock::now()); fmt::print(dest, "[{0:%H:%M:%S}] ", now); @@ -27,7 +29,7 @@ namespace hex::log { } template - void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto... args) { + [[maybe_unused]] void print(const fmt::text_style &ts, const std::string &level, const std::string &fmt, auto... args) { auto dest = getDestination(); printPrefix(dest, ts, level); @@ -37,28 +39,30 @@ namespace hex::log { } - void debug(const std::string &fmt, auto &&...args) { + [[maybe_unused]] void debug(const std::string &fmt, auto &&...args) { #if defined(DEBUG) - log::print(fg(fmt::color::green_yellow) | fmt::emphasis::bold, "[DEBUG]", fmt, args...); + print(fg(fmt::color::green_yellow) | fmt::emphasis::bold, "[DEBUG]", fmt, args...); +#else + hex::unused(fmt, args...); #endif } - void info(const std::string &fmt, auto &&...args) { - log::print(fg(fmt::color::cadet_blue) | fmt::emphasis::bold, "[INFO] ", fmt, args...); + [[maybe_unused]] void info(const std::string &fmt, auto &&...args) { + print(fg(fmt::color::cadet_blue) | fmt::emphasis::bold, "[INFO] ", fmt, args...); } - void warn(const std::string &fmt, auto &&...args) { - log::print(fg(fmt::color::orange) | fmt::emphasis::bold, "[WARN] ", fmt, args...); + [[maybe_unused]] void warn(const std::string &fmt, auto &&...args) { + print(fg(fmt::color::orange) | fmt::emphasis::bold, "[WARN] ", fmt, args...); } - void error(const std::string &fmt, auto &&...args) { - log::print(fg(fmt::color::red) | fmt::emphasis::bold, "[ERROR]", fmt, args...); + [[maybe_unused]] void error(const std::string &fmt, auto &&...args) { + print(fg(fmt::color::red) | fmt::emphasis::bold, "[ERROR]", fmt, args...); } - void fatal(const std::string &fmt, auto &&...args) { - log::print(fg(fmt::color::purple) | fmt::emphasis::bold, "[FATAL]", fmt, args...); + [[maybe_unused]] void fatal(const std::string &fmt, auto &&...args) { + print(fg(fmt::color::purple) | fmt::emphasis::bold, "[FATAL]", fmt, args...); } - void redirectToFile(); + [[maybe_unused]] void redirectToFile(); } \ No newline at end of file diff --git a/lib/libimhex/include/hex/helpers/utils.hpp b/lib/libimhex/include/hex/helpers/utils.hpp index 4f13cd859..2b129567f 100644 --- a/lib/libimhex/include/hex/helpers/utils.hpp +++ b/lib/libimhex/include/hex/helpers/utils.hpp @@ -55,9 +55,6 @@ namespace hex { [[nodiscard]] inline u64 extract(u32 from, u32 to, const std::vector &bytes) { u8 index = 0; while (from > 32 && to > 32) { - if (from - 8 < 0 || to - 8 < 0) - return 0; - from -= 8; to -= 8; index++; @@ -297,7 +294,7 @@ namespace hex { namespace scope_guard { #define SCOPE_GUARD ::hex::scope_guard::ScopeGuardOnExit() + [&]() -#define ON_SCOPE_EXIT auto ANONYMOUS_VARIABLE(SCOPE_EXIT_) = SCOPE_GUARD +#define ON_SCOPE_EXIT [[maybe_unused]] auto ANONYMOUS_VARIABLE(SCOPE_EXIT_) = SCOPE_GUARD template class ScopeGuard { @@ -332,7 +329,7 @@ namespace hex { namespace first_time_exec { -#define FIRST_TIME static auto ANONYMOUS_VARIABLE(FIRST_TIME_) = ::hex::first_time_exec::FirstTimeExecutor() + [&]() +#define FIRST_TIME [[maybe_unused]] static auto ANONYMOUS_VARIABLE(FIRST_TIME_) = ::hex::first_time_exec::FirstTimeExecutor() + [&]() template class FirstTimeExecute { @@ -355,7 +352,7 @@ namespace hex { namespace final_cleanup { -#define FINAL_CLEANUP static auto ANONYMOUS_VARIABLE(ON_EXIT_) = ::hex::final_cleanup::FinalCleanupExecutor() + [&]() +#define FINAL_CLEANUP [[maybe_unused]] static auto ANONYMOUS_VARIABLE(ON_EXIT_) = ::hex::final_cleanup::FinalCleanupExecutor() + [&]() template class FinalCleanupExecute { diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node.hpp index 3a34c20ca..3ecedb913 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node.hpp @@ -22,12 +22,24 @@ namespace hex::pl { [[maybe_unused]] constexpr void setLineNumber(u32 lineNumber) { this->m_lineNumber = lineNumber; } - [[nodiscard]] virtual std::unique_ptr evaluate(Evaluator *evaluator) const { return this->clone(); } + [[nodiscard]] virtual std::unique_ptr evaluate(Evaluator *evaluator) const { + hex::unused(evaluator); - [[nodiscard]] virtual std::vector> createPatterns(Evaluator *evaluator) const { return {}; } + return this->clone(); + } + + [[nodiscard]] virtual std::vector> createPatterns(Evaluator *evaluator) const { + hex::unused(evaluator); + + return {}; + } using FunctionResult = std::optional; - virtual FunctionResult execute(Evaluator *evaluator) const { LogConsole::abortEvaluation("cannot execute non-function statement", this); } + virtual FunctionResult execute(Evaluator *evaluator) const { + hex::unused(evaluator); + + LogConsole::abortEvaluation("cannot execute non-function statement", this); + } private: u32 m_lineNumber = 1; diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp index 5dbc710c2..23727bf19 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_array_variable_decl.hpp @@ -305,7 +305,7 @@ namespace hex::pl { arrayPattern->setEntries(std::move(entries)); arrayPattern->setSize(size); - return std::move(arrayPattern); + return arrayPattern; } }; diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp index c8198b513..f0ff2a43b 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_cast.hpp @@ -24,8 +24,6 @@ namespace hex::pl { auto literal = dynamic_cast(evaluatedValue.get()); auto type = dynamic_cast(evaluatedType.get())->getType(); - auto startOffset = evaluator->dataOffset(); - auto typePatterns = this->m_type->createPatterns(evaluator); auto &typePattern = typePatterns.front(); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp index d3e954464..4cc0ce9db 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_mathematical_expression.hpp @@ -6,14 +6,17 @@ namespace hex::pl { #define FLOAT_BIT_OPERATION(name) \ auto name(hex::floating_point auto left, auto right) const { \ + hex::unused(left, right); \ LogConsole::abortEvaluation("invalid floating point operation", this); \ return 0; \ } \ auto name(auto left, hex::floating_point auto right) const { \ + hex::unused(left, right); \ LogConsole::abortEvaluation("invalid floating point operation", this); \ return 0; \ } \ auto name(hex::floating_point auto left, hex::floating_point auto right) const { \ + hex::unused(left, right); \ LogConsole::abortEvaluation("invalid floating point operation", this); \ return 0; \ } \ @@ -42,7 +45,9 @@ namespace hex::pl { } FLOAT_BIT_OPERATION(bitNot) { - return ~right; + hex::unused(left); + + return ~static_cast(right); } FLOAT_BIT_OPERATION(modulus) { @@ -76,27 +81,30 @@ namespace hex::pl { return std::unique_ptr(std::visit(overloaded { // TODO: :notlikethis: - [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](u128, Pattern *const ) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](i128, Pattern *const &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](double, Pattern *const &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](char, Pattern *const &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](bool, Pattern *const &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](const std::string &, Pattern *const &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, u128) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, i128) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, double) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, char) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, bool) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, const std::string &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, + [this](Pattern *const &, Pattern *const &) -> 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](auto &&, const std::string &) -> ASTNode * { LogConsole::abortEvaluation("invalid operand used in mathematical expression", this); }, [this](const std::string &left, auto &&right) -> ASTNode * { switch (this->getOperator()) { case Token::Operator::Star: { + if (static_cast(right) < 0) + LogConsole::abortEvaluation("cannot repeat string a negative number of times", this); + std::string result; - for (auto i = 0; i < right; i++) + for (u128 i = 0; i < static_cast(right); i++) result += left; return new ASTNodeLiteral(result); } @@ -167,21 +175,21 @@ namespace hex::pl { case Token::Operator::BitNot: return new ASTNodeLiteral(bitNot(left, right)); case Token::Operator::BoolEquals: - return new ASTNodeLiteral(bool(left == right)); + return new ASTNodeLiteral(bool(left == static_cast(right))); case Token::Operator::BoolNotEquals: - return new ASTNodeLiteral(bool(left != right)); + return new ASTNodeLiteral(bool(left != static_cast(right))); case Token::Operator::BoolGreaterThan: - return new ASTNodeLiteral(bool(left > right)); + return new ASTNodeLiteral(bool(left > static_cast(right))); case Token::Operator::BoolLessThan: - return new ASTNodeLiteral(bool(left < right)); + return new ASTNodeLiteral(bool(left < static_cast(right))); case Token::Operator::BoolGreaterThanOrEquals: - return new ASTNodeLiteral(bool(left >= right)); + return new ASTNodeLiteral(bool(left >= static_cast(right))); case Token::Operator::BoolLessThanOrEquals: - return new ASTNodeLiteral(bool(left <= right)); + return new ASTNodeLiteral(bool(left <= static_cast(right))); case Token::Operator::BoolAnd: return new ASTNodeLiteral(bool(left && right)); case Token::Operator::BoolXor: - return new ASTNodeLiteral(bool(left && !right || !left && right)); + return new ASTNodeLiteral(bool((left && !right) || (!left && right))); case Token::Operator::BoolOr: return new ASTNodeLiteral(bool(left || right)); case Token::Operator::BoolNot: diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp index f4cee2de0..544d9a551 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_rvalue.hpp @@ -105,7 +105,7 @@ namespace hex::pl { readVariable(evaluator, value, assignmentValue); }, - [&, this](auto &&assignmentValue) { LogConsole::abortEvaluation(hex::format("cannot assign '{}' to string", pattern->getTypeName()), this); } }, + [&, this](auto &&) { LogConsole::abortEvaluation(hex::format("cannot assign '{}' to string", pattern->getTypeName()), this); } }, variableValue); } else { value.resize(pattern->getSize()); @@ -158,7 +158,7 @@ namespace hex::pl { if (name == "parent") { scopeIndex--; - if (-scopeIndex >= evaluator->getScopeCount()) + if (static_cast(std::abs(scopeIndex)) >= evaluator->getScopeCount()) LogConsole::abortEvaluation("cannot access parent of global scope", this); searchScope = *evaluator->getScope(scopeIndex).scope; @@ -208,12 +208,12 @@ namespace hex::pl { [this](Pattern *) { LogConsole::abortEvaluation("cannot use custom type to index array", this); }, [&, this](auto &&index) { if (auto dynamicArrayPattern = dynamic_cast(currPattern.get())) { - if (index >= searchScope.size() || index < 0) + if (static_cast(index) >= searchScope.size() || static_cast(index) < 0) LogConsole::abortEvaluation("array index out of bounds", this); currPattern = searchScope[index]->clone(); } else if (auto staticArrayPattern = dynamic_cast(currPattern.get())) { - if (index >= staticArrayPattern->getEntryCount() || index < 0) + if (static_cast(index) >= staticArrayPattern->getEntryCount() || static_cast(index) < 0) LogConsole::abortEvaluation("array index out of bounds", this); auto newPattern = searchScope.front()->clone(); diff --git a/lib/libimhex/include/hex/pattern_language/ast/ast_node_ternary_expression.hpp b/lib/libimhex/include/hex/pattern_language/ast/ast_node_ternary_expression.hpp index aecfe1171..46ec4dde6 100644 --- a/lib/libimhex/include/hex/pattern_language/ast/ast_node_ternary_expression.hpp +++ b/lib/libimhex/include/hex/pattern_language/ast/ast_node_ternary_expression.hpp @@ -40,7 +40,7 @@ namespace hex::pl { return std::visit(overloaded { [condition](const T &second, const T &third) -> std::unique_ptr { return std::unique_ptr(new ASTNodeLiteral(condition ? second : third)); }, - [this](auto &&second, auto &&third) -> std::unique_ptr { LogConsole::abortEvaluation("operands to ternary expression have different types", this); } }, + [this](auto &&, auto &&) -> std::unique_ptr { LogConsole::abortEvaluation("operands to ternary expression have different types", this); } }, second->getValue(), third->getValue()); } diff --git a/lib/libimhex/include/hex/pattern_language/evaluator.hpp b/lib/libimhex/include/hex/pattern_language/evaluator.hpp index ec1603853..978a2facd 100644 --- a/lib/libimhex/include/hex/pattern_language/evaluator.hpp +++ b/lib/libimhex/include/hex/pattern_language/evaluator.hpp @@ -64,13 +64,14 @@ namespace hex::pl { std::vector> *scope; std::optional parameterPack; }; + void pushScope(Pattern *parent, std::vector> &scope) { if (this->m_scopes.size() > this->getEvaluationDepth()) LogConsole::abortEvaluation(hex::format("evaluation depth exceeded set limit of {}", this->getEvaluationDepth())); this->handleAbort(); - this->m_scopes.push_back({ parent, &scope }); + this->m_scopes.push_back({ parent, &scope, { } }); } void popScope() { @@ -85,19 +86,19 @@ namespace hex::pl { return this->m_scopes[this->m_scopes.size() - 1 + index]; } - Scope &getGlobalScope() { + [[nodiscard]] Scope &getGlobalScope() { return this->m_scopes.front(); } - const Scope &getGlobalScope() const { + [[nodiscard]] const Scope &getGlobalScope() const { return this->m_scopes.front(); } - size_t getScopeCount() { + [[nodiscard]] size_t getScopeCount() { return this->m_scopes.size(); } - bool isGlobalScope() { + [[nodiscard]] bool isGlobalScope() { return this->m_scopes.size() == 1; } @@ -179,7 +180,7 @@ namespace hex::pl { bool addCustomFunction(const std::string &name, ContentRegistry::PatternLanguage::ParameterCount numParams, std::vector defaultParameters, const ContentRegistry::PatternLanguage::Callback &function) { const auto [iter, inserted] = this->m_customFunctions.insert({ - name, {numParams, std::move(defaultParameters), function} + name, {numParams, std::move(defaultParameters), function, false} }); return inserted; diff --git a/lib/libimhex/include/hex/pattern_language/pattern_drawer.hpp b/lib/libimhex/include/hex/pattern_language/pattern_drawer.hpp index 69225a0bb..b3cfd9c74 100644 --- a/lib/libimhex/include/hex/pattern_language/pattern_drawer.hpp +++ b/lib/libimhex/include/hex/pattern_language/pattern_drawer.hpp @@ -138,7 +138,7 @@ namespace hex::pl { for (auto &[entryValueLiteral, entryName] : pattern.getEnumValues()) { auto visitor = overloaded { [&, name = entryName](auto &entryValue) { - if (value == entryValue) { + if (static_cast(value) == entryValue) { valueString += name; foundValue = true; return true; @@ -175,17 +175,20 @@ namespace hex::pl { void visit(PatternFloat& pattern) override { if (pattern.getSize() == 4) { float f32 = pattern.getValue(m_provider); - u32 data = *reinterpret_cast(&f32); - this->createDefaultEntry(pattern, hex::format("{:e} (0x{:0{}X})", f32, data, pattern.getSize() * 2), f32); + u32 integerResult = 0; + std::memcpy(&integerResult, &f32, sizeof(float)); + this->createDefaultEntry(pattern, hex::format("{:e} (0x{:0{}X})", f32, integerResult, pattern.getSize() * 2), f32); } else if (pattern.getSize() == 8) { double f64 = pattern.getValue(m_provider); - u64 data = *reinterpret_cast(&f64); - this->createDefaultEntry(pattern, hex::format("{:e} (0x{:0{}X})", f64, data, pattern.getSize() * 2), f64); + u64 integerResult = 0; + std::memcpy(&integerResult, &f64, sizeof(double)); + this->createDefaultEntry(pattern, hex::format("{:e} (0x{:0{}X})", f64, integerResult, pattern.getSize() * 2), f64); } } void visit(PatternPadding& pattern) override { // Do nothing + hex::unused(pattern); } void visit(PatternPointer& pattern) override { diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp index 0ef77e53b..3c8aa93ba 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern.hpp @@ -126,9 +126,13 @@ namespace hex::pl { this->getEvaluator()->handleAbort(); } - virtual void sort(ImGuiTableSortSpecs *sortSpecs, prv::Provider *provider) { } + virtual void sort(ImGuiTableSortSpecs *sortSpecs, prv::Provider *provider) { + hex::unused(sortSpecs, provider); + } [[nodiscard]] virtual std::string toString(prv::Provider *provider) const { + hex::unused(provider); + return hex::format("{} {} @ 0x{:X}", this->getTypeName(), this->getVariableName(), this->getOffset()); } diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp index 4a3fd4148..bde54268b 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_bitfield.hpp @@ -21,8 +21,6 @@ namespace hex::pl { if (this->m_bitField->getEndian() != std::endian::native) std::reverse(value.begin(), value.end()); - u8 numBytes = (this->m_bitSize / 8) + 1; - return hex::extract(this->m_bitOffset + (this->m_bitSize - 1), this->m_bitOffset, value); } diff --git a/lib/libimhex/include/hex/pattern_language/patterns/pattern_float.hpp b/lib/libimhex/include/hex/pattern_language/patterns/pattern_float.hpp index 2cd7d3848..aa01fe94f 100644 --- a/lib/libimhex/include/hex/pattern_language/patterns/pattern_float.hpp +++ b/lib/libimhex/include/hex/pattern_language/patterns/pattern_float.hpp @@ -18,12 +18,18 @@ namespace hex::pl { u32 data = 0; provider->read(this->getOffset(), &data, 4); data = hex::changeEndianess(data, 4, this->getEndian()); - return *reinterpret_cast(&data); + + float result = 0; + std::memcpy(&result, &data, sizeof(float)); + return result; } else if (this->getSize() == 8) { u64 data = 0; provider->read(this->getOffset(), &data, 8); data = hex::changeEndianess(data, 8, this->getEndian()); - return *reinterpret_cast(&data); + + double result = 0; + std::memcpy(&result, &data, sizeof(double)); + return result; } else { assert(false); return std::numeric_limits::quiet_NaN(); diff --git a/lib/libimhex/include/hex/pattern_language/token.hpp b/lib/libimhex/include/hex/pattern_language/token.hpp index 78562550c..d8269bd38 100644 --- a/lib/libimhex/include/hex/pattern_language/token.hpp +++ b/lib/libimhex/include/hex/pattern_language/token.hpp @@ -132,7 +132,6 @@ namespace hex::pl { [[nodiscard]] const std::string &get() const { return this->m_identifier; } - auto operator<=>(const Identifier &) const = default; bool operator==(const Identifier &) const = default; private: diff --git a/lib/libimhex/source/data_processor/node.cpp b/lib/libimhex/source/data_processor/node.cpp index ca0619c60..ddaf2998c 100644 --- a/lib/libimhex/source/data_processor/node.cpp +++ b/lib/libimhex/source/data_processor/node.cpp @@ -34,7 +34,7 @@ namespace hex::dp { return outputData.value(); } - u64 Node::getIntegerOnInput(u32 index) { + i64 Node::getIntegerOnInput(u32 index) { auto attribute = this->getConnectedInputAttribute(index); if (attribute == nullptr) @@ -54,7 +54,7 @@ namespace hex::dp { if (outputData->size() < sizeof(u64)) throw std::runtime_error("Not enough data provided for integer"); - return *reinterpret_cast(outputData->data()); + return *reinterpret_cast(outputData->data()); } float Node::getFloatOnInput(u32 index) { @@ -77,7 +77,9 @@ namespace hex::dp { if (outputData->size() < sizeof(float)) throw std::runtime_error("Not enough data provided for float"); - return *reinterpret_cast(outputData->data()); + float result = 0; + std::memcpy(&result, outputData->data(), sizeof(float)); + return result; } void Node::setBufferOnOutput(u32 index, const std::vector &data) { @@ -92,7 +94,7 @@ namespace hex::dp { attribute.getOutputData() = data; } - void Node::setIntegerOnOutput(u32 index, u64 integer) { + void Node::setIntegerOnOutput(u32 index, i64 integer) { if (index >= this->getAttributes().size()) throw std::runtime_error("Attribute index out of bounds!"); diff --git a/lib/libimhex/source/helpers/crypto.cpp b/lib/libimhex/source/helpers/crypto.cpp index 81da62d83..5e9d0b83b 100644 --- a/lib/libimhex/source/helpers/crypto.cpp +++ b/lib/libimhex/source/helpers/crypto.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #if MBEDTLS_VERSION_MAJOR <= 2 @@ -82,91 +83,90 @@ namespace hex::crypt { } } + template requires (std::has_single_bit(NumBits)) class Crc { // use reflected algorithm, so we reflect only if refin / refout is FALSE // mask values, 0b1 << 64 is UB, so use 0b10 << 63 public: - using calc_type = uint64_t; + constexpr Crc(u64 polynomial, u64 init, u64 xorOut, bool reflectInput, bool reflectOutput) + : m_value(0x00), m_init(init & ((0b10ull << (NumBits - 1)) - 1)), m_xorOut(xorOut & ((0b10ull << (NumBits - 1)) - 1)), + m_reflectInput(reflectInput), m_reflectOutput(reflectOutput), + m_table([polynomial]() { + auto reflectedPoly = reflect(polynomial & ((0b10ull << (NumBits - 1)) - 1), NumBits); + std::array table = { 0 }; - Crc(int bits, calc_type polynomial, calc_type init, calc_type xorout, bool refin, bool refout) : m_bits(bits), - m_init(init & ((0b10ull << (bits - 1)) - 1)), - m_xorout(xorout & ((0b10ull << (bits - 1)) - 1)), - m_refin(refin), - m_refout(refout), - table([polynomial, bits]() { - auto reflectedpoly = reflect(polynomial & ((0b10ull << (bits - 1)) - 1), bits); - std::array table = { 0 }; + for (uint32_t i = 0; i < 256; i++) { + uint64_t c = i; + for (std::size_t j = 0; j < 8; j++) { + if (c & 0b1) + c = reflectedPoly ^ (c >> 1); + else + c >>= 1; + } + table[i] = c; + } - for (uint32_t i = 0; i < 256; i++) { - uint64_t c = i; - for (std::size_t j = 0; j < 8; j++) { - if (c & 0b1) - c = reflectedpoly ^ (c >> 1); - else - c >>= 1; - } - table[i] = c; - } - - return table; - }()) { + return table; + }()) { reset(); }; - void reset() { - c = reflect(m_init, m_bits); + constexpr void reset() { + this->m_value = reflect(m_init, NumBits); } - void processBytes(const unsigned char *data, std::size_t size) { + constexpr void processBytes(const unsigned char *data, std::size_t size) { for (std::size_t i = 0; i < size; i++) { - unsigned char d; - if (m_refin) - d = data[i]; + u8 byte; + if (this->m_reflectInput) + byte = data[i]; else - d = reflect(data[i]); + byte = reflect(data[i]); - c = table[(c ^ d) & 0xFFL] ^ (c >> 8); + this->m_value = this->m_table[(this->m_value ^ byte) & 0xFFL] ^ (this->m_value >> 8); } } - calc_type checksum() const { - if (m_refout) - return c ^ m_xorout; + [[nodiscard]] + constexpr u64 checksum() const { + if (this->m_reflectOutput) + return this->m_value ^ m_xorOut; else - return reflect(c, m_bits) ^ m_xorout; + return reflect(this->m_value, NumBits) ^ m_xorOut; } private: - const int m_bits; - const calc_type m_init; - const calc_type m_xorout; - const bool m_refin; - const bool m_refout; - const std::array table; + u64 m_value; - calc_type c; + u64 m_init; + u64 m_xorOut; + bool m_reflectInput; + bool m_reflectOutput; + + std::array m_table; }; - template + template auto calcCrc(prv::Provider *data, u64 offset, std::size_t size, u32 polynomial, u32 init, u32 xorout, bool reflectIn, bool reflectOut) { - Crc crc(bits, polynomial, init, xorout, reflectIn, reflectOut); + using Crc = Crc; + Crc crc(polynomial, init, xorout, reflectIn, reflectOut); processDataByChunks(data, offset, size, std::bind(&Crc::processBytes, &crc, _1, _2)); return crc.checksum(); } - u16 crc8(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorout, bool reflectIn, bool reflectOut) { - return calcCrc<8>(data, offset, size, polynomial, init, xorout, reflectIn, reflectOut); + u16 crc8(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorOut, bool reflectIn, bool reflectOut) { + return calcCrc<8>(data, offset, size, polynomial, init, xorOut, reflectIn, reflectOut); } - u16 crc16(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorout, bool reflectIn, bool reflectOut) { - return calcCrc<16>(data, offset, size, polynomial, init, xorout, reflectIn, reflectOut); + u16 crc16(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorOut, bool reflectIn, bool reflectOut) { + return calcCrc<16>(data, offset, size, polynomial, init, xorOut, reflectIn, reflectOut); } - u32 crc32(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorout, bool reflectIn, bool reflectOut) { - return calcCrc<32>(data, offset, size, polynomial, init, xorout, reflectIn, reflectOut); + u32 crc32(prv::Provider *&data, u64 offset, size_t size, u32 polynomial, u32 init, u32 xorOut, bool reflectIn, bool reflectOut) { + return calcCrc<32>(data, offset, size, polynomial, init, xorOut, reflectIn, reflectOut); } @@ -414,7 +414,7 @@ namespace hex::crypt { std::string output(input.size() * 2, '\0'); - for (int i = 0; i < input.size(); i++) { + for (size_t i = 0; i < input.size(); i++) { output[2 * i + 0] = "0123456789ABCDEF"[input[i] / 16]; output[2 * i + 1] = "0123456789ABCDEF"[input[i] % 16]; } @@ -427,13 +427,15 @@ namespace hex::crypt { if (input.empty()) return {}; + if (key.size() > 256) + return {}; mbedtls_cipher_context_t ctx; auto cipherInfo = mbedtls_cipher_info_from_type(type); mbedtls_cipher_setup(&ctx, cipherInfo); - mbedtls_cipher_setkey(&ctx, key.data(), key.size() * 8, operation); + mbedtls_cipher_setkey(&ctx, key.data(), static_cast(key.size() * 8), operation); std::array nonceCounter = { 0 }; std::copy(nonce.begin(), nonce.end(), nonceCounter.begin()); diff --git a/lib/libimhex/source/helpers/file.cpp b/lib/libimhex/source/helpers/file.cpp index c5eb7299d..752cf9c4f 100644 --- a/lib/libimhex/source/helpers/file.cpp +++ b/lib/libimhex/source/helpers/file.cpp @@ -115,7 +115,8 @@ namespace hex::fs { void File::setSize(u64 size) { if (!isValid()) return; - ftruncate64(fileno(this->m_file), size); + auto result = ftruncate64(fileno(this->m_file), size); + hex::unused(result); } void File::flush() { diff --git a/lib/libimhex/source/helpers/fs.cpp b/lib/libimhex/source/helpers/fs.cpp index 56c9150f5..bbd8e641e 100644 --- a/lib/libimhex/source/helpers/fs.cpp +++ b/lib/libimhex/source/helpers/fs.cpp @@ -59,7 +59,7 @@ namespace hex::fs { return result; } - bool openFileBrowser(const std::string &title, DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath) { + bool openFileBrowser(DialogMode mode, const std::vector &validExtensions, const std::function &callback, const std::string &defaultPath) { NFD::Init(); nfdchar_t *outPath; @@ -95,6 +95,7 @@ namespace hex::fs { const std::string settingName { "hex.builtin.setting.folders" }; auto userDirs = ContentRegistry::Settings::read(settingName, settingName, std::vector {}); + [[maybe_unused]] auto addUserDirs = [&userDirs](auto &paths) { std::transform(userDirs.begin(), userDirs.end(), std::back_inserter(paths), [](auto &item) { return std::move(item); diff --git a/lib/libimhex/source/helpers/loader_script_handler.cpp b/lib/libimhex/source/helpers/loader_script_handler.cpp index afdc4d521..1c10e267d 100644 --- a/lib/libimhex/source/helpers/loader_script_handler.cpp +++ b/lib/libimhex/source/helpers/loader_script_handler.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #define PY_SSIZE_T_CLEAN #include @@ -18,10 +19,14 @@ using namespace std::literals::string_literals; namespace hex { PyObject *LoaderScript::Py_getFilePath(PyObject *self, PyObject *args) { + hex::unused(self, args); + return PyUnicode_FromString(LoaderScript::s_filePath.string().c_str()); } PyObject *LoaderScript::Py_addPatch(PyObject *self, PyObject *args) { + hex::unused(self); + u64 address; u8 *patches; Py_ssize_t count; @@ -47,6 +52,8 @@ namespace hex { } PyObject *LoaderScript::Py_addBookmark(PyObject *self, PyObject *args) { + hex::unused(self); + u64 address; size_t size; @@ -171,10 +178,14 @@ namespace hex { } PyObject *LoaderScript::Py_addStruct(PyObject *self, PyObject *args) { + hex::unused(self); + return createStructureType("struct", args); } PyObject *LoaderScript::Py_addUnion(PyObject *self, PyObject *args) { + hex::unused(self); + return createStructureType("union", args); } diff --git a/lib/libimhex/source/helpers/net.cpp b/lib/libimhex/source/helpers/net.cpp index a3043b4c2..a0693534a 100644 --- a/lib/libimhex/source/helpers/net.cpp +++ b/lib/libimhex/source/helpers/net.cpp @@ -38,19 +38,16 @@ namespace hex { return size * nmemb; } - static size_t readFromFile(void *contents, size_t size, size_t nmemb, void *userdata) { - FILE *file = static_cast(userdata); - - return fread(contents, size, nmemb, file); - } - static size_t writeToFile(void *contents, size_t size, size_t nmemb, void *userdata) { FILE *file = static_cast(userdata); return fwrite(contents, size, nmemb, file); } - static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userdata) { + [[maybe_unused]] + static CURLcode sslCtxFunction(CURL *ctx, void *sslctx, void *userData) { + hex::unused(ctx, userData); + auto *cfg = static_cast(sslctx); static mbedtls_x509_crt crt; diff --git a/lib/libimhex/source/helpers/socket.cpp b/lib/libimhex/source/helpers/socket.cpp index 8c93a9108..66fd9c550 100644 --- a/lib/libimhex/source/helpers/socket.cpp +++ b/lib/libimhex/source/helpers/socket.cpp @@ -75,7 +75,7 @@ namespace hex { if (this->m_socket == SOCKET_NONE) return; - sockaddr_in client = { 0 }; + sockaddr_in client = { }; client.sin_family = AF_INET; client.sin_port = htons(port); diff --git a/lib/libimhex/source/helpers/utils.cpp b/lib/libimhex/source/helpers/utils.cpp index c2f3dc8c5..5fb07aeb2 100644 --- a/lib/libimhex/source/helpers/utils.cpp +++ b/lib/libimhex/source/helpers/utils.cpp @@ -249,14 +249,13 @@ namespace hex { void runCommand(const std::string &command) { #if defined(OS_WINDOWS) - system(hex::format("start {0}", command).c_str()); + auto result = system(hex::format("start {0}", command).c_str()); #elif defined(OS_MACOS) - system(hex::format("open {0}", command).c_str()); + auto result = system(hex::format("open {0}", command).c_str()); #elif defined(OS_LINUX) - system(hex::format("xdg-open {0}", command).c_str()); -#else - #warning "Unknown OS, can't open webpages" + auto result = system(hex::format("xdg-open {0}", command).c_str()); #endif + hex::unused(result); } void openWebpage(std::string url) { @@ -271,7 +270,8 @@ namespace hex { LSOpenCFURLRef(urlRef, nullptr); CFRelease(urlRef); #elif defined(OS_LINUX) - system(hex::format("xdg-open {0}", url).c_str()); + auto result = system(hex::format("xdg-open {0}", url).c_str()); + hex::unused(result); #else #warning "Unknown OS, can't open webpages" #endif @@ -399,7 +399,7 @@ namespace hex { u32 exponent = (float16 >> 10) & 0x1F; u32 mantissa = float16 & 0x3FF; - u32 result; + u32 result = 0x00; if (exponent == 0) { if (mantissa == 0) { @@ -425,7 +425,10 @@ namespace hex { result = (sign << 31) | ((exponent + (0x7F - 15)) << 23) | (mantissa << 13); } - return reinterpret_cast(result); + float floatResult = 0; + std::memcpy(&floatResult, &result, sizeof(float)); + + return floatResult; } bool isProcessElevated() { @@ -447,7 +450,7 @@ namespace hex { return elevated; #elif defined(OS_LINUX) || defined(OS_MACOS) - return getuid() < 0 || getuid() != geteuid(); + return getuid() == 0 || getuid() != geteuid(); #endif } diff --git a/lib/libimhex/source/pattern_language/lexer.cpp b/lib/libimhex/source/pattern_language/lexer.cpp index b5004d094..07b332774 100644 --- a/lib/libimhex/source/pattern_language/lexer.cpp +++ b/lib/libimhex/source/pattern_language/lexer.cpp @@ -39,8 +39,7 @@ namespace hex::pl { std::optional lexIntegerLiteral(std::string_view string) { bool hasFloatSuffix = string.ends_with('D') || string.ends_with('F') || string.ends_with('d') || string.ends_with('f'); - bool isFloat = std::count(string.begin(), string.end(), '.') == 1 || - !string.starts_with("0x") && hasFloatSuffix; + bool isFloat = std::count(string.begin(), string.end(), '.') == 1 || (!string.starts_with("0x") && hasFloatSuffix); if (isFloat) { // Parse double diff --git a/lib/libimhex/source/pattern_language/preprocessor.cpp b/lib/libimhex/source/pattern_language/preprocessor.cpp index e52dad59e..c5f671035 100644 --- a/lib/libimhex/source/pattern_language/preprocessor.cpp +++ b/lib/libimhex/source/pattern_language/preprocessor.cpp @@ -215,7 +215,7 @@ namespace hex::pl { }); for (const auto &[define, value, defineLine] : sortedDefines) { - i32 index = 0; + size_t index = 0; while ((index = output.find(define, index)) != std::string::npos) { output.replace(index, define.length(), value); index += value.length(); diff --git a/lib/libimhex/source/providers/provider.cpp b/lib/libimhex/source/providers/provider.cpp index b781d3070..ae563bfa5 100644 --- a/lib/libimhex/source/providers/provider.cpp +++ b/lib/libimhex/source/providers/provider.cpp @@ -29,6 +29,8 @@ namespace hex::prv { } void Provider::read(u64 offset, void *buffer, size_t size, bool overlays) { + hex::unused(overlays); + this->readRaw(offset - this->getBaseAddress(), buffer, size); } @@ -37,9 +39,13 @@ namespace hex::prv { } void Provider::save() { } - void Provider::saveAs(const std::fs::path &path) { } + void Provider::saveAs(const std::fs::path &path) { + hex::unused(path); + } - void Provider::resize(size_t newSize) { } + void Provider::resize(size_t newSize) { + hex::unused(newSize); + } void Provider::insert(u64 offset, size_t size) { auto &patches = getPatches(); @@ -54,7 +60,7 @@ namespace hex::prv { for (const auto &[address, value] : patchesToMove) patches.erase(address); for (const auto &[address, value] : patchesToMove) - patches.insert({ address + offset, value }); + patches.insert({ address + size, value }); } void Provider::applyOverlays(u64 offset, void *buffer, size_t size) { @@ -72,7 +78,7 @@ namespace hex::prv { std::map &Provider::getPatches() { auto iter = this->m_patches.end(); - for (auto i = 0; i < this->m_patchTreeOffset + 1; i++) + for (u32 i = 0; i < this->m_patchTreeOffset + 1; i++) iter--; return *(iter); @@ -80,7 +86,7 @@ namespace hex::prv { const std::map &Provider::getPatches() const { auto iter = this->m_patches.end(); - for (auto i = 0; i < this->m_patchTreeOffset + 1; i++) + for (u32 i = 0; i < this->m_patchTreeOffset + 1; i++) iter--; return *(iter); @@ -149,7 +155,7 @@ namespace hex::prv { void Provider::addPatch(u64 offset, const void *buffer, size_t size, bool createUndo) { if (this->m_patchTreeOffset > 0) { auto iter = this->m_patches.end(); - for (auto i = 0; i < this->m_patchTreeOffset; i++) + for (u32 i = 0; i < this->m_patchTreeOffset; i++) iter--; this->m_patches.erase(iter, this->m_patches.end()); diff --git a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp index 33a6cd531..25e015cad 100644 --- a/lib/libimhex/source/ui/imgui_imhex_extensions.cpp +++ b/lib/libimhex/source/ui/imgui_imhex_extensions.cpp @@ -32,7 +32,6 @@ namespace ImGui { return false; ImGuiContext &g = *GImGui; - const ImGuiStyle &style = g.Style; const ImGuiID id = window->GetID(label); ImVec2 label_size = CalcTextSize(icon, NULL, false); label_size.x += CalcTextSize(" ", NULL, false).x + CalcTextSize(label, NULL, false).x; @@ -67,7 +66,6 @@ namespace ImGui { return false; ImGuiContext &g = *GImGui; - const ImGuiStyle &style = g.Style; const ImGuiID id = window->GetID(label); const ImVec2 label_size = CalcTextSize(label, NULL, true); @@ -554,7 +552,6 @@ namespace ImGui { fraction = ImSaturate(fraction); RenderFrame(bb.Min, bb.Max, GetColorU32(ImGuiCol_FrameBg), true, style.FrameRounding); bb.Expand(ImVec2(-style.FrameBorderSize, -style.FrameBorderSize)); - const ImVec2 fill_br = ImVec2(ImLerp(bb.Min.x, bb.Max.x, fraction), bb.Max.y); RenderRectFilledRangeH(window->DrawList, bb, GetColorU32(ImGuiCol_PlotHistogram), 0.0f, fraction, style.FrameRounding); } diff --git a/lib/libimhex/source/ui/view.cpp b/lib/libimhex/source/ui/view.cpp index 5cff78b1e..f95f04ed2 100644 --- a/lib/libimhex/source/ui/view.cpp +++ b/lib/libimhex/source/ui/view.cpp @@ -108,7 +108,7 @@ namespace hex { ImGui::SameLine(); if (ImGui::Button("hex.builtin.common.browse"_lang)) { - fs::openFileBrowser("hex.builtin.common.open"_lang, fs::DialogMode::Open, View::s_selectableFilesValidExtensions, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, View::s_selectableFilesValidExtensions, [](const auto &path) { View::s_selectableFileOpenCallback(path); ImGui::CloseCurrentPopup(); }); @@ -147,7 +147,7 @@ namespace hex { void View::showFileChooserPopup(const std::vector &paths, const std::vector &validExtensions, const std::function &callback) { if (paths.empty()) { - fs::openFileBrowser("hex.builtin.common.open"_lang, fs::DialogMode::Open, validExtensions, [callback](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, validExtensions, [callback](const auto &path) { callback(path); }); } else { diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e48368cbb..07caf8d1f 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(main ${APPLICATION_TYPE} ) target_include_directories(main PUBLIC include) +target_compile_options(main PRIVATE -Wall -Wextra -Werror) set_target_properties(main PROPERTIES OUTPUT_NAME "imhex" @@ -28,4 +29,8 @@ if (WIN32) target_link_libraries(main PUBLIC libimhex wsock32 ws2_32 Dwmapi.lib) else () target_link_libraries(main PUBLIC libimhex pthread) +endif () + +if (APPLE) + add_compile_definitions(GL_SILENCE_DEPRECATION) endif () \ No newline at end of file diff --git a/main/source/window/win_window.cpp b/main/source/window/win_window.cpp index c8e0a114f..fe95aba59 100644 --- a/main/source/window/win_window.cpp +++ b/main/source/window/win_window.cpp @@ -27,7 +27,6 @@ namespace hex { static LONG_PTR g_oldWndProc; static float g_titleBarHeight; static ImGuiMouseCursor g_mouseCursorIcon; - static BOOL g_compositionEnabled = false; static LRESULT windowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { @@ -42,7 +41,9 @@ namespace hex { CallWindowProc((WNDPROC)g_oldWndProc, hwnd, uMsg, wParam, lParam); if (IsMaximized(hwnd)) { - WINDOWINFO windowInfo = { .cbSize = sizeof(WINDOWINFO) }; + WINDOWINFO windowInfo = { }; + windowInfo.cbSize = sizeof(WINDOWINFO); + GetWindowInfo(hwnd, &windowInfo); rect = RECT { .left = static_cast(client.left + windowInfo.cyWindowBorders), @@ -209,7 +210,7 @@ namespace hex { globalMutex = CreateMutex(nullptr, FALSE, UniqueMutexId); } else { if (ImHexApi::System::getProgramArguments().argc > 1) { - ::EnumWindows([](HWND hWnd, LPARAM lparam) -> BOOL { + ::EnumWindows([](HWND hWnd, LPARAM) -> BOOL { auto &programArgs = ImHexApi::System::getProgramArguments(); auto length = ::GetWindowTextLength(hWnd); diff --git a/main/source/window/window.cpp b/main/source/window/window.cpp index 93a80eea4..9af40056d 100644 --- a/main/source/window/window.cpp +++ b/main/source/window/window.cpp @@ -9,12 +9,10 @@ #include #include #include -#include #include #include #include -#include #include #include #include @@ -26,24 +24,17 @@ #include #include #include -#include #include #include #include #include #include -#include #include -#include #include -#include "init/tasks.hpp" #include -#include - -#include namespace hex { @@ -53,14 +44,14 @@ namespace hex { return ctx; // Unused, but the return value has to be non-null } - void ImHexSettingsHandler_ReadLine(ImGuiContext *, ImGuiSettingsHandler *handler, void *, const char *line) { + void ImHexSettingsHandler_ReadLine(ImGuiContext *, ImGuiSettingsHandler *, void *, const char *line) { for (auto &[name, view] : ContentRegistry::Views::getEntries()) { std::string format = std::string(view->getUnlocalizedName()) + "=%d"; sscanf(line, format.c_str(), &view->getWindowOpenState()); } } - void ImHexSettingsHandler_WriteAll(ImGuiContext *ctx, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf) { + void ImHexSettingsHandler_WriteAll(ImGuiContext *, ImGuiSettingsHandler *handler, ImGuiTextBuffer *buf) { buf->reserve(buf->size() + 0x20); // Ballpark reserve buf->appendf("[%s][General]\n", handler->TypeName); @@ -120,7 +111,7 @@ namespace hex { constexpr auto CrashBackupFileName = "crash_backup.hexproj"; - EventManager::subscribe(this, [this, CrashBackupFileName](int signal) { + EventManager::subscribe(this, [this, CrashBackupFileName](int) { ImGui::SaveIniSettingsToDisk(this->m_imguiSettingsPath.string().c_str()); if (!ProjectFile::hasUnsavedChanges()) @@ -263,7 +254,7 @@ namespace hex { ImGui::BeginDisabled(!ImHexApi::Provider::isValid()); { if (ImGui::Button(icon.c_str(), ImVec2(sidebarWidth, sidebarWidth))) { - if (openWindow == index) + if (static_cast(openWindow) == index) openWindow = -1; else openWindow = index; @@ -273,7 +264,7 @@ namespace hex { ImGui::PopStyleColor(3); - bool open = openWindow == index; + bool open = static_cast(openWindow) == index; if (open) { ImGui::SetNextWindowPos(ImGui::GetWindowPos() + sidebarPos + ImVec2(sidebarWidth - 2_scaled, 0)); ImGui::SetNextWindowSize(ImVec2(250_scaled, dockSpaceSize.y + ImGui::GetStyle().FramePadding.y + 2_scaled)); @@ -601,11 +592,11 @@ namespace hex { } }); - glfwSetDropCallback(this->m_window, [](GLFWwindow *window, int count, const char **paths) { + glfwSetDropCallback(this->m_window, [](GLFWwindow *, int count, const char **paths) { if (count != 1) return; - for (u32 i = 0; i < count; i++) { + for (int i = 0; i < count; i++) { auto path = std::fs::path(reinterpret_cast(paths[i])); bool handled = false; diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index ef51ace78..ae8b0f14e 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -73,3 +73,4 @@ endif() add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) diff --git a/plugins/builtin/include/content/providers/file_provider.hpp b/plugins/builtin/include/content/providers/file_provider.hpp index 40ba13ab2..c2e337b95 100644 --- a/plugins/builtin/include/content/providers/file_provider.hpp +++ b/plugins/builtin/include/content/providers/file_provider.hpp @@ -60,7 +60,7 @@ namespace hex::plugin::builtin::prv { void *m_mappedFile = nullptr; size_t m_fileSize = 0; - struct stat m_fileStats = { 0 }; + struct stat m_fileStats = { }; bool m_fileStatsValid = false; bool m_emptyFile = false; diff --git a/plugins/builtin/include/content/views/view_diff.hpp b/plugins/builtin/include/content/views/view_diff.hpp index c18456c10..efcf9ae52 100644 --- a/plugins/builtin/include/content/views/view_diff.hpp +++ b/plugins/builtin/include/content/views/view_diff.hpp @@ -25,7 +25,7 @@ namespace hex::plugin::builtin { bool m_greyedOutZeros = true; bool m_upperCaseHex = true; - int m_columnCount = 16; + u32 m_columnCount = 16; }; } \ No newline at end of file diff --git a/plugins/builtin/include/math_evaluator.hpp b/plugins/builtin/include/math_evaluator.hpp index 0a508a581..8bfca4ea1 100644 --- a/plugins/builtin/include/math_evaluator.hpp +++ b/plugins/builtin/include/math_evaluator.hpp @@ -58,9 +58,12 @@ namespace hex { struct Token { TokenType type; - long double number; - Operator op; - BracketType bracketType; + union { + long double number; + Operator op; + BracketType bracketType; + }; + std::string name; std::vector arguments; }; diff --git a/plugins/builtin/source/content/data_formatters.cpp b/plugins/builtin/source/content/data_formatters.cpp index 786d89405..5ab3a83b8 100644 --- a/plugins/builtin/source/content/data_formatters.cpp +++ b/plugins/builtin/source/content/data_formatters.cpp @@ -77,7 +77,7 @@ namespace hex::plugin::builtin { result += hex::format("{0:08X} ", col << 4); for (u64 i = 0; i < 16; i++) { - if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF)) + if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF))) result += " "; else result += hex::format("{0:02X} ", buffer[((col << 4) - offset) + i]); @@ -90,7 +90,7 @@ namespace hex::plugin::builtin { for (u64 i = 0; i < 16; i++) { - if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF)) + if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF))) result += " "; else { u8 c = buffer[((col << 4) - offset) + i]; @@ -129,7 +129,7 @@ namespace hex::plugin::builtin { result += hex::format(" {0:08X}  ", col << 4); for (u64 i = 0; i < 16; i++) { - if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF)) + if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF))) result += "   "; else result += hex::format("{0:02X} ", buffer[((col << 4) - offset) + i]); @@ -142,7 +142,7 @@ namespace hex::plugin::builtin { for (u64 i = 0; i < 16; i++) { - if (col == (offset >> 4) && i < (offset & 0xF) || col == (end >> 4) && i > (end & 0xF)) + if ((col == (offset >> 4) && i < (offset & 0xF)) || (col == (end >> 4) && i > (end & 0xF))) result += " "; else { u8 c = buffer[((col << 4) - offset) + i]; diff --git a/plugins/builtin/source/content/data_inspector.cpp b/plugins/builtin/source/content/data_inspector.cpp index 83152f6f4..25af6cc0a 100644 --- a/plugins/builtin/source/content/data_inspector.cpp +++ b/plugins/builtin/source/content/data_inspector.cpp @@ -82,6 +82,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.binary", sizeof(u8), [](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'; @@ -91,6 +93,7 @@ namespace hex::plugin::builtin { return binary; }; }, [](std::string value, std::endian endian) -> std::vector { + hex::unused(endian); if (value.starts_with("0b")) value = value.substr(2); @@ -113,6 +116,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.u8", sizeof(u8), [](auto buffer, auto endian, auto style) { + hex::unused(endian); + auto format = (style == Style::Decimal) ? "{0:d}" : ((style == Style::Hexadecimal) ? "0x{0:02X}" : "0o{0:03o}"); auto value = hex::format(format, *reinterpret_cast(buffer.data())); @@ -209,6 +214,7 @@ 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(buffer.data())), endian)); return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; } @@ -216,6 +222,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.float", sizeof(float), [](auto buffer, auto endian, auto style) { + hex::unused(style); + auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast(buffer.data()), endian)); return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; }, @@ -224,7 +232,12 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.double", sizeof(double), [](auto buffer, auto endian, auto style) { - auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast(buffer.data()), endian)); + hex::unused(style); + + double result = 0; + std::memcpy(&result, buffer.data(), sizeof(double)); + + auto value = hex::format("{0:G}", hex::changeEndianess(result, endian)); return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; }, stringToFloat @@ -232,6 +245,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.long_double", sizeof(long double), [](auto buffer, auto endian, auto style) { + hex::unused(style); + auto value = hex::format("{0:G}", hex::changeEndianess(*reinterpret_cast(buffer.data()), endian)); return [value] { ImGui::TextUnformatted(value.c_str()); return value; }; }, @@ -240,10 +255,14 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.ascii", sizeof(char8_t), [](auto buffer, auto endian, auto style) { + hex::unused(endian, style); + auto value = makePrintable(*reinterpret_cast(buffer.data())); return [value] { ImGui::TextFormatted("'{0}'", value.c_str()); return value; }; }, [](const std::string &value, std::endian endian) -> std::vector { + hex::unused(endian); + if (value.length() > 1) return { }; return { u8(value[0]) }; @@ -252,6 +271,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.wide", sizeof(wchar_t), [](auto buffer, auto endian, auto style) { + hex::unused(style); + wchar_t wideChar = '\x00'; std::memcpy(&wideChar, buffer.data(), std::min(sizeof(wchar_t), buffer.size())); @@ -278,6 +299,8 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.utf8", sizeof(char8_t) * 4, [](auto buffer, auto endian, auto style) { + hex::unused(endian, style); + char utf8Buffer[5] = { 0 }; char codepointString[5] = { 0 }; u32 codepoint = 0; @@ -296,12 +319,14 @@ namespace hex::plugin::builtin { ContentRegistry::DataInspector::add("hex.builtin.inspector.string", 1, [](auto buffer, auto endian, auto style) { - Region currSelection = { 0 }; + hex::unused(endian, style); + + Region currSelection = { 0, 0 }; EventManager::post(currSelection); constexpr static auto MaxStringLength = 32; - std::vector stringBuffer(std::min(MaxStringLength, currSelection.size), 0x00); + std::vector stringBuffer(std::min(MaxStringLength, currSelection.size), 0x00); ImHexApi::Provider::get()->read(currSelection.address, stringBuffer.data(), stringBuffer.size()); auto value = hex::encodeByteString(stringBuffer); @@ -313,6 +338,8 @@ namespace hex::plugin::builtin { return [value, copyValue] { ImGui::TextFormatted("\"{0}\"", value.c_str()); return copyValue; }; }, [](const std::string &value, std::endian endian) -> std::vector { + hex::unused(endian); + return hex::decodeByteString(value); } ); @@ -320,6 +347,8 @@ namespace hex::plugin::builtin { #if defined(OS_WINDOWS) && defined(ARCH_64_BIT) ContentRegistry::DataInspector::add("hex.builtin.inspector.time32", sizeof(u32), [](auto buffer, auto endian, auto style) { + hex::unused(style); + auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast(buffer.data()), endian); std::string value; @@ -333,6 +362,8 @@ namespace hex::plugin::builtin { }); ContentRegistry::DataInspector::add("hex.builtin.inspector.time64", sizeof(u64), [](auto buffer, auto endian, auto style) { + hex::unused(style); + auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast(buffer.data()), endian); std::string value; @@ -348,6 +379,8 @@ namespace hex::plugin::builtin { #else ContentRegistry::DataInspector::add("hex.builtin.inspector.time", sizeof(time_t), [](auto buffer, auto endian, auto style) { + hex::unused(style); + auto endianAdjustedTime = hex::changeEndianess(*reinterpret_cast(buffer.data()), endian); std::string value; @@ -363,7 +396,9 @@ namespace hex::plugin::builtin { #endif ContentRegistry::DataInspector::add("hex.builtin.inspector.guid", sizeof(GUID), [](auto buffer, auto endian, auto style) { - GUID guid = { 0 }; + hex::unused(style); + + GUID guid = { }; std::memcpy(&guid, buffer.data(), sizeof(GUID)); auto value = hex::format("{}{{{:08X}-{:04X}-{:04X}-{:02X}{:02X}-{:02X}{:02X}{:02X}{:02X}{:02X}{:02X}}}", (hex::changeEndianess(guid.data3, endian) >> 12) <= 5 && ((guid.data4[0] >> 4) >= 8 || (guid.data4[0] >> 4) == 0) ? "" : "Invalid ", @@ -383,6 +418,8 @@ namespace hex::plugin::builtin { }); ContentRegistry::DataInspector::add("hex.builtin.inspector.rgba8", sizeof(u32), [](auto buffer, auto endian, auto style) { + hex::unused(style); + ImColor value(hex::changeEndianess(*reinterpret_cast(buffer.data()), endian)); auto copyValue = hex::format("#{:02X}{:02X}{:02X}{:02X}", u8(0xFF * (value.Value.x)), u8(0xFF * (value.Value.y)), u8(0xFF * (value.Value.z)), u8(0xFF * (value.Value.w))); diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index 0c7c28c8f..6c291d737 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -530,9 +530,9 @@ namespace hex::plugin::builtin { auto from = this->getIntegerOnInput(1); auto to = this->getIntegerOnInput(2); - if (from < 0 || from >= input.size()) + if (from < 0 || static_cast(from) >= input.size()) throwNodeError("'from' input out of range"); - if (to < 0 || from >= input.size()) + if (to < 0 || static_cast(from) >= input.size()) throwNodeError("'to' input out of range"); if (to <= from) throwNodeError("'to' input needs to be greater than 'from' input"); diff --git a/plugins/builtin/source/content/pl_builtin_functions.cpp b/plugins/builtin/source/content/pl_builtin_functions.cpp index 3c16b4552..9032b0625 100644 --- a/plugins/builtin/source/content/pl_builtin_functions.cpp +++ b/plugins/builtin/source/content/pl_builtin_functions.cpp @@ -75,12 +75,12 @@ namespace hex::plugin::builtin { }); /* pack_size(...) */ - ContentRegistry::PatternLanguage::addFunction(nsStd, "sizeof_pack", ParameterCount::atLeast(0), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStd, "sizeof_pack", ParameterCount::atLeast(0), [](Evaluator *, auto params) -> std::optional { return u128(params.size()); }); /* error(message) */ - ContentRegistry::PatternLanguage::addFunction(nsStd, "error", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStd, "error", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { LogConsole::abortEvaluation(Token::literalToString(params[0], true)); return std::nullopt; @@ -99,11 +99,15 @@ namespace hex::plugin::builtin { /* base_address() */ ContentRegistry::PatternLanguage::addFunction(nsStdMem, "base_address", ParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional { + hex::unused(params); + return u128(ctx->getProvider()->getBaseAddress()); }); /* size() */ ContentRegistry::PatternLanguage::addFunction(nsStdMem, "size", ParameterCount::none(), [](Evaluator *ctx, auto params) -> std::optional { + hex::unused(params); + return u128(ctx->getProvider()->getActualSize()); }); @@ -185,14 +189,14 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::Namespace nsStdString = { "builtin", "std", "string" }; { /* length(string) */ - ContentRegistry::PatternLanguage::addFunction(nsStdString, "length", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdString, "length", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { auto string = Token::literalToString(params[0], false); return u128(string.length()); }); /* at(string, index) */ - ContentRegistry::PatternLanguage::addFunction(nsStdString, "at", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdString, "at", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { auto string = Token::literalToString(params[0], false); auto index = Token::literalToSigned(params[1]); @@ -213,7 +217,7 @@ namespace hex::plugin::builtin { }); /* substr(string, pos, count) */ - ContentRegistry::PatternLanguage::addFunction(nsStdString, "substr", ParameterCount::exactly(3), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdString, "substr", ParameterCount::exactly(3), [](Evaluator *, auto params) -> std::optional { auto string = Token::literalToString(params[0], false); auto pos = Token::literalToUnsigned(params[1]); auto size = Token::literalToUnsigned(params[2]); @@ -225,7 +229,7 @@ namespace hex::plugin::builtin { }); /* parse_int(string, base) */ - ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_int", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_int", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { auto string = Token::literalToString(params[0], false); auto base = Token::literalToUnsigned(params[1]); @@ -233,7 +237,7 @@ namespace hex::plugin::builtin { }); /* parse_float(string) */ - ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_float", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdString, "parse_float", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { auto string = Token::literalToString(params[0], false); return double(std::strtod(string.c_str(), nullptr)); @@ -243,7 +247,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::Namespace nsStdHttp = { "builtin", "std", "http" }; { /* get(url) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdHttp, "get", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto url = Token::literalToString(params[0], false); hex::Net net; @@ -258,7 +262,7 @@ namespace hex::plugin::builtin { static std::map openFiles; /* open(path, mode) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "open", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "open", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { const auto path = Token::literalToString(params[0], false); const auto modeEnum = Token::literalToUnsigned(params[1]); @@ -289,7 +293,7 @@ namespace hex::plugin::builtin { }); /* close(file) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "close", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "close", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); if (!openFiles.contains(file)) @@ -301,7 +305,7 @@ namespace hex::plugin::builtin { }); /* read(file, size) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "read", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "read", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); const auto size = Token::literalToUnsigned(params[1]); @@ -312,7 +316,7 @@ namespace hex::plugin::builtin { }); /* write(file, data) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "write", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "write", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); const auto data = Token::literalToString(params[1], true); @@ -325,7 +329,7 @@ namespace hex::plugin::builtin { }); /* seek(file, offset) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "seek", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "seek", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); const auto offset = Token::literalToUnsigned(params[1]); @@ -338,7 +342,7 @@ namespace hex::plugin::builtin { }); /* size(file) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "size", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "size", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); if (!openFiles.contains(file)) @@ -348,7 +352,7 @@ namespace hex::plugin::builtin { }); /* resize(file, size) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "resize", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "resize", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); const auto size = Token::literalToUnsigned(params[1]); @@ -361,7 +365,7 @@ namespace hex::plugin::builtin { }); /* flush(file) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "flush", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "flush", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); if (!openFiles.contains(file)) @@ -373,7 +377,7 @@ namespace hex::plugin::builtin { }); /* remove(file) */ - ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "remove", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addDangerousFunction(nsStdFile, "remove", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { const auto file = Token::literalToUnsigned(params[0]); if (!openFiles.contains(file)) @@ -389,126 +393,126 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::Namespace nsStdMath = { "builtin", "std", "math" }; { /* floor(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "floor", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "floor", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::floor(Token::literalToFloatingPoint(params[0])); }); /* ceil(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ceil", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ceil", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::ceil(Token::literalToFloatingPoint(params[0])); }); /* round(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "round", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "round", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::round(Token::literalToFloatingPoint(params[0])); }); /* trunc(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "trunc", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "trunc", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::trunc(Token::literalToFloatingPoint(params[0])); }); /* log10(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log10", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log10", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::log10(Token::literalToFloatingPoint(params[0])); }); /* log2(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log2", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "log2", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::log2(Token::literalToFloatingPoint(params[0])); }); /* ln(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ln", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "ln", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::log(Token::literalToFloatingPoint(params[0])); }); /* fmod(x, y) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "fmod", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "fmod", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { return std::fmod(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1])); }); /* pow(base, exp) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "pow", ParameterCount::exactly(2), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "pow", ParameterCount::exactly(2), [](Evaluator *, auto params) -> std::optional { return std::pow(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1])); }); /* sqrt(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sqrt", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sqrt", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::sqrt(Token::literalToFloatingPoint(params[0])); }); /* cbrt(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cbrt", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cbrt", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::cbrt(Token::literalToFloatingPoint(params[0])); }); /* sin(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sin", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sin", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::sin(Token::literalToFloatingPoint(params[0])); }); /* cos(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cos", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cos", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::cos(Token::literalToFloatingPoint(params[0])); }); /* tan(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::tan(Token::literalToFloatingPoint(params[0])); }); /* asin(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asin", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asin", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::asin(Token::literalToFloatingPoint(params[0])); }); /* acos(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acos", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acos", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::acos(Token::literalToFloatingPoint(params[0])); }); /* atan(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::atan(Token::literalToFloatingPoint(params[0])); }); /* atan2(y, x) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atan", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::atan2(Token::literalToFloatingPoint(params[0]), Token::literalToFloatingPoint(params[1])); }); /* sinh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sinh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "sinh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::sinh(Token::literalToFloatingPoint(params[0])); }); /* cosh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cosh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "cosh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::cosh(Token::literalToFloatingPoint(params[0])); }); /* tanh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tanh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "tanh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::tanh(Token::literalToFloatingPoint(params[0])); }); /* asinh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asinh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "asinh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::asinh(Token::literalToFloatingPoint(params[0])); }); /* acosh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acosh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "acosh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::acosh(Token::literalToFloatingPoint(params[0])); }); /* atanh(value) */ - ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atanh", ParameterCount::exactly(1), [](Evaluator *ctx, auto params) -> std::optional { + ContentRegistry::PatternLanguage::addFunction(nsStdMath, "atanh", ParameterCount::exactly(1), [](Evaluator *, auto params) -> std::optional { return std::atanh(Token::literalToFloatingPoint(params[0])); }); } diff --git a/plugins/builtin/source/content/providers/disk_provider.cpp b/plugins/builtin/source/content/providers/disk_provider.cpp index 6915d02b1..ed5ecf744 100644 --- a/plugins/builtin/source/content/providers/disk_provider.cpp +++ b/plugins/builtin/source/content/providers/disk_provider.cpp @@ -4,12 +4,12 @@ #include #include +#include #include #include #include -#include #if defined(OS_LINUX) #include @@ -82,7 +82,7 @@ namespace hex::plugin::builtin::prv { } { - DISK_GEOMETRY_EX diskGeometry = { 0 }; + DISK_GEOMETRY_EX diskGeometry = { }; DWORD bytesRead = 0; if (DeviceIoControl( this->m_diskHandle, @@ -113,8 +113,11 @@ namespace hex::plugin::builtin::prv { struct stat driveStat; - ::stat(path.c_str(), &driveStat) == 0; - this->m_diskSize = driveStat.st_size; + if (::stat(path.c_str(), &driveStat) == 0) + this->m_diskSize = driveStat.st_size; + else + this->m_diskSize = 0; + this->m_sectorSize = 0; this->m_diskHandle = ::open(path.c_str(), O_RDWR); @@ -158,7 +161,7 @@ namespace hex::plugin::builtin::prv { seekPosition.LowPart = (offset & 0xFFFF'FFFF) - (offset % this->m_sectorSize); seekPosition.HighPart = offset >> 32; - if (this->m_sectorBufferAddress != seekPosition.QuadPart) { + if (this->m_sectorBufferAddress != static_cast(seekPosition.QuadPart)) { ::SetFilePointer(this->m_diskHandle, seekPosition.LowPart, &seekPosition.HighPart, FILE_BEGIN); ::ReadFile(this->m_diskHandle, this->m_sectorBuffer.data(), this->m_sectorBuffer.size(), &bytesRead, nullptr); this->m_sectorBufferAddress = seekPosition.QuadPart; @@ -177,7 +180,9 @@ namespace hex::plugin::builtin::prv { if (this->m_sectorBufferAddress != seekPosition) { ::lseek(this->m_diskHandle, seekPosition, SEEK_SET); - ::read(this->m_diskHandle, buffer, size); + if (::read(this->m_diskHandle, buffer, size) < 0) + break; + this->m_sectorBufferAddress = seekPosition; } @@ -231,7 +236,8 @@ namespace hex::plugin::builtin::prv { std::memcpy(modifiedSectorBuffer.data() + ((offset - sectorBase) % this->m_sectorSize), reinterpret_cast(buffer) + (startOffset - offset), currSize); ::lseek(this->m_diskHandle, sectorBase, SEEK_SET); - ::write(this->m_diskHandle, modifiedSectorBuffer.data(), modifiedSectorBuffer.size()); + if (::write(this->m_diskHandle, modifiedSectorBuffer.data(), modifiedSectorBuffer.size()) < 0) + break; offset += currSize; size -= currSize; @@ -272,7 +278,7 @@ namespace hex::plugin::builtin::prv { if (handle == INVALID_HANDLE_VALUE) continue; - VOLUME_DISK_EXTENTS diskExtents = { 0 }; + VOLUME_DISK_EXTENTS diskExtents = { }; DWORD bytesRead = 0; auto result = ::DeviceIoControl( handle, @@ -314,7 +320,7 @@ namespace hex::plugin::builtin::prv { #else - if (ImGui::InputText("hex.builtin.provider.disk.selected_disk"_lang, this->m_pathBuffer)) + 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)) this->m_path = this->m_pathBuffer; #endif diff --git a/plugins/builtin/source/content/providers/file_provider.cpp b/plugins/builtin/source/content/providers/file_provider.cpp index ac1f3d43a..644057cfa 100644 --- a/plugins/builtin/source/content/providers/file_provider.cpp +++ b/plugins/builtin/source/content/providers/file_provider.cpp @@ -111,7 +111,7 @@ namespace hex::plugin::builtin::prv { this->m_fileSize = file.getSize(); } - this->open(); + (void)this->open(); } void FileProvider::insert(u64 offset, size_t size) { @@ -171,7 +171,7 @@ namespace hex::plugin::builtin::prv { this->m_fileStatsValid = wstat(path.c_str(), &this->m_fileStats) == 0; - LARGE_INTEGER fileSize = { 0 }; + LARGE_INTEGER fileSize = { }; this->m_file = reinterpret_cast(CreateFileW(path.c_str(), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr)); GetFileSizeEx(this->m_file, &fileSize); diff --git a/plugins/builtin/source/content/providers/gdb_provider.cpp b/plugins/builtin/source/content/providers/gdb_provider.cpp index 2fa2b7506..590084755 100644 --- a/plugins/builtin/source/content/providers/gdb_provider.cpp +++ b/plugins/builtin/source/content/providers/gdb_provider.cpp @@ -218,6 +218,7 @@ namespace hex::plugin::builtin::prv { } void GDBProvider::saveAs(const std::fs::path &path) { + hex::unused(path); } size_t GDBProvider::getActualSize() const { diff --git a/plugins/builtin/source/content/settings_entries.cpp b/plugins/builtin/source/content/settings_entries.cpp index 732e4513a..a1aa3ba91 100644 --- a/plugins/builtin/source/content/settings_entries.cpp +++ b/plugins/builtin/source/content/settings_entries.cpp @@ -238,7 +238,7 @@ namespace hex::plugin::builtin { ImGui::SameLine(); if (ImGui::IconButton(ICON_VS_FOLDER_OPENED, ImGui::GetStyleColorVec4(ImGuiCol_Text))) { - return fs::openFileBrowser("hex.builtin.setting.font.font_path", fs::DialogMode::Open, { {"TTF Font", "ttf"} }, + return fs::openFileBrowser(fs::DialogMode::Open, { {"TTF Font", "ttf"} }, [&](const std::fs::path &path) { fontPath = path.string(); setting = fontPath; @@ -275,8 +275,10 @@ namespace hex::plugin::builtin { ContentRegistry::Settings::addCategoryDescription(dirsSetting, "hex.builtin.setting.folders.description"); ContentRegistry::Settings::add(dirsSetting, dirsSetting, std::vector {}, [](auto name, nlohmann::json &setting) { + hex::unused(name); + static std::vector folders = setting; - static int currentItemIndex = 0; + static size_t currentItemIndex = 0; if (!ImGui::BeginListBox("", ImVec2(-38, -FLT_MIN))) { return false; @@ -292,7 +294,7 @@ namespace hex::plugin::builtin { ImGui::BeginGroup(); if (ImGui::IconButton(ICON_VS_NEW_FOLDER, ImGui::GetCustomColorVec4(ImGuiCustomCol_DescButton), ImVec2(30, 30))) { - fs::openFileBrowser("Select include folder", fs::DialogMode::Folder, {}, [&](const std::fs::path &path) { + fs::openFileBrowser(fs::DialogMode::Folder, {}, [&](const std::fs::path &path) { auto pathStr = path.string(); if (std::find(folders.begin(), folders.end(), pathStr) == folders.end()) { diff --git a/plugins/builtin/source/content/tools_entries.cpp b/plugins/builtin/source/content/tools_entries.cpp index aba27ac17..229737b7d 100644 --- a/plugins/builtin/source/content/tools_entries.cpp +++ b/plugins/builtin/source/content/tools_entries.cpp @@ -142,6 +142,8 @@ namespace hex::plugin::builtin { evaluator.setFunction( "clear", [&](auto args) -> std::optional { + hex::unused(args); + mathHistory.clear(); lastMathError.clear(); mathEvaluator.getVariables().clear(); @@ -185,16 +187,16 @@ namespace hex::plugin::builtin { 2, 2); - return std::move(evaluator); + return evaluator; }(); - enum class MathDisplayType - { + enum class MathDisplayType : u8 { Standard, Scientific, Engineering, Programmer - } mathDisplayType; + } mathDisplayType = MathDisplayType::Standard; + if (ImGui::BeginTabBar("##mathFormatTabBar")) { if (ImGui::BeginTabItem("hex.builtin.tools.format.standard"_lang)) { mathDisplayType = MathDisplayType::Standard; @@ -235,8 +237,10 @@ namespace hex::plugin::builtin { if (ImGui::Button("CE", buttonSize)) mathInput.clear(); ImGui::SameLine(); if (ImGui::Button(ICON_FA_BACKSPACE, buttonSize)) mathInput.clear(); + ImGui::SameLine(); ImGui::NewLine(); + switch (mathDisplayType) { case MathDisplayType::Standard: case MathDisplayType::Scientific: @@ -339,7 +343,7 @@ namespace hex::plugin::builtin { ImGui::TableHeadersRow(); while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { if (i == 0) ImGui::PushStyleColor(ImGuiCol_Text, ImU32(ImColor(0xA5, 0x45, 0x45))); @@ -438,7 +442,7 @@ namespace hex::plugin::builtin { } void drawBaseConverter() { - static char buffer[4][0xFFF] = { { '0' }, { '0' }, { '0' }, { '0' } }; + static char buffer[4][0x1000] = { { '0' }, { '0' }, { '0' }, { '0' } }; static auto CharFilter = [](ImGuiInputTextCallbackData *data) -> int { switch (*static_cast(data->UserData)) { @@ -481,10 +485,15 @@ namespace hex::plugin::builtin { auto base8String = hex::format("{0:#o}", number); auto base2String = hex::toBinaryString(number); - std::strncpy(buffer[0], base10String.c_str(), sizeof(buffer[0])); - std::strncpy(buffer[1], base16String.c_str(), sizeof(buffer[1])); - std::strncpy(buffer[2], base8String.c_str(), sizeof(buffer[2])); - std::strncpy(buffer[3], base2String.c_str(), sizeof(buffer[3])); + std::strncpy(buffer[0], base10String.c_str(), sizeof(buffer[0]) - 1); + std::strncpy(buffer[1], base16String.c_str(), sizeof(buffer[1]) - 1); + std::strncpy(buffer[2], base8String.c_str(), sizeof(buffer[2]) - 1); + std::strncpy(buffer[3], base2String.c_str(), sizeof(buffer[3]) - 1); + + buffer[0][0xFFF] = '\x00'; + buffer[1][0xFFF] = '\x00'; + buffer[2][0xFFF] = '\x00'; + buffer[3][0xFFF] = '\x00'; }; u8 base = 10; @@ -579,7 +588,7 @@ namespace hex::plugin::builtin { ImGui::Header("hex.builtin.tools.file_uploader.control"_lang, true); if (!uploading) { if (ImGui::Button("hex.builtin.tools.file_uploader.upload"_lang)) { - fs::openFileBrowser("hex.builtin.tools.file_uploader.done"_lang, fs::DialogMode::Open, {}, [&](auto path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [&](auto path) { uploadProcess = net.uploadFile("https://api.anonfiles.com/upload", path); currFile = path; }); @@ -678,7 +687,7 @@ namespace hex::plugin::builtin { startSearch = ImGui::InputText("##search", searchString, ImGuiInputTextFlags_EnterReturnsTrue); ImGui::SameLine(); - ImGui::BeginDisabled(searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready || searchString.empty()); + ImGui::BeginDisabled((searchProcess.valid() && searchProcess.wait_for(0s) != std::future_status::ready) || searchString.empty()); startSearch = ImGui::Button("hex.builtin.tools.wiki_explain.search"_lang) || startSearch; ImGui::EndDisabled(); @@ -744,7 +753,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##path", selectedFile); ImGui::SameLine(); if (ImGui::Button("...")) { - fs::openFileBrowser("hex.builtin.tools.file_tools.shredder.picker"_lang, fs::DialogMode::Open, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { selectedFile = path.string(); }); } @@ -886,7 +895,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##path", selectedFile); ImGui::SameLine(); if (ImGui::Button("...##input")) { - fs::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.input"_lang, fs::DialogMode::Open, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { selectedFile = path.string(); }); } @@ -896,7 +905,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##base_path", baseOutputPath); ImGui::SameLine(); if (ImGui::Button("...##output")) { - fs::openFileBrowser("hex.builtin.tools.file_tools.splitter.picker.output"_lang, fs::DialogMode::Save, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { baseOutputPath = path.string(); }); } @@ -979,7 +988,7 @@ namespace hex::plugin::builtin { static bool combining = false; static std::vector files; static auto outputPath = [] { std::string s; s.reserve(0x1000); return s; }(); - static i32 selectedIndex; + static u32 selectedIndex; if (ImGui::BeginTable("files_table", 2, ImGuiTableFlags_SizingStretchProp)) { ImGui::TableSetupColumn("file list", ImGuiTableColumnFlags_NoHeaderLabel, 10); @@ -989,7 +998,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginListBox("##files", { -FLT_MIN, 10 * ImGui::GetTextLineHeightWithSpacing() })) { - i32 index = 0; + u32 index = 0; for (auto &file : files) { if (ImGui::Selectable(std::fs::path(file).filename().string().c_str(), index == selectedIndex)) selectedIndex = index; @@ -1025,7 +1034,7 @@ namespace hex::plugin::builtin { ImGui::BeginDisabled(combining); { if (ImGui::Button("hex.builtin.tools.file_tools.combiner.add"_lang)) { - fs::openFileBrowser("hex.builtin.tools.file_tools.combiner.add.picker"_lang, fs::DialogMode::Open, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { files.push_back(path.string()); }); } @@ -1049,7 +1058,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##output_path", outputPath); ImGui::SameLine(); if (ImGui::Button("...")) { - fs::openFileBrowser("hex.builtin.tools.file_tools.combiner.output.picker"_lang, fs::DialogMode::Save, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { outputPath = path.string(); }); } diff --git a/plugins/builtin/source/content/ui_items.cpp b/plugins/builtin/source/content/ui_items.cpp index 0dab86441..c3c4247a1 100644 --- a/plugins/builtin/source/content/ui_items.cpp +++ b/plugins/builtin/source/content/ui_items.cpp @@ -105,7 +105,7 @@ namespace hex::plugin::builtin { // Save file as ImGui::Disabled([&provider] { if (ImGui::ToolBarButton(ICON_VS_SAVE_AS, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarBlue))) - fs::openFileBrowser("hex.builtin.view.hex_editor.save_as"_lang, fs::DialogMode::Save, {}, [&provider](auto path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [&provider](auto path) { provider->saveAs(path); }); }, @@ -118,7 +118,7 @@ namespace hex::plugin::builtin { // Create bookmark ImGui::Disabled([] { if (ImGui::ToolBarButton(ICON_VS_BOOKMARK, ImGui::GetCustomColorVec4(ImGuiCustomCol_ToolbarGreen))) { - Region region = { 0 }; + Region region = { }; EventManager::post(region); ImHexApi::Bookmarks::add(region.address, region.size, {}, {}); @@ -141,7 +141,7 @@ namespace hex::plugin::builtin { ImGui::SetNextItemWidth(200_scaled); if (ImGui::BeginCombo("", preview.c_str())) { - for (int i = 0; i < providers.size(); i++) { + for (size_t i = 0; i < providers.size(); i++) { if (ImGui::Selectable(providers[i]->getName().c_str())) { ImHexApi::Provider::setCurrentProvider(i); } diff --git a/plugins/builtin/source/content/views/view_constants.cpp b/plugins/builtin/source/content/views/view_constants.cpp index b97d722d0..5be2e15f2 100644 --- a/plugins/builtin/source/content/views/view_constants.cpp +++ b/plugins/builtin/source/content/views/view_constants.cpp @@ -128,7 +128,7 @@ namespace hex::plugin::builtin { clipper.Begin(this->m_filterIndices.size()); while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { auto &constant = this->m_constants[this->m_filterIndices[i]]; ImGui::TableNextRow(); ImGui::TableNextColumn(); diff --git a/plugins/builtin/source/content/views/view_data_processor.cpp b/plugins/builtin/source/content/views/view_data_processor.cpp index 02c3fb546..ebc23baed 100644 --- a/plugins/builtin/source/content/views/view_data_processor.cpp +++ b/plugins/builtin/source/content/views/view_data_processor.cpp @@ -42,6 +42,8 @@ namespace hex::plugin::builtin { }); EventManager::subscribe(this, [this](const std::fs::path &path) { + hex::unused(path); + for (auto &node : this->m_nodes) { node->setCurrentOverlay(nullptr); } @@ -56,7 +58,7 @@ namespace hex::plugin::builtin { bool providerValid = ImHexApi::Provider::isValid(); if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.load_processor"_lang, nullptr, false, providerValid)) { - fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.load_processor"_lang, fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, + fs::openFileBrowser(fs::DialogMode::Open, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, [this](const std::fs::path &path) { fs::File file(path, fs::File::Mode::Read); if (file.isValid()) @@ -65,7 +67,7 @@ namespace hex::plugin::builtin { } if (ImGui::MenuItem("hex.builtin.view.data_processor.menu.file.save_processor"_lang, nullptr, false, !this->m_nodes.empty() && providerValid)) { - fs::openFileBrowser("hex.builtin.view.data_processor.menu.file.save_processor"_lang, fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, + fs::openFileBrowser(fs::DialogMode::Save, { {"hex.builtin.view.data_processor.name"_lang, "hexnode"} }, [this](const std::fs::path &path) { fs::File file(path, fs::File::Mode::Create); if (file.isValid()) @@ -114,7 +116,7 @@ namespace hex::plugin::builtin { } void ViewDataProcessor::eraseNodes(const std::vector &ids) { - for (const int id : ids) { + for (u32 id : ids) { auto node = std::find_if(this->m_nodes.begin(), this->m_nodes.end(), [&id](auto node) { return node->getId() == id; }); for (auto &attr : (*node)->getAttributes()) { @@ -127,7 +129,7 @@ namespace hex::plugin::builtin { } } - for (const int id : ids) { + for (u32 id : ids) { auto node = std::find_if(this->m_nodes.begin(), this->m_nodes.end(), [&id](auto node) { return node->getId() == id; }); std::erase_if(this->m_endNodes, [&id](auto node) { return node->getId() == id; }); @@ -275,7 +277,7 @@ namespace hex::plugin::builtin { { int nodeId; - if (ImNodes::IsNodeHovered(&nodeId) && this->m_currNodeError.has_value() && this->m_currNodeError->first->getId() == nodeId) { + if (ImNodes::IsNodeHovered(&nodeId) && this->m_currNodeError.has_value() && this->m_currNodeError->first->getId() == static_cast(nodeId)) { ImGui::BeginTooltip(); ImGui::TextUnformatted("hex.builtin.common.error"_lang); ImGui::Separator(); @@ -305,6 +307,7 @@ namespace hex::plugin::builtin { ImNodesPinShape pinShape; switch (attribute.getType()) { + default: case dp::Attribute::Type::Integer: pinShape = ImNodesPinShape_Circle; break; @@ -366,9 +369,9 @@ namespace hex::plugin::builtin { dp::Attribute *fromAttr, *toAttr; for (auto &node : this->m_nodes) { for (auto &attribute : node->getAttributes()) { - if (attribute.getId() == from) + if (attribute.getId() == static_cast(from)) fromAttr = &attribute; - else if (attribute.getId() == to) + else if (attribute.getId() == static_cast(to)) toAttr = &attribute; } } diff --git a/plugins/builtin/source/content/views/view_diff.cpp b/plugins/builtin/source/content/views/view_diff.cpp index a112b1c69..4dbf44328 100644 --- a/plugins/builtin/source/content/views/view_diff.cpp +++ b/plugins/builtin/source/content/views/view_diff.cpp @@ -50,7 +50,7 @@ namespace hex::plugin::builtin { ImGui::SetNextItemWidth(200_scaled); if (ImGui::BeginCombo("", preview.c_str())) { - for (int i = 0; i < providers.size(); i++) { + for (size_t i = 0; i < providers.size(); i++) { if (ImGui::Selectable(providers[i]->getName().c_str())) { provider = i; } @@ -130,7 +130,8 @@ namespace hex::plugin::builtin { ImGui::TableNextColumn(); auto other = !curr; - std::optional lastHighlightEnd; + bool hasLastHighlight = false; + ImVec2 lastHighlightEnd = { }; for (i64 col = 0; col < lineInfo[curr].validBytes; col++) { auto pos = ImGui::GetCursorScreenPos(); @@ -162,10 +163,15 @@ namespace hex::plugin::builtin { // Draw highlighting if (highlightColor.has_value()) { - drawList->AddRectFilled(lastHighlightEnd.value_or(pos), pos + highlightSize, highlightColor.value()); + if (hasLastHighlight) + drawList->AddRectFilled(lastHighlightEnd, pos + highlightSize, highlightColor.value()); + else + drawList->AddRectFilled(pos, pos + highlightSize, highlightColor.value()); + + hasLastHighlight = true; lastHighlightEnd = pos + ImVec2((glyphWidth - 1) * 2, 0); } else { - lastHighlightEnd.reset(); + hasLastHighlight = false; } } } @@ -217,7 +223,7 @@ namespace hex::plugin::builtin { // Draw diff lines while (clipper.Step()) { - for (u64 row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { + for (int row = clipper.DisplayStart; row < clipper.DisplayEnd; row++) { ImGui::TableNextRow(); drawDiffLine({ this->m_providerA, this->m_providerB }, row); } diff --git a/plugins/builtin/source/content/views/view_disassembler.cpp b/plugins/builtin/source/content/views/view_disassembler.cpp index 48488b422..d0f4f2b3b 100644 --- a/plugins/builtin/source/content/views/view_disassembler.cpp +++ b/plugins/builtin/source/content/views/view_disassembler.cpp @@ -71,7 +71,7 @@ namespace hex::plugin::builtin { u64 usedBytes = 0; for (u32 i = 0; i < instructionCount; i++) { const auto &instr = instructions[i]; - Disassembly disassembly = { 0 }; + Disassembly disassembly = { }; disassembly.address = instr.address; disassembly.offset = this->m_codeRegion[0] + address + usedBytes; disassembly.size = instr.size; @@ -169,7 +169,7 @@ namespace hex::plugin::builtin { static bool microMode; ImGui::Checkbox("hex.builtin.view.disassembler.mips.micro"_lang, µMode); - this->m_mode = cs_mode(mode | (microMode ? CS_MODE_MICRO : 0)); + this->m_mode = cs_mode(mode | (microMode ? CS_MODE_MICRO : cs_mode(0))); } break; case Architecture::X86: @@ -198,7 +198,7 @@ namespace hex::plugin::builtin { static bool booke = false; ImGui::Checkbox("hex.builtin.view.disassembler.ppc.booke"_lang, &booke); - this->m_mode = cs_mode(mode | (qpx ? CS_MODE_QPX : 0) | (spe ? CS_MODE_SPE : 0) | (booke ? CS_MODE_BOOKE : 0)); + this->m_mode = cs_mode(mode | (qpx ? CS_MODE_QPX : cs_mode(0)) | (spe ? CS_MODE_SPE : cs_mode(0)) | (booke ? CS_MODE_BOOKE : cs_mode(0))); } break; case Architecture::SPARC: @@ -206,7 +206,7 @@ namespace hex::plugin::builtin { static bool v9Mode = false; ImGui::Checkbox("hex.builtin.view.disassembler.sparc.v9"_lang, &v9Mode); - this->m_mode = cs_mode(v9Mode ? CS_MODE_V9 : 0); + this->m_mode = cs_mode(v9Mode ? CS_MODE_V9 : cs_mode(0)); } break; case Architecture::RISCV: @@ -219,7 +219,7 @@ namespace hex::plugin::builtin { static bool compressed = false; ImGui::Checkbox("hex.builtin.view.disassembler.riscv.compressed"_lang, &compressed); - this->m_mode = cs_mode(mode | (compressed ? CS_MODE_RISCVC : 0)); + this->m_mode = cs_mode(mode | (compressed ? CS_MODE_RISCVC : cs_mode(0))); } break; case Architecture::M68K: @@ -351,7 +351,7 @@ namespace hex::plugin::builtin { ImGui::TableHeadersRow(); while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &instruction = this->m_disassembly[i]; ImGui::TableNextRow(); ImGui::TableNextColumn(); diff --git a/plugins/builtin/source/content/views/view_hashes.cpp b/plugins/builtin/source/content/views/view_hashes.cpp index c21f3796b..8e9e1bc99 100644 --- a/plugins/builtin/source/content/views/view_hashes.cpp +++ b/plugins/builtin/source/content/views/view_hashes.cpp @@ -34,7 +34,7 @@ namespace hex::plugin::builtin { template static void formatBigHexInt(std::array dataArray, char *buffer, size_t bufferSize) { - for (int i = 0; i < dataArray.size(); i++) + for (size_t i = 0; i < dataArray.size(); i++) snprintf(buffer + 2 * i, bufferSize - 2 * i, "%02X", dataArray[i]); } @@ -64,8 +64,8 @@ namespace hex::plugin::builtin { ImGui::Separator(); if (ImGui::BeginCombo("hex.builtin.view.hashes.function"_lang, hashFunctionNames[this->m_currHashFunction].second, 0)) { - for (int i = 0; i < hashFunctionNames.size(); i++) { - bool is_selected = (this->m_currHashFunction == i); + for (size_t i = 0; i < hashFunctionNames.size(); i++) { + bool is_selected = (static_cast(this->m_currHashFunction) == i); if (ImGui::Selectable(hashFunctionNames[i].second, is_selected)) this->m_currHashFunction = i; if (is_selected) diff --git a/plugins/builtin/source/content/views/view_hex_editor.cpp b/plugins/builtin/source/content/views/view_hex_editor.cpp index b27a144c5..90f1379d3 100644 --- a/plugins/builtin/source/content/views/view_hex_editor.cpp +++ b/plugins/builtin/source/content/views/view_hex_editor.cpp @@ -39,7 +39,7 @@ namespace hex::plugin::builtin { return true; }); - this->m_memoryEditor.ReadFn = [](const ImU8 *data, size_t off) -> ImU8 { + this->m_memoryEditor.ReadFn = [](const ImU8 *, size_t off) -> ImU8 { auto provider = ImHexApi::Provider::get(); if (!provider->isAvailable() || !provider->isReadable()) return 0x00; @@ -50,7 +50,7 @@ namespace hex::plugin::builtin { return byte; }; - this->m_memoryEditor.WriteFn = [](ImU8 *data, size_t off, ImU8 d) -> void { + this->m_memoryEditor.WriteFn = [](ImU8 *, size_t off, ImU8 d) -> void { auto provider = ImHexApi::Provider::get(); if (!provider->isAvailable() || !provider->isWritable()) return; @@ -269,7 +269,7 @@ namespace hex::plugin::builtin { } static void saveAs() { - fs::openFileBrowser("hex.builtin.view.hex_editor.save_as"_lang, fs::DialogMode::Save, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [](const auto &path) { ImHexApi::Provider::get()->saveAs(path); }); } @@ -299,7 +299,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##nolabel", this->m_loaderScriptScriptPath.data(), this->m_loaderScriptScriptPath.length(), ImGuiInputTextFlags_ReadOnly); ImGui::SameLine(); if (ImGui::Button("hex.builtin.view.hex_editor.script.script"_lang)) { - fs::openFileBrowser("hex.builtin.view.hex_editor.script.script.title"_lang, fs::DialogMode::Open, { {"Python Script", "py"} }, + fs::openFileBrowser(fs::DialogMode::Open, { {"Python Script", "py"} }, [this](const auto &path) { this->m_loaderScriptScriptPath = path.string(); }); @@ -307,7 +307,7 @@ namespace hex::plugin::builtin { ImGui::InputText("##nolabel", this->m_loaderScriptFilePath.data(), this->m_loaderScriptFilePath.length(), ImGuiInputTextFlags_ReadOnly); ImGui::SameLine(); if (ImGui::Button("hex.builtin.view.hex_editor.script.file"_lang)) { - fs::openFileBrowser("hex.builtin.view.hex_editor.script.file.title"_lang, fs::DialogMode::Open, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) { this->m_loaderScriptFilePath = path.string(); }); } @@ -801,7 +801,7 @@ namespace hex::plugin::builtin { ImGui::Separator(); - bool bytesSelected = this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1; + bool bytesSelected = this->m_memoryEditor.DataPreviewAddr != static_cast(-1) && this->m_memoryEditor.DataPreviewAddrEnd != static_cast(-1); if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.copy"_lang, "CTRL + C", false, bytesSelected)) this->copyBytes(); @@ -834,7 +834,9 @@ namespace hex::plugin::builtin { ImGui::Separator(); - if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.bookmark"_lang, nullptr, false, this->m_memoryEditor.DataPreviewAddr != -1 && this->m_memoryEditor.DataPreviewAddrEnd != -1)) { + if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.edit.bookmark"_lang, nullptr, false, + this->m_memoryEditor.DataPreviewAddr != static_cast(-1) && this->m_memoryEditor.DataPreviewAddrEnd != static_cast(-1))) + { auto base = provider->getBaseAddress(); size_t start = base + std::min(this->m_memoryEditor.DataPreviewAddr, this->m_memoryEditor.DataPreviewAddrEnd); @@ -898,7 +900,7 @@ namespace hex::plugin::builtin { EventManager::subscribe(this, [this](const std::string &name) { if (name == "Create File") { - fs::openFileBrowser("hex.builtin.view.hex_editor.create_file"_lang, fs::DialogMode::Save, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) { fs::File file(path, fs::File::Mode::Create); if (!file.isValid()) { @@ -912,12 +914,12 @@ namespace hex::plugin::builtin { this->getWindowOpenState() = true; }); } else if (name == "Open File") { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) { EventManager::post(path); this->getWindowOpenState() = true; }); } else if (name == "Open Project") { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_project"_lang, fs::DialogMode::Open, { {"Project File", "hexproj"} }, + fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} }, [this](const auto &path) { ProjectFile::load(path); this->getWindowOpenState() = true; @@ -1033,7 +1035,7 @@ namespace hex::plugin::builtin { }); ShortcutManager::addShortcut(this, CTRL + Keys::O, [] { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { EventManager::post(path); }); }); @@ -1092,7 +1094,7 @@ namespace hex::plugin::builtin { bool providerValid = ImHexApi::Provider::isValid(); if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.open_project"_lang, "")) { - fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.open_project"_lang, fs::DialogMode::Open, { {"Project File", "hexproj"} + fs::openFileBrowser(fs::DialogMode::Open, { {"Project File", "hexproj"} }, [](const auto &path) { ProjectFile::load(path); @@ -1101,7 +1103,7 @@ namespace hex::plugin::builtin { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.save_project"_lang, "", false, providerValid && provider->isWritable())) { if (ProjectFile::getProjectFilePath() == "") { - fs::openFileBrowser("hex.builtin.view.hex_editor.save_project"_lang, fs::DialogMode::Save, { {"Project File", "hexproj"} + fs::openFileBrowser(fs::DialogMode::Save, { {"Project File", "hexproj"} }, [](std::fs::path path) { if (path.extension() != ".hexproj") { @@ -1142,7 +1144,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginMenu("hex.builtin.view.hex_editor.menu.file.import"_lang)) { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.base64"_lang)) { - fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.import.base64"_lang, fs::DialogMode::Open, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) { fs::File file(path, fs::File::Mode::Read); if (!file.isValid()) { View::showErrorPopup("hex.builtin.view.hex_editor.error.open"_lang); @@ -1167,7 +1169,7 @@ namespace hex::plugin::builtin { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.ips"_lang, nullptr, false, !this->m_processingImportExport)) { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) { this->m_processingImportExport = true; std::thread([this, path] { auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hex_editor.processing", 0); @@ -1195,7 +1197,7 @@ namespace hex::plugin::builtin { } if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.import.ips32"_lang, nullptr, false, !this->m_processingImportExport)) { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [this](const auto &path) { this->m_processingImportExport = true; std::thread([this, path] { auto task = ImHexApi::Tasks::createTask("hex.builtin.view.hex_editor.processing", 0); @@ -1250,7 +1252,7 @@ namespace hex::plugin::builtin { this->m_processingImportExport = false; ImHexApi::Tasks::doLater([this] { - fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.export.title"_lang, fs::DialogMode::Save, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) { auto file = fs::File(path, fs::File::Mode::Create); if (!file.isValid()) { View::showErrorPopup("hex.builtin.view.hex_editor.error.create"_lang); @@ -1279,7 +1281,7 @@ namespace hex::plugin::builtin { this->m_processingImportExport = false; ImHexApi::Tasks::doLater([this] { - fs::openFileBrowser("hex.builtin.view.hex_editor.menu.file.export.title"_lang, fs::DialogMode::Save, {}, [this](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Save, {}, [this](const auto &path) { auto file = fs::File(path, fs::File::Mode::Create); if (!file.isValid()) { View::showErrorPopup("hex.builtin.view.hex_editor.error.create"_lang); diff --git a/plugins/builtin/source/content/views/view_information.cpp b/plugins/builtin/source/content/views/view_information.cpp index 981a537a9..247b02153 100644 --- a/plugins/builtin/source/content/views/view_information.cpp +++ b/plugins/builtin/source/content/views/view_information.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -156,7 +157,7 @@ namespace hex::plugin::builtin { if (this->m_dataValid) { - ImGui::LabelText("hex.builtin.view.information.region"_lang, "0x%llx - 0x%llx", this->m_analyzedRegion.first, this->m_analyzedRegion.second); + ImGui::LabelText("hex.builtin.view.information.region"_lang, "%s", hex::format("0x{:X} - 0x{:X}", this->m_analyzedRegion.first, this->m_analyzedRegion.second).c_str()); ImGui::NewLine(); diff --git a/plugins/builtin/source/content/views/view_pattern_editor.cpp b/plugins/builtin/source/content/views/view_pattern_editor.cpp index 66103ba49..d52b51b5d 100644 --- a/plugins/builtin/source/content/views/view_pattern_editor.cpp +++ b/plugins/builtin/source/content/views/view_pattern_editor.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -101,6 +100,8 @@ namespace hex::plugin::builtin { }); EventManager::subscribe(this, [this](const std::fs::path &path) { + hex::unused(path); + if (!ContentRegistry::Settings::read("hex.builtin.setting.general", "hex.builtin.setting.general.auto_load_patterns", 1)) return; @@ -217,7 +218,7 @@ namespace hex::plugin::builtin { } if (ImGui::MenuItem("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, nullptr, false, providerValid)) { - fs::openFileBrowser("hex.builtin.view.pattern_editor.menu.file.save_pattern"_lang, fs::DialogMode::Save, { {"Pattern", "hexpat"} }, + fs::openFileBrowser(fs::DialogMode::Save, { {"Pattern", "hexpat"} }, [this](const auto &path) { fs::File file(path, fs::File::Mode::Create); @@ -379,7 +380,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginChild("##console", size, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) { ImGuiListClipper clipper(this->m_console.size()); while (clipper.Step()) - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &[level, message] = this->m_console[i]; switch (level) { @@ -639,7 +640,8 @@ namespace hex::plugin::builtin { PatternVariable variable = { .inVariable = variableDecl->isInVariable(), .outVariable = variableDecl->isOutVariable(), - .type = builtinType->getType() + .type = builtinType->getType(), + .value = { } }; if (variable.inVariable || variable.outVariable) { diff --git a/plugins/builtin/source/content/views/view_strings.cpp b/plugins/builtin/source/content/views/view_strings.cpp index 2feb573a6..5278b1fae 100644 --- a/plugins/builtin/source/content/views/view_strings.cpp +++ b/plugins/builtin/source/content/views/view_strings.cpp @@ -81,7 +81,7 @@ namespace hex::plugin::builtin { if (buffer[i] >= ' ' && buffer[i] <= '~' && offset < provider->getActualSize() - 1) foundCharacters++; else { - if (foundCharacters >= this->m_minimumLength) { + if (foundCharacters >= static_cast(this->m_minimumLength)) { FoundString foundString = { offset + i - foundCharacters + provider->getBaseAddress(), foundCharacters @@ -212,7 +212,7 @@ namespace hex::plugin::builtin { clipper.Begin(this->m_filterIndices.size()); while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { auto &foundString = this->m_foundStrings[this->m_filterIndices[i]]; auto string = readString(foundString); diff --git a/plugins/builtin/source/content/views/view_yara.cpp b/plugins/builtin/source/content/views/view_yara.cpp index 68dabe899..56c84d281 100644 --- a/plugins/builtin/source/content/views/view_yara.cpp +++ b/plugins/builtin/source/content/views/view_yara.cpp @@ -2,18 +2,14 @@ #include -#include #include #include #include -#include #include #include #include -#include - namespace hex::plugin::builtin { ViewYara::ViewYara() : View("hex.builtin.view.yara.name") { @@ -94,7 +90,7 @@ namespace hex::plugin::builtin { clipper.Begin(this->m_matches.size()); while (clipper.Step()) { - for (u32 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { auto &[identifier, variableName, address, size, wholeDataMatch, highlightId] = this->m_matches[i]; ImGui::TableNextRow(); ImGui::TableNextColumn(); @@ -133,7 +129,7 @@ namespace hex::plugin::builtin { if (ImGui::BeginChild("##console", consoleSize, true, ImGuiWindowFlags_AlwaysVerticalScrollbar | ImGuiWindowFlags_HorizontalScrollbar)) { ImGuiListClipper clipper(this->m_consoleMessages.size()); while (clipper.Step()) - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &message = this->m_consoleMessages[i]; if (ImGui::Selectable(message.c_str())) @@ -189,7 +185,7 @@ namespace hex::plugin::builtin { yr_compiler_set_include_callback( compiler, - [](const char *includeName, const char *callingRuleFileName, const char *callingRuleNamespace, void *userData) -> const char * { + [](const char *includeName, const char *, const char *, void *userData) -> const char * { auto currFilePath = static_cast(userData); fs::File file((std::fs::path(currFilePath).parent_path() / includeName).string(), fs::File::Mode::Read); @@ -204,6 +200,8 @@ namespace hex::plugin::builtin { return buffer; }, [](const char *ptr, void *userData) { + hex::unused(userData); + delete[] ptr; }, this->m_rules[this->m_selectedRule].second.data()); @@ -257,6 +255,8 @@ namespace hex::plugin::builtin { return context.buffer.data(); }; iterator.file_size = [](auto *iterator) -> u64 { + hex::unused(iterator); + return ImHexApi::Provider::get()->getActualSize(); }; @@ -310,11 +310,11 @@ namespace hex::plugin::builtin { if (rule->strings != nullptr) { yr_rule_strings_foreach(rule, string) { yr_string_matches_foreach(context, string, match) { - results.newMatches.push_back({ rule->identifier, string->identifier, u64(match->offset), size_t(match->match_length), false }); + results.newMatches.push_back({ rule->identifier, string->identifier, u64(match->offset), size_t(match->match_length), false, 0 }); } } } else { - results.newMatches.push_back({ rule->identifier, "", 0, 0, true }); + results.newMatches.push_back({ rule->identifier, "", 0, 0, true, 0 }); } } break; diff --git a/plugins/builtin/source/content/welcome_screen.cpp b/plugins/builtin/source/content/welcome_screen.cpp index f83403d20..a3c83f4f4 100644 --- a/plugins/builtin/source/content/welcome_screen.cpp +++ b/plugins/builtin/source/content/welcome_screen.cpp @@ -200,7 +200,7 @@ namespace hex::plugin::builtin { clipper.Begin(plugins.size()); while (clipper.Step()) { - for (u64 i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart; i < clipper.DisplayEnd; i++) { const auto &plugin = plugins[i]; ImGui::TableNextRow(); @@ -420,7 +420,7 @@ namespace hex::plugin::builtin { ContentRegistry::Interface::addMenuItem("hex.builtin.menu.file", 1050, [&] { if (ImGui::MenuItem("hex.builtin.view.hex_editor.menu.file.open_file"_lang, "CTRL + O")) { - fs::openFileBrowser("hex.builtin.view.hex_editor.open_file"_lang, fs::DialogMode::Open, {}, [](const auto &path) { + fs::openFileBrowser(fs::DialogMode::Open, {}, [](const auto &path) { EventManager::post(path); }); } diff --git a/plugins/builtin/source/math_evaluator.cpp b/plugins/builtin/source/math_evaluator.cpp index 8817d6f6d..522ba588f 100644 --- a/plugins/builtin/source/math_evaluator.cpp +++ b/plugins/builtin/source/math_evaluator.cpp @@ -58,7 +58,7 @@ namespace hex { if (currToken.type == TokenType::Number || currToken.type == TokenType::Variable || currToken.type == TokenType::Function) outputQueue.push(currToken); else if (currToken.type == TokenType::Operator) { - while ((!operatorStack.empty()) && (operatorStack.top().type == TokenType::Operator && currToken.type == TokenType::Operator && (comparePrecedence(operatorStack.top().op, currToken.op) > 0) || (comparePrecedence(operatorStack.top().op, currToken.op) == 0 && isLeftAssociative(currToken.op))) && operatorStack.top().type != TokenType::Bracket) { + while ((!operatorStack.empty()) && ((operatorStack.top().type == TokenType::Operator && currToken.type == TokenType::Operator && (comparePrecedence(operatorStack.top().op, currToken.op) > 0)) || (comparePrecedence(operatorStack.top().op, currToken.op) == 0 && isLeftAssociative(currToken.op))) && operatorStack.top().type != TokenType::Bracket) { outputQueue.push(operatorStack.top()); operatorStack.pop(); } @@ -109,12 +109,12 @@ namespace hex { number = std::strtoull(pos, &pos, 0); } - inputQueue.push(Token { .type = TokenType::Number, .number = number }); + inputQueue.push(Token { .type = TokenType::Number, .number = number, .name = "", .arguments = { } }); } else if (*pos == '(') { - inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Left }); + inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Left, .name = "", .arguments = { } }); pos++; } else if (*pos == ')') { - inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Right }); + inputQueue.push(Token { .type = TokenType::Bracket, .bracketType = BracketType::Right, .name = "", .arguments = { } }); pos++; } else if (std::isspace(*pos)) { pos++; @@ -122,7 +122,7 @@ namespace hex { auto [op, width] = toOperator(pos); if (op != Operator::Invalid) { - inputQueue.push(Token { .type = TokenType::Operator, .op = op }); + inputQueue.push(Token { .type = TokenType::Operator, .op = op, .name = "", .arguments = { } }); pos += width; } else { Token token; diff --git a/plugins/example_cpp/CMakeLists.txt b/plugins/example_cpp/CMakeLists.txt index fc4f4aebc..788e7254f 100644 --- a/plugins/example_cpp/CMakeLists.txt +++ b/plugins/example_cpp/CMakeLists.txt @@ -26,4 +26,5 @@ if (WIN32) endif() add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") -set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) \ No newline at end of file +set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) +target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) \ No newline at end of file diff --git a/plugins/windows/CMakeLists.txt b/plugins/windows/CMakeLists.txt index 8fe177857..f6ddb93e3 100644 --- a/plugins/windows/CMakeLists.txt +++ b/plugins/windows/CMakeLists.txt @@ -37,5 +37,6 @@ if (WIN32) add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) + target_compile_options(${PROJECT_NAME} PRIVATE -Wall -Wextra -Werror) endif () \ No newline at end of file diff --git a/plugins/windows/source/content/ui_items.cpp b/plugins/windows/source/content/ui_items.cpp index a9cbbbe4e..7d74142b1 100644 --- a/plugins/windows/source/content/ui_items.cpp +++ b/plugins/windows/source/content/ui_items.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include @@ -14,18 +13,6 @@ namespace hex::plugin::windows { - static ULONGLONG subtractTimes(const FILETIME &left, const FILETIME &right) { - LARGE_INTEGER a, b; - - a.LowPart = left.dwLowDateTime; - a.HighPart = left.dwHighDateTime; - - b.LowPart = right.dwLowDateTime; - b.HighPart = right.dwHighDateTime; - - return a.QuadPart - b.QuadPart; - } - void addTitleBarButtons() { #if defined(DEBUG) ContentRegistry::Interface::addTitleBarButton(ICON_VS_DEBUG, "hex.windows.title_bar_button.debug_build", []{ @@ -59,15 +46,17 @@ namespace hex::plugin::windows { static u32 numProcessors; static HANDLE self = GetCurrentProcess(); - FILETIME ftime, fsys, fuser; ULARGE_INTEGER now, sys, user; + { + FILETIME ftime, fsys, fuser; - GetSystemTimeAsFileTime(&ftime); - memcpy(&now, &ftime, sizeof(FILETIME)); + GetSystemTimeAsFileTime(&ftime); + memcpy(&now, &ftime, sizeof(FILETIME)); - GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); - memcpy(&sys, &fsys, sizeof(FILETIME)); - memcpy(&user, &fuser, sizeof(FILETIME)); + GetProcessTimes(self, &ftime, &ftime, &fsys, &fuser); + memcpy(&sys, &fsys, sizeof(FILETIME)); + memcpy(&user, &fuser, sizeof(FILETIME)); + } if (lastCPU.QuadPart == 0) { SYSTEM_INFO sysInfo; diff --git a/plugins/windows/source/views/view_tty_console.cpp b/plugins/windows/source/views/view_tty_console.cpp index 350b82b1b..f7d9068de 100644 --- a/plugins/windows/source/views/view_tty_console.cpp +++ b/plugins/windows/source/views/view_tty_console.cpp @@ -40,6 +40,8 @@ namespace hex::plugin::windows { ImGui::Combo( "hex.windows.view.tty_console.baud"_lang, &this->m_selectedBaudRate, [](void *data, int idx, const char **out_text) -> bool { + hex::unused(data); + *out_text = ViewTTYConsole::BaudRates[idx]; return true; }, @@ -48,6 +50,7 @@ namespace hex::plugin::windows { ImGui::Combo( "hex.windows.view.tty_console.num_bits"_lang, &this->m_selectedNumBits, [](void *data, int idx, const char **out_text) -> bool { + hex::unused(data); *out_text = ViewTTYConsole::NumBits[idx]; return true; }, @@ -56,6 +59,7 @@ namespace hex::plugin::windows { ImGui::Combo( "hex.windows.view.tty_console.stop_bits"_lang, &this->m_selectedStopBits, [](void *data, int idx, const char **out_text) -> bool { + hex::unused(data); *out_text = ViewTTYConsole::StopBits[idx]; return true; }, @@ -64,6 +68,7 @@ namespace hex::plugin::windows { ImGui::Combo( "hex.windows.view.tty_console.parity_bits"_lang, &this->m_selectedParityBits, [](void *data, int idx, const char **out_text) -> bool { + hex::unused(data); *out_text = ViewTTYConsole::ParityBits[idx]; return true; }, @@ -113,12 +118,12 @@ namespace hex::plugin::windows { while (clipper.Step()) { std::scoped_lock lock(this->m_receiveBufferMutex); - for (u32 i = clipper.DisplayStart + 1; i < clipper.DisplayEnd; i++) { + for (int i = clipper.DisplayStart + 1; i < clipper.DisplayEnd; i++) { ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions[i - 1], this->m_receiveDataBuffer.data() + this->m_wrapPositions[i]); } if (!this->m_receiveDataBuffer.empty() && !this->m_wrapPositions.empty()) - if (clipper.DisplayEnd >= this->m_wrapPositions.size() - 1) + if (static_cast(clipper.DisplayEnd) >= this->m_wrapPositions.size() - 1) ImGui::TextUnformatted(this->m_receiveDataBuffer.data() + this->m_wrapPositions.back()); if (this->m_shouldAutoScroll && ImGui::GetScrollY() >= ImGui::GetScrollMaxY()) { @@ -182,7 +187,7 @@ namespace hex::plugin::windows { } bool ViewTTYConsole::connect() { - if (this->m_comPorts.empty() || this->m_selectedPort >= this->m_comPorts.size()) { + if (this->m_comPorts.empty() || static_cast(this->m_selectedPort) >= this->m_comPorts.size()) { View::showErrorPopup("hex.windows.view.tty_console.no_available_port"_lang); return true; // If false, connect_error error popup will override this error popup } @@ -231,7 +236,7 @@ namespace hex::plugin::windows { this->m_receiveThread = std::jthread([this](const std::stop_token &token) { bool waitingOnRead = false; - OVERLAPPED overlapped = { 0 }; + OVERLAPPED overlapped = { }; overlapped.hEvent = ::CreateEvent(nullptr, true, false, nullptr); ON_SCOPE_EXIT { ::CloseHandle(&overlapped); }; @@ -298,7 +303,7 @@ namespace hex::plugin::windows { return; auto transmitThread = std::thread([&, this] { - OVERLAPPED overlapped = { 0 }; + OVERLAPPED overlapped = { }; overlapped.hEvent = ::CreateEvent(nullptr, true, false, nullptr); ON_SCOPE_EXIT { ::CloseHandle(&overlapped); };