From ee3f1292d0e7cb90e2cbf8a57088bc738ac0f79b Mon Sep 17 00:00:00 2001 From: John Reiser Date: Thu, 11 Jan 2018 11:33:15 -0800 Subject: [PATCH] fix editing rot for mach-o .dylib https://github.com/upx/upx/issues/57 modified: p_mach.cpp --- src/p_mach.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/p_mach.cpp b/src/p_mach.cpp index 010fa74d..ff0e1a98 100644 --- a/src/p_mach.cpp +++ b/src/p_mach.cpp @@ -1366,7 +1366,6 @@ void PackMachBase::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e unsigned const sz_threado = threado_size(); MemBuffer space(sz_threado); memset(space, 0, sz_threado); fo->write(space, sz_threado); - sz_mach_headers = fo->getBytesWritten(); } else if (my_filetype == Mach_header::MH_DYLIB) { Mach_command const *ptr = (Mach_command const *)rawmseg; @@ -1398,13 +1397,10 @@ void PackMachBase::pack1(OutputFile *const fo, Filter &/*ft*/) // generate e } memset(&linkitem, 0, sizeof(linkitem)); fo->write(&linkitem, sizeof(linkitem)); - fo->write(rawmseg, mhdri.sizeofcmds); - - gap = secTEXT.offset - sz_mach_headers; } sz_mach_headers = fo->getBytesWritten(); - MemBuffer filler(gap); - memset(filler, 0, gap); + gap = secTEXT.offset - sz_mach_headers; + MemBuffer filler(gap); filler.clear(); fo->write(filler, gap); sz_mach_headers += gap;