Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encrypt or obfuscate objective c code? [duplicate]

Possible Duplicate:
iPhone/iPad App Code Obfuscation - Is it Possible? Worth it?

I have spent a lot of time on this and I couldn't able to find a perfect answer. That's why I decided to put my question here. I have an iPhone application and want to encrypt the code to prevent from class-dump or otool utilities. (Tools used to dump out the headers from executable). I would like to know is there any way to encrypt the source code or obfuscate the source code?

like image 278
Johny_568 Avatar asked Jun 06 '11 07:06

Johny_568


People also ask

How do you obfuscate in Objective C?

There is no easy way to do code obfuscation in Objective-C. It is possible, but be ready to be extremely limited in how you do your development. There are plenty of posts on the subject if you search for them on StackOverflow or your favorite search engine. You might wish to look at PPiOS-Rename.


2 Answers

It's a lot more complicated than it might seem initially. Any tool that mangles method names has the potential to fudge up:

  1. KVC compliance
  2. The use of dynamically generated selectors
  3. Nib file compatibility
  4. Protocol conformance
  5. Method inheritance

Obfuscation is just another layer to deal with; often obfuscation is easily reversed. It is not really possible to “encrypt” your classes because the Objective-C runtime and Cocoa framework won't know how to decrypt it. Anyone determined enough will eventually figure out how your program works.

like image 149
dreamlax Avatar answered Oct 20 '22 03:10

dreamlax


Actually you can provide some obfuscation and tamper protection with specialist 3rd party tools. There are 2 companies, I know of, that provide tools or services to do this : Arxan and irDato.

Neither are cheap or accessible to small developers but if you are developing for a large corporation then you should consider them.

Obfuscation is done by mangling code paths and adding redundant instructions so as to confuse anybody trying to reverse engineer the code. Tamper protection is done by adding checksums to the code and embedding checksum checks within functions. You can create a network of interdependent checksums that makes it extremely difficult to bypass them. There are a few other things that can be done but you really need to talk to specialists in this area.

Further to the earlier answer, Apple does not encrypt the binaries but just signs them. It is fairly easy to reverse engineer and modify app binaries on a jailbroken device.

like image 33
Andrew Avatar answered Oct 20 '22 05:10

Andrew