From 0f1623163891e019fe5d5bdbd652dc5fb123f30e Mon Sep 17 00:00:00 2001 From: jakcron Date: Wed, 29 Sep 2021 18:28:49 +0800 Subject: [PATCH] Add getTruncatedBytesString() to utils. --- src/util.cpp | 18 ++++++++++++++++++ src/util.h | 2 ++ 2 files changed, 20 insertions(+) diff --git a/src/util.cpp b/src/util.cpp index ccb157b..8db21e2 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -97,4 +97,22 @@ void nstool::writeStreamToStream(const std::shared_ptr& in_stre remaining_data -= int64_t(cache_read_len); } +} + +std::string nstool::getTruncatedBytesString(const byte_t* data, size_t len, bool do_not_truncate) +{ + if (data == nullptr) { return fmt::format(""); } + + std::string str = ""; + + if (len <= 8 || do_not_truncate) + { + str = tc::cli::FormatUtil::formatBytesAsString(data, len, true, ""); + } + else + { + str = fmt::format("{:02X}{:02X}{:02X}{:02X}...{:02X}{:02X}{:02X}{:02X}", data[0], data[1], data[2], data[3], data[len-4], data[len-3], data[len-2], data[len-1]); + } + + return str; } \ No newline at end of file diff --git a/src/util.h b/src/util.h index 04e01fb..2611acc 100644 --- a/src/util.h +++ b/src/util.h @@ -10,4 +10,6 @@ void writeSubStreamToFile(const std::shared_ptr& in_stream, int void writeStreamToFile(const std::shared_ptr& in_stream, const tc::io::Path& out_path, size_t cache_size = 0x10000); void writeStreamToStream(const std::shared_ptr& in_stream, const std::shared_ptr& out_stream, size_t cache_size = 0x10000); +std::string getTruncatedBytesString(const byte_t* data, size_t len, bool do_not_truncate); + } \ No newline at end of file