Page 1 of 1

Add new segment to the existing Mach-O file

PostPosted: Fri Aug 01, 2014 11:58 pm
by MaxBrein
I'm looking for way to add a new segment with section to a existed file.

The segment will contain zero sized section, so content doesnt matter.
As I understand I should add new load command LC_SEGMENT to a macho header ? Or I should allocate a space for section too ?

Re: Add new segment to the existing Mach-O file

PostPosted: Fri May 08, 2015 10:31 pm
by morpheus
Another question I missed...

Adding a new load command is basically the way to do it: an LC_SEGMENT contains 1 or more sections in it. Sections are parts of the segments. So you basically need to do what codesign_allocate does - i.e. create a new load command (LC_SEGMENT), inject it anywhere within the Mach-O, and rewrite the header. The functionality exists (albeit hidden) in tool already.