>From 5b9c1a0ebab3825dce85bc81139c36787923eec0 Mon Sep 17 00:00:00 2001 From: Roland Kaufmann Date: Thu, 27 Dec 2018 15:57:42 +0100 Subject: [PATCH 3/6] Allow padding of sections to other than page size --- src/unexmacosx.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/unexmacosx.c b/src/unexmacosx.c index d274ab7..561a509 100644 --- a/src/unexmacosx.c +++ b/src/unexmacosx.c @@ -191,7 +191,8 @@ static unsigned long curr_header_offset = sizeof (struct mach_header); static unsigned long curr_file_offset = 0; static unsigned long pagesize; -#define ROUNDUP_TO_PAGE_BOUNDARY(x) (((x) + pagesize - 1) & ~(pagesize - 1)) +#define ROUNDUP_TO_BOUNDARY(x,size) (((x) + size - 1) & ~(size - 1)) +#define ROUNDUP_TO_PAGE_BOUNDARY(x) ROUNDUP_TO_BOUNDARY(x,pagesize) static int infd, outfd; @@ -1125,13 +1126,16 @@ copy_dyld_info (struct load_command *lc, long delta) load command from the input file to the output file, adjusting the data offset field. */ static void -copy_linkedit_data (struct load_command *lc, long delta) +copy_linkedit_data (struct load_command *lc, long delta, long alignment) { struct linkedit_data_command *ldp = (struct linkedit_data_command *) lc; if (ldp->dataoff > 0) ldp->dataoff += delta; + /* add bytes necessary to be at given alignment */ + ldp->dataoff = ROUNDUP_TO_BOUNDARY (ldp->dataoff, alignment); + printf ("Writing "); print_load_command_name (lc->cmd); printf (" command\n"); @@ -1222,7 +1226,7 @@ dump_it (void) #ifdef LC_DYLIB_CODE_SIGN_DRS case LC_DYLIB_CODE_SIGN_DRS: #endif - copy_linkedit_data (lca[i], linkedit_delta); + copy_linkedit_data (lca[i], linkedit_delta, 1); break; #endif default: -- 2.25.2