diff --git a/CMakeLists.txt b/CMakeLists.txt index cc21f786e..1effaab00 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -38,7 +38,6 @@ add_executable(imhex ${application_type} source/main.cpp source/window.cpp - source/helpers/crypto.cpp source/helpers/patches.cpp source/helpers/project_file_handler.cpp source/helpers/loader_script_handler.cpp @@ -69,7 +68,7 @@ set_target_properties(imhex PROPERTIES CXX_VISIBILITY_PRESET hidden) target_link_directories(imhex PRIVATE ${MBEDTLS_LIBRARY_DIRS} ${CAPSTONE_LIBRARY_DIRS} ${MAGIC_LIBRARY_DIRS}) if (WIN32) - target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libmbedx509.a libmbedcrypto.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES} wsock32 ws2_32) + target_link_libraries(imhex libdl.a libmagic.a libgnurx.a libtre.a libintl.a libiconv.a libshlwapi.a libcapstone.a LLVMDemangle libimhex ${Python_LIBRARIES} wsock32 ws2_32) elseif (UNIX) target_link_libraries(imhex magic mbedtls ${CMAKE_DL_LIBS} capstone LLVMDemangle libimhex ${Python_LIBRARIES} dl) endif() diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 53471bf28..4da9e85fe 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -36,7 +36,7 @@ macro(findLibraries) # Find packages find_package(PkgConfig REQUIRED) - pkg_search_module(MBEDTLS libmbedtls) + pkg_search_module(MBEDTLS mbedtls) if(NOT MBEDTLS_FOUND) find_library(MBEDTLS mbedtls REQUIRED) else() diff --git a/plugins/builtin/source/content/data_processor_nodes.cpp b/plugins/builtin/source/content/data_processor_nodes.cpp index f05ba7f6b..2651651a9 100644 --- a/plugins/builtin/source/content/data_processor_nodes.cpp +++ b/plugins/builtin/source/content/data_processor_nodes.cpp @@ -2,6 +2,8 @@ #include "math_evaluator.hpp" +#include + namespace hex::plugin::builtin { class NodeInteger : public dp::Node { diff --git a/plugins/libimhex/CMakeLists.txt b/plugins/libimhex/CMakeLists.txt index f59fcf898..e54c3a6eb 100644 --- a/plugins/libimhex/CMakeLists.txt +++ b/plugins/libimhex/CMakeLists.txt @@ -19,8 +19,10 @@ add_library(libimhex SHARED source/api/event.cpp source/api/imhex_api.cpp source/api/content_registry.cpp + source/helpers/utils.cpp source/helpers/shared_data.cpp + source/helpers/crypto.cpp source/lang/pattern_language.cpp source/lang/preprocessor.cpp @@ -36,4 +38,9 @@ add_library(libimhex SHARED ) target_include_directories(libimhex PUBLIC include) -target_link_libraries(libimhex PUBLIC imgui nlohmann_json) + +if (WIN32) + target_link_libraries(libimhex PUBLIC imgui nlohmann_json libmbedcrypto.a) +else () + target_link_libraries(libimhex PUBLIC imgui nlohmann_json mbedcrypto) +endif () \ No newline at end of file diff --git a/include/helpers/crypto.hpp b/plugins/libimhex/include/hex/helpers/crypto.hpp similarity index 87% rename from include/helpers/crypto.hpp rename to plugins/libimhex/include/hex/helpers/crypto.hpp index 3637448a7..8438a3934 100644 --- a/include/helpers/crypto.hpp +++ b/plugins/libimhex/include/hex/helpers/crypto.hpp @@ -26,4 +26,6 @@ namespace hex::crypt { std::vector decode64(const std::vector &input); std::vector encode64(const std::vector &input); + + std::vector aesCtrDecrypt(const std::vector &key, std::array nonce, std::array iv, const std::vector &input); } \ No newline at end of file diff --git a/source/helpers/crypto.cpp b/plugins/libimhex/source/helpers/crypto.cpp similarity index 89% rename from source/helpers/crypto.cpp rename to plugins/libimhex/source/helpers/crypto.cpp index c047d4e8d..6531b6445 100644 --- a/source/helpers/crypto.cpp +++ b/plugins/libimhex/source/helpers/crypto.cpp @@ -1,4 +1,4 @@ -#include "helpers/crypto.hpp" +#include #include @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include #include @@ -239,4 +241,24 @@ namespace hex::crypt { return output; } + std::vector aesCtrDecrypt(const std::vector &key, std::array nonce, std::array iv, const std::vector &input) { + std::vector output(input.size()); + mbedtls_cipher_context_t ctx; + + mbedtls_cipher_setup(&ctx, mbedtls_cipher_info_from_type(MBEDTLS_CIPHER_AES_128_CTR)); + + mbedtls_cipher_setkey(&ctx, key.data(), key.size() * 8, MBEDTLS_DECRYPT); + + std::array nonceCounter = { 0 }; + std::copy(nonce.begin(), nonce.end(), nonceCounter.begin()); + std::copy(iv.begin(), iv.end(), nonceCounter.begin() + 8); + + size_t outputSize = output.size(); + mbedtls_cipher_crypt(&ctx, nonceCounter.data(), nonceCounter.size(), input.data(), input.size(), output.data(), &outputSize); + + mbedtls_cipher_free(&ctx); + + return output; + } + } \ No newline at end of file diff --git a/source/views/view_hashes.cpp b/source/views/view_hashes.cpp index 851288d94..a56422d68 100644 --- a/source/views/view_hashes.cpp +++ b/source/views/view_hashes.cpp @@ -2,8 +2,7 @@ #include #include - -#include "helpers/crypto.hpp" +#include #include diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 563563bbf..783115953 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -2,11 +2,11 @@ #include #include -#include "providers/file_provider.hpp" +#include #include -#include "helpers/crypto.hpp" +#include "providers/file_provider.hpp" #include "helpers/patches.hpp" #include "helpers/project_file_handler.hpp" #include "helpers/loader_script_handler.hpp"