Adding and using an executable file in iOS at runtime - ios

Suppose, I have some external executable file(call it a .swift file) that are not linked with the xcode project at compile time. That means, I did not have any of those files in my project tree when built the project.
For an example, lets say I have a file called exc.swift. This file was not included while I built the project.
Is there any way that I can execute that executable (the exc.swift) file at runtime?
In android there is a way by using DexClassLoader class. That class is responsible for executing code not installed as part of an application.
The documentation for that class is here.
Is there an iOS equivalent version of this? or in any way is this achievable?

If you are hoping to distribute the app that you are writing, then this is an absolute no-no. The app store review guidelines clearly state "Apps that install or launch other executable code will be rejected" so no app that exhibits this functionality will ever get onto the app store. You may be able to find or devise some kind of hack or workaround to get this kind of thing to work, but it will only ever be for your own amusement.

Related

ios Static Library - how obfuscate directly?

I have an application Unity that uses the iOS static library. Then this application Unity is build in XCode. I found several utilities that allow you to obfuscate the library in the application. for example this - PPiOS-Rename.
I carefully read their documentation "Obfuscate Static Libraries", but at the time of building, the iOS static library are already "hidden in the root" of the Unity app, and XCode cannot obfuscate this.
So I need to first obfuscate the library and then add it to the application. or is it not possible?
In my understanding of the documentation PPiOS-Rename stays an external tool, just the files *.plist can be added into the releases, for being able to use the tool on the compiled releases.
I might be completely wrong about it, especially as without iOS I can't test it, but I'd check if my statement is right and if you can omit the step to include the library in your compiled releases.
About handling of *.plist files, follow the instructions on the linked page, I'm not sure if you have one or more in the end. As it doesn't seem relevant to the core of your question, I never verified it deeper.

Updating .stringsdict localization files over-the-air

I'm looking for a way to update stringsdict localization files over-the-air without having to release a new version in the appStore. So ideally I want my stringdict files on a webserver, and the iOS app should download these files from the website and update the local strings.
After doing some research, I realized that we cannot update files in the bundle it was shipped in however I found some reports saying we could store/load localizations in/from the application support folder.
source #1
source #2
source #3
Can this also be applied to stringsdict files because I'm trying but no success so far.
Basically you need to create a .bundle with your new strings and make your app download it. After that, I think it's possible to create a NSBundle object using your freshly downloaded translations and swizzle a couple of methods from the main NSBundle currently used by the system.
I've tried something similar, but found out that it's much easier to integrate an existing service such as Smartling or Lokalise. They already have an SDK that allows you to update your translation over the air.
Also I found it's much easier to manage all my translations there.

How to decompile iOS apps?

I want to see the code of an iOS app.
The app I downloaded is .deb.
First question: Is it possible to install .deb file on iOS or I downloaded a wrong file?
After unpacking the .deb file, I got some files, including .nib, .storyboard and some other files.
My main question is, How to decompile these .nib files?
I tried to decompile these files using NibToXibConverter, but I didn't succeed.
Answer to your first question:
I think you downloaded the wrong file. .deb files for iOS are common for jailbreak community and not for apps, I think all of the Cydia stuffs are packed into .deb's. If your app is especially made for the jailbreak scene then you may try to install it using Cydia's auto install feature on a jailbroken device.
Answer to your main question:
This is general info about decompiling and modifying iOS apps (not specific for nibs, but you may still find it useful).
iOS apps are distibuted in .ipa archives, which are ordinary zip archives. They contain, usually one executable in the form of Mach-O file, and resources like .plist, sounds, images - every resource you include in your xcode project. Decompiling the executable file is only possible on jailbroken iDevice, because it is encrypted especially for the current device and the magic key to decrypt the binary is burned inside the device CPU and as far as I know there is no software way to read that key. The encryption system here is called FairPlay.
Briefly described, one way to decrypt that binary is to have the app installed on a jailbroken device, and launch it from command line using a debugger (gdb) which you can download from Cydia. You have to set a breakpoint somewhere, and when your code execution pauses at the breakpoint, you are doing a memory dump of the device ram - and that is your decrypted bin.
So when you have the decrypted binary, you can run one tool called "class-dump", and get the information for declared classes and their methods if the app is written in Objective C. Once you know this information you can alter the implementation of given method from some class used in your app using "Cydia Subtstrate" a.k.a "Mobile Substrate". In fact that is the way all of the jailbroken iOS tweaks are made. Basically you are hooking a method call, and when that method get invoked, it uses your implementation. Furthermore your implementation can call the original implementation, and that is really useful if you want to make some small code addition.
I am not sure whether those things possible in Swift, but if you are dealing with a Hybrid app like the ones done with cordova, phonegap, etc., then you can see all of its javascript source because it is persisted as a resource inside the "ipa" file. In addition you can alter that javascript code directly if you have a jailbroken device and find where the app is installed on file system (usually /var/containers/Bundle/Application/uuid_for_your_app/). However, I think there is no way to get that patched version and redistribute it (correct me if I'm wrong).

What is the exact build process of an ios app in XCode?

I am making an iOS app and I wanted to know what the build process is exactly. I don't mean want something like, it compiles, then it links and then its done. I want to know exactly what each step does like android has build steps viz. resource manager, pre-compiler, java builder, package builder, How are these steps taken care of in IOS. Secondly, what is the importance of .app file which is created with xcodebuild command to eventually create .ipa file.
Here are some links that might help:
Joshua Davies walks through building a simple Hello World app outside of Xcode:
http://commandlinefanatic.com/cgi-bin/showarticle.cgi?article=art024
A .ipa file is just a zip archive with a predefined structure. The iPhone wiki describes it well:
http://theiphonewiki.com/wiki/IPA_File_Format

How to insert a LC_LOAD_DYLIB command into a Mach-O binary or join a static library to an existing binary (IOS)

This is the first time I am asking on stackoverflow and I am desperate.
My task is to load a dylib or join a static lib to an already existing executable for an IOS device.
I will be using the static void __attribute__((constructor)) initialize(void) to start the swizzling.
This executable is for in house enterprise appstore so i do not need to go thru the apple appstore (since they will reject it).
The reason for this is to take an existing IPA from a customer and their signing keys and add a new functionality to their application without requiring a developer intervention.
There is one company doing that called nukona. You can watch the movie here: https://www.youtube.com/watch?feature=player_embedded&v=z9rrOB6lOxY
I can tell you that i tried to put LSEnvironment inside the plist file with a DYLD_INSERT_LIBRARIES but it turns out LSEnvironment does not seem to have any effect in the sandbox of an IOS application.
I also tried install_name_tool for changing one of the dependencies and replacing it with my dylib (which has that dependecy as well). It crashes without information why.
Obviously, if i add the dylib to a test application in XCode and recompile it works perfectly which is a given. However, this is something i cannot ask, for example, an administrator of a company. Rebuilding may deter customers of using this lib.
Here is a related link i found on stack overflow but for osx and i need it for IOS.
How to insert a LC_LOAD_DYLIB command into a Mach-O binary (OSX)
The only thing i can think off is to edit the binary load commands some how, but i am not sure how and how to do it taking into account the relocation tables etc...
Any alternative is welcome.
Thank you for your time.
I open-sourced optool which does exactly this (I haven't tested it on iOS but it should work. Open up an issue if you have problems)

Resources