diff --git a/lib/external/pattern_language b/lib/external/pattern_language index 3717689c3..24612218e 160000 --- a/lib/external/pattern_language +++ b/lib/external/pattern_language @@ -1 +1 @@ -Subproject commit 3717689c374cd5e8645de258c09c15ebf7a8a91a +Subproject commit 24612218e4d4f085c82cbbbaa6a25a5a9bcc7ec7 diff --git a/lib/libimhex/source/helpers/file.cpp b/lib/libimhex/source/helpers/file.cpp index 752cf9c4f..890210287 100644 --- a/lib/libimhex/source/helpers/file.cpp +++ b/lib/libimhex/source/helpers/file.cpp @@ -1,5 +1,7 @@ #include + #include +#include namespace hex::fs { @@ -77,7 +79,8 @@ namespace hex::fs { if (bytes.empty()) return ""; - return { reinterpret_cast(bytes.data()), bytes.size() }; + const char *cString = reinterpret_cast(bytes.data()); + return { cString, std::strlen(cString) }; } void File::write(const u8 *buffer, size_t size) { diff --git a/lib/libimhex/source/helpers/tar.cpp b/lib/libimhex/source/helpers/tar.cpp index 5135c848f..2035599b3 100644 --- a/lib/libimhex/source/helpers/tar.cpp +++ b/lib/libimhex/source/helpers/tar.cpp @@ -59,24 +59,28 @@ namespace hex { mtar_write_data(&this->m_ctx, data.data(), data.size()); } - void Tar::extract(const std::fs::path &path, const std::fs::path &outputPath) { - mtar_header_t header; - mtar_find(&this->m_ctx, path.string().c_str(), &header); - + static void writeFile(mtar_t *ctx, mtar_header_t *header, const std::fs::path &path) { constexpr static u64 BufferSize = 1_MiB; - fs::File outputFile(outputPath, fs::File::Mode::Create); + fs::File outputFile(path, fs::File::Mode::Create); - std::vector buffer(BufferSize, 0x00); - for (u64 offset = 0; offset < header.size; offset += BufferSize) { - mtar_read_data(&this->m_ctx, buffer.data(), std::min(BufferSize, header.size - offset)); + std::vector buffer; + for (u64 offset = 0; offset < header->size; offset += BufferSize) { + buffer.resize(std::min(BufferSize, header->size - offset)); + + mtar_read_data(ctx, buffer.data(), buffer.size()); outputFile.write(buffer); } } - void Tar::extractAll(const std::fs::path &outputPath) { - constexpr static u64 BufferSize = 1_MiB; + void Tar::extract(const std::fs::path &path, const std::fs::path &outputPath) { + mtar_header_t header; + mtar_find(&this->m_ctx, path.string().c_str(), &header); + writeFile(&this->m_ctx, &header, outputPath); + } + + void Tar::extractAll(const std::fs::path &outputPath) { mtar_header_t header; while (mtar_read_header(&this->m_ctx, &header) != MTAR_ENULLRECORD) { const auto filePath = std::fs::absolute(outputPath / std::fs::path(header.name)); @@ -84,13 +88,8 @@ namespace hex { if (filePath.filename() != "@PaxHeader") { std::fs::create_directories(filePath.parent_path()); - fs::File outputFile(filePath, fs::File::Mode::Create); - std::vector buffer(BufferSize, 0x00); - for (u64 offset = 0; offset < header.size; offset += BufferSize) { - mtar_read_data(&this->m_ctx, buffer.data(), std::min(BufferSize, header.size - offset)); - outputFile.write(buffer); - } + writeFile(&this->m_ctx, &header, filePath); } mtar_next(&this->m_ctx);