From 1b3ad96fc111825b1673460bd2992a742257182c Mon Sep 17 00:00:00 2001 From: lzwdgc Date: Fri, 7 Jun 2024 02:03:07 +0300 Subject: [PATCH] [mod][bin] Fill replacement string with zeroes. --- src/aim1_mod_maker/aim1_mod_maker.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/aim1_mod_maker/aim1_mod_maker.h b/src/aim1_mod_maker/aim1_mod_maker.h index 1af085c..73805e5 100644 --- a/src/aim1_mod_maker/aim1_mod_maker.h +++ b/src/aim1_mod_maker/aim1_mod_maker.h @@ -178,9 +178,12 @@ struct bin_patcher { } v ^= value; } - static void replace_bin_in_file_raw(const path &fn, const std::string &from, const std::string &to) { + static void replace_bin_in_file_raw(const path &fn, const std::string &from, std::string to) { + if (to.size() > from.size()) { + throw std::runtime_error{"replacement string is larger than original"}; + } if (from.size() != to.size()) { - throw std::runtime_error{"mismatched size"}; + to.resize(from.size(), '\0'); } primitives::templates2::mmap_file f{fn, primitives::templates2::mmap_file::rw{}}; while (auto p = memmem(f.p, f.sz, from)) {