user1320885
user1320885

Reputation: 135

How do I convert an armv7 binary to i386/x86_64

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.

Upvotes: 0

Views: 1827

Answers (2)

dgatwood
dgatwood

Reputation: 10407

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. :-)

Upvotes: 2

user149341
user149341

Reputation:

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.

Upvotes: 1

Related Questions