Converting an executable into a shared library?

Questions and Answers about all things *OS (macOS, iOS, tvOS, watchOS)

Converting an executable into a shared library?

Postby johncoates » Thu Aug 31, 2017 2:44 am

Before I go off and try writing a converter, I was wondering if anyone here has experience or guidance in this?
As far as I can tell all you would need to do would need to do is update the header to MH_DYLIB, then strip out the LC_MAIN load command and add in LC_ID_DYLIB. Anything I'm missing here?
johncoates
 
Posts: 3
Joined: Thu Aug 31, 2017 2:34 am

Re: Converting an executable into a shared library?

Postby Siguza » Thu Aug 31, 2017 2:46 am

You should probably also remove __PAGEZERO...
User avatar
Siguza
Unicorn
 
Posts: 159
Joined: Thu Jan 28, 2016 10:38 am

Re: Converting an executable into a shared library?

Postby johncoates » Thu Aug 31, 2017 2:58 am

Gotcha, had to look up what that segment contains. Hope I'm not missing anything and it's as simple as that.
johncoates
 
Posts: 3
Joined: Thu Aug 31, 2017 2:34 am

Re: Converting an executable into a shared library?

Postby johncoates » Thu Aug 31, 2017 5:56 am

It's kind of working!
When I try and use a class it errors out with dyld: Symbol not found: _OBJC_CLASS_$_example
However if I use it dynamically like so: [NSClassFromString(@"example") print]; it works.

So this is what I've done so far:
- renaming __PAGEZERO to nullify it
- remove LC_MAIN
- remove LC_LOAD_DYLINKER
- add LC_ID_DYLIB
- Change _OBJC_CLASS_$_example & _OBJC_METACLASS_$_example from N_PEXT to N_EXT

I'm thinking that LC_DYLD_INFO_ONLY's exports will need to be filled in with references to the class and meta class.
johncoates
 
Posts: 3
Joined: Thu Aug 31, 2017 2:34 am

Re: Converting an executable into a shared library?

Postby scknight » Tue Sep 05, 2017 12:05 pm

Very cool. Keep us updated with what all you need to add/change to get it to work.
scknight
 
Posts: 27
Joined: Thu Nov 10, 2016 1:01 pm


Return to Questions and Answers

Who is online

Users browsing this forum: No registered users and 6 guests