0

I am trying to build a mac(cocoa) app. I have a framework that I am trying to link with that has been compiled for iOS(the armv7 arch). I unfortunately no longer have the source code that I used to compile the original framework. Would it be possible to change the architecture of the framework(perhaps through decompilation and then recompilation) so that it can be compiled into my cocoa app?

So far I have looked into lipo and fat binaries as well as using optool to decompile but haven't made any direct progress towards converting architectures.

Thanks for your help.

2 Answers 2

2

In theory, if the code doesn't use any POSIX system calls directly, it might be possible to create an Frankensteinian abomination:

  • Run the code on an arm64 emulator.
  • Replace all function call linkages into the Objective-C runtime (e.g. objc_msgsend) with emulator traps.
  • Abort if you find any other function call linkages.
  • For runtime function calls, call the equivalent runtime function on the x86-64 side.
  • For alloc calls, return an NSProxy object on the arm64 side that traps into the emulator.
  • For any objects passed via parameters, return values, or return parameters, pass an NSProxy object.

That said, in practice, unless the framework is insanely complex, it would be faster to rewrite the code. And realistically, even if it is insanely complex, if you know enough arm64 asm to pull this off, you can probably rewrite it from the asm more quickly. :-)

2
  • sounds insanely hard, i'll just rewrite it :p Commented Jun 14, 2017 at 3:39
  • Insanely. Like the sort of thing you'd do to prove that it's possible, but would never ship in a million years. :-D
    – dgatwood
    Commented Jun 14, 2017 at 7:26
1

No, there is no reasonable way to automate this conversion. Most C decompilers generate code that is a very literal translation of the assembly; it is usually not suitable for compilation.

(One good decompiler is the Hex-Rays plugin for IDA Pro. However, it is extremely expensive -- a license is over $2000. Unless your framework is particularly large and complex, it may be more cost-effective to work without this tool.)

If you have really lost the source code, your only real option will be to rewrite the framework. You can use the disassembly to guide your efforts, but you will need to fill in some of the details.

Not the answer you're looking for? Browse other questions tagged or ask your own question.