71

I browsed a lot, but can't find any resources for reverse engineering an IPA file (iPhone application). Is there any method to reverse engineer an IPA file to its source? I've tried to rename it to zip and open it via Winrar/Winzip to view its source, but it doesn't seem helpful.

What are the possibilities to decompile/reverse engineer an IPA file to its source code?

1
  • Requires a jailbroken iphone 1. In cydia -> Sources -> edit-> Add -> cydia.iphonecake.com 2. In cydia -> Download CrackerXI+ & Install CrackerXI+ 3. In CrackerXI -> Settings -> Enable CrackerXI Hook 4. In Apps -> click the App 5. SSH to Iphone (ssh root@<IP_Address>) -> Download the IPA Commented Sep 26, 2022 at 18:18

7 Answers 7

70

If the IPA file is straight from iTunes/iPhone (without any modification), the code section in the binary (as indicated by the Info.plist) is encrypted with FairPlay (Apple's proprietary DRM). If you are unsure, you can check whether the cryptid bit is set with otool (see this page).

otool -arch armv7 -l thebinary | grep crypt

(where thebinary is the executable binary - see the app's Info.plist, CFBundleExecutable key)

Pre Decryption:

if cryptid is 0, you can proceed on to the Post Decryption section. Otherwise, you will need to decrypt the app. The typical method in brief (with a jailbroken iOS device) is to

  1. Install otool, gdb and ldid from Cydia
  2. Install the IPA on an authorized device
  3. Run otool on the binary to get information such as the size of the encrypted payload
  4. Launch the app and suspend it immediately
  5. Use gdb to dump the payload (beginning from 0x2000) gdb -p <process id> then dump output.bin 0x2000 0xNNNN where NNNN is the sum of the beginning (0x2000) and the payload size
  6. Create a new file, using the first 0x1000 bytes of the original binary, and appended with the dump file
  7. Use ldid to sign the new binary, and change the cryptid to 0 (so that iOS won't decrypt the decrypted app again)

There are many tools of dubious purposes (piracy) which automates the process, however the above is the gist of how the process is done.

Post Decryption:

You can begin reverse engineering the code when you have access to an unencrypted copy of the binary.

One possible tool is IDA Pro (Free version does not support ARM). It may still be quite messy since much of iOS's code works with objc_sendMsg(). This IDA plugin may help: https://github.com/zynamics/objc-helper-plugin-ida

When you are patching functions, an easier way to work (if you know Objective-C) is to use MobileSubstrate to hook the relevant functions. See Dustin Howett's theos if you would like to try this method.

Useful Links:

More about the decryption process: http://iphonedevwiki.net/index.php/Crack_prevention

Getting otool: https://apple.stackexchange.com/questions/21256/i-cant-find-otool-on-my-jailbroken-ipod

Signing with ldid (since the original signature is made invalid after editing) http://www.saurik.com/id/8

For newer devices

Some of the tools (gdb in my base) are not working reliably on the iPhone 5S / iOS7. Currently a method that works is to use a popular open-source cracking software "Clutch". The actual cracking process can be found here: https://github.com/KJCracks/Clutch/blob/master/Clutch/Binary.m

iOS 11

Bishop Fox's bfdecrypt, used together with their bfinject should work for iOS 11.

1
22

After decrypting an IPA file on a jailbroken iDevice, you can use a much more affordable alternative to IDA Pro called Hopper - the multi-platform disassembler for < $100.

https://www.hopperapp.com/

It has support for analyzing iOS executables (among others) and even comes with the ability to convert ARM assembly to pseudo-C.

Hopper screenshot with example disassembly and pseudocode

2
  • to use on ubuntu, after add the repo, you need to install libgvc5, add to ldconfig and execute as sudo
    – albfan
    Commented Oct 24, 2013 at 10:34
  • But the current version (3) doesn't support 64 bit ARM – too bad, really.
    – adib
    Commented Mar 7, 2016 at 8:53
11

Other users have done a good job with the elements of this question that are specific to the IPA format. As for obtaining the source code to a binary object, please see this answer as for why this may be more difficult than you expect (as compared to, say, bytecode language decompilation).

10

If you have a jailbroken iDevice, AppSec Labs' iNalyzer can automate some of this process for you as well as provide you with a great way to review an iOS application.adding the appropriate repo

You can install iNalyzer from Cydia after adding the appropriate repo.

In my experience, it's easiest to work with the iNalyzer created project files (that you will copy from your iDevice after running iNalyzer) from a Linux machine because the tool will require doxygen and Graphviz Dot to be installed to create it's HTML report.

AppSec Labs iNalyzer is a framework for manipulating iOS applications, tampering with parameters and methods; no sources needed! AppSec Labs iNalyzer targets closed applications, turning a painful Black Box into an automatic Gray-Box effort.

AppSec Labs iNalyzer Automates your testing effort as it exposes the internal logic of your target iOS application and the correlation between hidden functionalities. The AppSec Labs iNalyzer allows you to use your daily web-based pen-testing tools such as scanners, proxies etc. AppSec Labs iNalyzer maintains the attack logic and forwards it onto the targeted iOS application. No more manual BruteForce, Fuzzing, SQL injection and other tedious manual work!

10

I would recommend checking out Frida. It's an open source instrumentation toolkit for iOS, Android, Windows, Mac and Linux.

Check out this tutorial to dive in by building your own debugger in 5 minutes using Frida and Qml. The last part shows how to inject code into the “Yo” app and plot its network connections on Google Maps.

2
  • 1
    nicely written app,would like to explore more in it,any video tutorial? Commented Jun 30, 2014 at 5:21
  • 1
    Not yet unfortunately, only the docs at frida.re, but I'm planning to do more blog posts and tutorials in the time to come. Feel free to drop by #Frida on irc.freenode.net if you have any questions, or shoot me an email to oleavr at gmail dot com. Commented Jun 30, 2014 at 23:32
5

dumpdecrypted can automate the decryption of the iOS binary. Additionally, there is a tool called iRET that you can use that automates alot of the analysis and reversing for you.

1

Rasticrac can also automate the decryption (FairPlay DRM) of the iOS binary and is very easy to use!

Rasticrac

Rapid Advanced Secure Thorough Intelligent Gaulish Nuclear Acclaimed Cracker

Rasticrac is a very powerful tool to decrypt the iOS app binaries. You can install Rasticrac with Cydia by adding the following Repo source in Cydia: http://cydia.iphonecake.com

4
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. Commented Dec 18, 2014 at 10:15
  • 1
    What?! I don't think this is a link ? (;
    – David L-R
    Commented Dec 18, 2014 at 13:27
  • Would you mind adding some more content, like how it can do that?
    – 0xC0000022L
    Commented Dec 21, 2014 at 20:55
  • You can have a look at this blog, there is a detailed description: reverseengineeringapps.blogspot.de
    – David L-R
    Commented Dec 22, 2014 at 18:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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