From 4720cf9fbe8af1e29edecd84a95e01dce078a80c Mon Sep 17 00:00:00 2001 From: WerWolv Date: Sun, 6 Dec 2020 13:48:56 +0100 Subject: [PATCH] Added possible support for MacOS. Completely untested. Relevant: #32 --- .idea/modules.xml | 8 -------- libs/ImGui/include/imgui_memory_editor.h | 2 +- source/helpers/crypto.cpp | 18 +++++++++--------- source/lang/lexer.cpp | 2 +- source/providers/file_provider.cpp | 12 ++++++++++-- source/views/view_data_inspector.cpp | 2 +- source/views/view_hexeditor.cpp | 4 ++-- source/views/view_information.cpp | 2 +- source/views/view_strings.cpp | 2 +- 9 files changed, 26 insertions(+), 26 deletions(-) delete mode 100644 .idea/modules.xml diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 49d5c485e..000000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/libs/ImGui/include/imgui_memory_editor.h b/libs/ImGui/include/imgui_memory_editor.h index 7c217c29c..86e032c18 100644 --- a/libs/ImGui/include/imgui_memory_editor.h +++ b/libs/ImGui/include/imgui_memory_editor.h @@ -227,7 +227,7 @@ struct MemoryEditor footer_height += height_separator + ImGui::GetFrameHeightWithSpacing() * 1; ImGui::BeginChild("offset", ImVec2(0, s.LineHeight), false, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoNav); - ImGui::Text("% *c ", s.AddrDigitsCount, ' '); + ImGui::Text("%*c ", s.AddrDigitsCount, ' '); for (int i = 0; i < Cols; i++) { float byte_pos_x = s.PosHexStart + s.HexCellWidth * i; if (OptMidColsCount > 0) diff --git a/source/helpers/crypto.cpp b/source/helpers/crypto.cpp index fa234287d..7bf3c58a9 100644 --- a/source/helpers/crypto.cpp +++ b/source/helpers/crypto.cpp @@ -41,7 +41,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; offset < size; offset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); for (size_t i = 0; i < readSize; i++) { @@ -74,7 +74,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; offset < size; offset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); for (size_t i = 0; i < readSize; i++) { @@ -94,7 +94,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); MD4_Update(&ctx, buffer.data(), readSize); } @@ -113,7 +113,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); MD5_Update(&ctx, buffer.data(), readSize); } @@ -131,7 +131,7 @@ namespace hex { SHA1_Init(&ctx); std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); SHA1_Update(&ctx, buffer.data(), readSize); } @@ -150,7 +150,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); SHA224_Update(&ctx, buffer.data(), readSize); } @@ -169,7 +169,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); SHA256_Update(&ctx, buffer.data(), readSize); } @@ -188,7 +188,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); SHA384_Update(&ctx, buffer.data(), readSize); } @@ -207,7 +207,7 @@ namespace hex { std::array buffer = { 0 }; for (u64 bufferOffset = 0; bufferOffset < size; bufferOffset += buffer.size()) { - const u64 readSize = std::min(buffer.size(), size - bufferOffset); + const u64 readSize = std::min(u64(buffer.size()), size - bufferOffset); data->read(offset + bufferOffset, buffer.data(), readSize); SHA512_Update(&ctx, buffer.data(), readSize); } diff --git a/source/lang/lexer.cpp b/source/lang/lexer.cpp index 60af18b8e..f607f55b0 100644 --- a/source/lang/lexer.cpp +++ b/source/lang/lexer.cpp @@ -231,7 +231,7 @@ namespace hex::lang { char *end = nullptr; std::strtoull(&code[offset], &end, 0); - auto integer = parseInt(std::string_view(&code[offset], end)); + auto integer = parseInt(std::string_view(&code[offset], end - &code[offset])); if (!integer.has_value()) { this->m_error = { lineNumber, "Invalid integer literal" }; diff --git a/source/providers/file_provider.cpp b/source/providers/file_provider.cpp index a6deb2a0d..3a4abb700 100644 --- a/source/providers/file_provider.cpp +++ b/source/providers/file_provider.cpp @@ -9,18 +9,26 @@ #include "helpers/utils.hpp" #include "helpers/project_file_handler.hpp" + +#ifdef __APPLE__ + #define off64_t off_t + #define fopen64 fopen + #define fseeko64 fseek + #define ftello64 ftell +#endif + namespace hex::prv { FileProvider::FileProvider(std::string_view path) : Provider(), m_path(path) { this->m_fileStatsValid = stat(path.data(), &this->m_fileStats) == 0; - this->m_file = fopen(path.data(), "r+b"); + this->m_file = fopen64(path.data(), "r+b"); this->m_readable = true; this->m_writable = true; if (this->m_file == nullptr) { - this->m_file = fopen(path.data(), "rb"); + this->m_file = fopen64(path.data(), "rb"); this->m_writable = false; } diff --git a/source/views/view_data_inspector.cpp b/source/views/view_data_inspector.cpp index 892910bd9..8b41313a8 100644 --- a/source/views/view_data_inspector.cpp +++ b/source/views/view_data_inspector.cpp @@ -13,7 +13,7 @@ namespace hex { View::subscribeEvent(Events::RegionSelected, [this](const void* userData){ Region region = *static_cast(userData); - this->m_validBytes = std::min(this->m_dataProvider->getSize() - region.address, sizeof(PreviewData)); + this->m_validBytes = std::min(u64(this->m_dataProvider->getSize() - region.address), u64(sizeof(PreviewData))); std::memset(&this->m_previewData, 0x00, sizeof(PreviewData)); this->m_dataProvider->read(region.address, &this->m_previewData, this->m_validBytes); diff --git a/source/views/view_hexeditor.cpp b/source/views/view_hexeditor.cpp index 16f8ea4d9..7cf769e76 100644 --- a/source/views/view_hexeditor.cpp +++ b/source/views/view_hexeditor.cpp @@ -748,7 +748,7 @@ R"( std::vector buffer(1024, 0x00); size_t dataSize = provider->getSize(); for (u64 offset = 0; offset < dataSize; offset += 1024) { - size_t usedBufferSize = std::min(buffer.size(), dataSize - offset); + size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset); provider->read(offset, buffer.data(), usedBufferSize); for (u64 i = 0; i < usedBufferSize; i++) { @@ -786,7 +786,7 @@ R"( std::vector buffer(1024, 0x00); size_t dataSize = provider->getSize(); for (u64 offset = 0; offset < dataSize; offset += 1024) { - size_t usedBufferSize = std::min(buffer.size(), dataSize - offset); + size_t usedBufferSize = std::min(u64(buffer.size()), dataSize - offset); provider->read(offset, buffer.data(), usedBufferSize); for (u64 i = 0; i < usedBufferSize; i++) { diff --git a/source/views/view_information.cpp b/source/views/view_information.cpp index 0386b2e76..bf9439d5e 100644 --- a/source/views/view_information.cpp +++ b/source/views/view_information.cpp @@ -63,7 +63,7 @@ namespace hex { for (u64 i = 0; i < this->m_dataProvider->getSize(); i += this->m_blockSize) { std::array blockValueCounts = { 0 }; - this->m_dataProvider->read(i, buffer.data(), std::min(size_t(this->m_blockSize), this->m_dataProvider->getSize() - i)); + this->m_dataProvider->read(i, buffer.data(), std::min(u64(this->m_blockSize), this->m_dataProvider->getSize() - i)); for (size_t j = 0; j < this->m_blockSize; j++) { blockValueCounts[buffer[j]]++; diff --git a/source/views/view_strings.cpp b/source/views/view_strings.cpp index 0e09cfc09..a49eb3cde 100644 --- a/source/views/view_strings.cpp +++ b/source/views/view_strings.cpp @@ -55,7 +55,7 @@ namespace hex { std::vector buffer(1024, 0x00); u32 foundCharacters = 0; for (u64 offset = 0; offset < this->m_dataProvider->getSize(); offset += buffer.size()) { - size_t readSize = std::min(buffer.size(), this->m_dataProvider->getSize() - offset); + size_t readSize = std::min(u64(buffer.size()), this->m_dataProvider->getSize() - offset); this->m_dataProvider->read(offset, buffer.data(), readSize); for (u32 i = 0; i < readSize; i++) {