How to get Root privileges developing iPhone app using Xcode - iphone

I cannot access /var/mobile/Library/SMS etc. in xcode even if the iphone is jailbroken.
Apple sandboxing doesn't allow root access.
A Similar Answer is here Gaining root permissions on iOS for NSFileManager (Jailbreak) .
But i am a newbie. Except for the first two steps, i don't understand what he is doing. That would be great if anyone can explain that answer.
OR
Is there any other way to access /private/var/mobile/Library....?
Xcode: 5.0.1
Device: iPhone 5s with iOS 7.1
OSX: 10.9.2

3 . Create a copy of the executable file in the app bundle.
When you build a project in Xcode, it will produce an output directory. This varies by machine, so you'll have to search your filesystem. However, if your app is named HelloWorld, normally, you'd have a directory named HelloWorld.app. This is what the answer is referring to as the app bundle. From the command line (or using your Mac's Finder), go inside HelloWorld.app and make a copy of the HelloWorld executable file. Normally, I name the copy MobileHelloWorld.
4 . Open the original executable file and replace its content with this script:
#!/bin/bash
dir=$(dirname "$0")
exec "${dir}"/COPIED_EXECUTABLE_NAME "$#"
Directly launching a root app fails on iOS. Therefore we replace the app's main
executable with a script that launches the root executable.
I guess I would have described this step differently. You can delete the file. Create a new script with the same filename (HelloWorld) and edit it to include the lines above, starting with #!/bin/bash. Of course, COPIED_EXECUTABLE_NAME would be replaced with MobileHelloWorld in my example.
So, iOS will launch your script directly, instead of your executable. However, your script will then launch your executable and because of the permissions you've given those files, your running executable will have root privileges.
5 . In terminal, navigate to the app bundle.
You're probably already in this "bundle" directory. (HelloWorld.app)
6 . chmod 0775 the original executable file and chmod 6775 the copied executable file.
Issue the chmod command so that the HelloWorld file has 775 permissions (rwxrwxr-x). The MobileHelloWorld file should then have 6775 permissions (rwsrwsr-x).
7 . Copy the app bundle to /Applications to a device. Restart SpringBoard
and you should be good to go. If the app doesn't launch then repeat step 5 & 6
on the device.
Using whatever tool you like (I just use scp since my device is jailbroken with openssh installed), copy the entire HelloWorld.app folder to the iOS device. So, you would have a folder named: /Applications/HelloWorld.app/ which contains the bash script, the copied/renamed executable, and any other bundle resources (.png files, .xib files, etc.) your app contains.
Example
If you have a jailbroken device, install openssh and ssh into the phone, then check out how the Cydia app itself accomplishes this. You can view the /Applications/Cydia.app/Cydia script file, which launches the MobileCydia executable with root privileges.
Another Way
Actually, if you only want to access /var/mobile/Library, that doesn't require root access. That directory is owned by the mobile user, so root isn't necessary. What is necessary is escaping the normal iOS 3rd-party app sandbox. To do that, simply copy your HelloWorld.app folder and its contents to the /Applications/ folder on your device. Apps installed there, as opposed to /var/mobile/Applications won't have such tight sandbox restrictions.
So, none of that copying of the executable, inserting a bash script, are necessary. Steps 3 through 6 can be skipped.
Hope that helps. Sorry for my snarky comment.

Related

Unity3d OSX "Application can't be opened"

I'm using a PC and I've created a build for Mac standalone.
I shared the file with my test user by zipping and emailing the build, but when he tries to run the application he sees this error:
The application "SomeApp.app" can't be opened.
After some searching, I learned that I need to do chmod to open the file. Can anyone tell me how to do that on a Mac?
The zip format doesn't have easy support for Unix-like file permissions, so your transfer process is stripping any permission flags that OSX uses to recognize files within that zip that are supposed to be executable. This can also happen with other file transfer solutions, so it's something to watch out for.
The best solution would be to create an archive which does keep those permissions, such as a tar archive.
Failing that, you can have a Mac user open a terminal and set the permission flag manually:
chmod a+x SomeApp.app/Contents/MacOS/*
(Replace SomeApp.app with whatever your .app folder is named)
I had the same issue, I left an answer here, at the bottom: https://forum.unity.com/threads/mac-build-breaking-when-uploaded-to-storage.1093330/
The problem was not with the .zip, but rather with the build itself. Ran fine on my Mac, did NOT run fine once I uploaded it and downloaded it again (or if anyone else downloaded it).
Edited 12/8/2021, as per EmiOB's suggestion, to add the text of my answer (same as in the link):
This worked for me on 2020.3.16f1:
In the Unity Editor: Build Settings, check the box that lets you make an XCode project (requires having XCode installed, I believe I have Xcode 11)
Open the XCode project
Build
That solved my problem :)

Is there a method for sharing and syncing the iOS simulator Applications folder

Our sales team often needs to give demos of apps currently in development. We've used a variety of methods to get them installed on their laptops but everything has been very manual.
The initial method we were using had us downloading the source code and compiling each and every project for each and every salesman. Very time consuming and annoying.
Then we got a little smarter and realized that we could copy out the Applications folder for the iOS simulator and just past that over the iOS simulator's Applications folder on each salesman's laptop. Much better, but still the manual part of copying them all over to each laptop.
So I started poking around about some folder syncing options for macs and came across this technique http://www.youtube.com/watch?v=iWoXPWlu_Dk
Very awesome and seemed to meet my need exactly. I had one central shared folder I could throw new iOS applications into and then the salesmen's laptops would automagically sync with that applications folder and new apps would just appear with no need to ever have their laptops here.
Unfortunately, the iOS simulator does not seem to be recognizing the Applications folder when it's a symbolic link or alias. Is there some Mac magic that could make this work? (I'm a Windows guy normally, just recently been working in the iOS world, so there could be something basic I'm missing here).
I'd love to have the Applications folder /Application Support/iPhone Simulator/5.1/Applications be a shared folder that syncs automatically for them, grabbing any new applications we have ready for demos (and getting them updates to old ones). Just seems like a nice smooth way to get them early builds.
We've used services like TestFlight for the actual devices and that's a great option for that, but when they don't have a device handy or are just blasting through demos on their laptops we'd love to have a nice easy process for keeping them up to date with new builds for their simulator install.
First a bit of background, you don't really need this, but I like teaching :).
On Unix, and now MacOS, there are two basic kinds of links. 'normal' links, and symbolic links. Alias, on windows, unix and mac are a kind of symbolic link: the link contains a reference to the original file. Normal, or hard links create a second directory entry that points to the data, if you delete the original file, the OS knows that there is still another entry pointing to it, so it only actually deletes the file (or directory) when all hard links have been removed. The disadvantage of hard links is that they have to be on the same file system, so that the file system can keep count of how many hard links there are.
OK, I've just installed Dropbox, and it seems that it creates a real folder in the user's home directory, so unless you're a complicated disk partitioning scheme, or file vault 1, where the user's home directory is actually an encrypted disk image, you can use a hard link. It also means that you don't need to copy or sync, as Dropbox is already doing that.
One thing not corrected, but didn't actually point out is that in your post, you seem to be copying to /Application Support, not ~/Library/Application Support or /Library/Application Support. Since you've got the basic scheme working without dropbox, I'll assume that is a typo.
Before I give you the commands, you might want to delete the old iPhone Simulator Applications directory with the Finder, instead of using the rm command, as the rm command is potentially very destructive.
OK, finally, the commands to do the linking; the quotes are important whenever filenames contain spaces. This example is for ~/Library
rm -rf "~/Library/Application Support/iPhone Simulator/5.1/Applications"
ln "~/Dropbox/Simulator Applications" "~/Library/Application Support/iPhone Simulator/5.1/Applications"
This should work, you can stop reading now, the rest is just more education :)
Tilde (~) is a short cut for the users home directory. Use the commands without this to work on /Library instead.
If you want to be sure you've got the exact path, you can drag files and folders from a finder window into the terminal, the path gets pasted instead of the file.
If you're messing with stuff in the root filesystem, you might need superuser rights. If you are logged in with an admin account, you can run single commands with superuser access as follows.
sudo ln "/Library/Application Support/iPhone Simulator" fred
The shell asks for your password, and then runs the command for you as superuser.
sudo remembers the authorization for a few minutes, then you have to authenticate again.
Haven't tested this since I only have one Mac, but give this a try:
Install Dropbox
Create a shared folder there and copy your apps from /Users/USERNAME/Library/Application Support/iPhone Simulator/5.1/Applications
Create a shell script to copy them back to the simulator's location, and add it to the shared folder. It should look something like this:
#!/bin/sh
cp -R ~/Dropbox/Appfolder/appname ~/Library/Application Support/iPhone Simulator/5.1/Applications/
Have your users sync their dropboxes to get the files, then run the shell script to copy the files.

iOS Writing Files

If a device is jailbroken, the file system is unlocked and open for you to see and modify. If I wanted to write an app that wrote a file to the /private/var/mobile/Library/Preferences/ folder, do I have to use a command other than [fileManager copyItemAtURL:fileTempPathURL toURL:filePathURL error:NULL];
? I'm using this command, but it is not working... Thanks for your help!
If you're on a jailbroken device, you can write to any place in the system. You can do this in many different ways, from the C FILE pointer to all kinds of iOS Foundation methods, like the one you mentioned in your question.
The only thing you'll have to mind is that your application has to be installed in the /Applications directory and not in the ~/Applications directory, what iTunes and Xcode will do by default. Only by putting them in that folder, along with the Apple base applications like MobileSafari, MobileMusicPlayer, etc. your app will launch from the springboard with those root privileges. You can put it in the /Applications folder through SSH.
If you do not manually put your app in the root application folder and your app resides in its own subfolder in ~/Applications like normal App Store applications do, your app will launch in a sandbox. This sandbox will then prevent you from accessing any file outside your application's sandbox.

Compile directly to /Applications from Xcode

First off, I am not publishing this app to the app store and this is a jailbroken phone.
Anyone know how to compile apps directly to the /Applications folder with Xcode? Currently, I am having to compile to the /var/mobile/Applications folder and copying it to the /Applications folder on the device. It would be very convenient if the app could be compiled directly to the /Applications folder. Google doesn't seem to have any results on this topic.
Thanks in advance...
I don't have a jailbroken iPhone, so I can't say if this works, but presuming you can mount the iPhone as a volume on the Mac, you can add a custom script to the compilation in Xcode that does the copying for you.
Presuming that your iPhone is mounted in /mnt/My iPhone
You would add a custom build phase (Editor > Add Build Phase > Add Run Script Phase) and the script would do something like:
cd /var/mobile/Applications
cp myappfile "/mnt/My iPhone/Applications/"
If XCode compiles applications into the same target directory every time, could you put in a symlink to point to your mounted phone? The OS X docs are in the ln(1) manpage, look for -s for details on symlinks.
e.g., remove /var/mobile/Applications/, and replace it with a symlink to wherever your phone's /Applications/ directory is, (I'm guessing /Volumes/WakePhone/Applications/):
rmdir /var/mobile/Applications
ln -s /Volumes/WakePhone/Applications/ /var/mobile/Applications
Of course, this will only let you compile when your phone is mounted. This might be too much hassle.
Why is copying over your application so onerous that you want to compile directly onto the device? There is probably a better solution than this. :)

How can I install a .ipa file to my iPhone simulator

I have an iphone simulator running on my Mac.
I have a .ipa file, can you please tell me how can I install it on the simulator?
You can't. If it was downloaded via the iTunes store it was built for a different processor and won't work in the simulator.
I found an .ipa file that I wanted using iTunes and copied it over to my desktop.
After that I changed the extension to .zip and extracted it.
Next I found the Payload folder and moved the application inside to my desktop.
Finally I moved that application to my iPhone simulators applications folder found at:
HD
> Applications
> Xcode.app (right click - Show Package Contents)
> Contents
> Developer
> Platforms
> iPhoneSimulator.platform
> SDKs
> iPhoneSimulator6.0.sdk
> Applications
(Note: Some apps crash more often than others.)
In Xcode 6+ and iOS8+ you can do the simple steps below
Paste .app file on desktop.
Open terminal and paste the commands below:
cd desktop
xcrun simctl install booted xyz.app
Open iPhone simulator and click on app and use
For versions below iOS 8, do the following simple steps.
Note: You'll want to make sure that your app is built for all architectures, the Simulator is x386 in the Build Settings and Build Active Architecture Only set to No.
Path: Library->Application Support->iPhone Simulator->7.1 (or another version if you need it)->Applications
Create a new folder with the name of the app
Go inside the folder and place the .app file here.
Update for Xcode 9.4.1+
Hope my answer is getting seen down here as this took me a while to figure out but I just got it working.
First of all you need to build and run the App on your simulator. Then you open the Activity Monitor. Double click the name of your App to find its content.
In the next screen open the Open Files and Ports tab and find the line with MyAppName.app/MyAppName.
Copy the link but make sure to stop at the MyAppName.app. Do not copy the path following it.
Control click onto the finder icon and select Go to folder.
]
Paste the path and click enter. You will see your MyAppName.app file.
Copy it to the Desktop and zip it. Move it to your desired 2nd computer and unzip the file. Build a random project to have a simulator open.
Lastly: Literally drag and drop the App from your Desktop into your Simulator. You will see the install and the App opens and does not crash.
You cannot run an ipa file in the simulator because the ipa file is compiled for a phone's ARM architecture, not the simulator's x86 architecture.
However, you can extract an app installed in a local simulator, send it to someone else, and have them copy it to the simulator on their machine.
In terminal, type:
open ~/Library/Application\ Support/iPhone\ Simulator/*/Applications
This will open all the applications folders of all the simulators you have installed. Each of the applications will be in a folder with a random hexadecimal name. You can work out which is your application by looking inside each of them. Once you have found out which one you want, right click it and choose "Compress ..." and it will make a zip file that you can easily copy to another computer and unzip to a similar location.
UPDATE: For Xcode 8.0+ you need to follow below Steps:
Download application from iTunes
Select downloaded app, right click show in finder
Copy .ipa file to Desktop, rename it to .zip file
Extract that .zip file and you will get directory with application name
Check that directory you will find app file in Payload folder, copy this app file
Go to ~/Library/Developer/CoreSimulator/Devices
FYI: Library folder is hidden by default in mac, you can see hidden file using below command.
defaults write com.apple.finder AppleShowAllFiles YES;
killall Finder /System/Library/CoreServices/Finder.app
Now here you'll see many directories with long hexadecimal names, these all are simulators.
To find your desired simulator, sort these directories using "Arranged By > Date Modified".
Select that simulator file and go to below location.
<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/
Create new folder name with <download-app-name> and paste app file in that folder
Open Terminal and run below command to install this application
xcrun simctl install booted <APP_FILE_PATH>
Example <APP_FILE_PATH> will be looks like below:
~/Library/Developer/CoreSimulator/Devices/<HEXADECIMAL-SIMULATOR-STRING>/data/Containers/Bundle/Application/<APP_NAME>
First of all, IPAs usually only have ARM slices because the App Store does not currently accept Simulator slices in uploads.
Secondly, as of Xcode 8.3 you can drag & drop a .app bundle into the Simulator window and it will be installed. You can find the app in your build products directory ~/Library/Developer/Xcode/DerivedData/projectname-xyzzyabcdefg/Build/Products/Debug-iphonesimulator if you want to save it or distribute it to other people.
To install from the command line use xcrun simctl install <device> <path>.
device can be the device UUID, its name, or booted which means the currently booted device.
For Xcode 10, here's an easy way that worked for me for a debug IPA (development profiles)
Unzip the IPA to get the Payload folder.
Within the Payload folder is the app executable.
Drag and drop the app to an open simulator. (You might see a green add button when you drag it over the simulator)
It should install that app on that simulator.
You can run the application file of project in simulator - not .ipa file.
You can get it from:
Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then u can see many files like 0CD04F.... find out your application file through open it.
You can copy the file to your system(which system simulator u need run ) location Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->
Then open the simulator 4.3 (its your simulator version where you pasted). You can see the application installed there.
Getting from other people:
Please tell them to find out Libraries-->Applicationsupport-->iphone simulator-->4.3(its ur simulator version)-->applications-->then you can see many files like 0CD04F.... from their system and receive that file from them.
After they have got the file, please copy and paste the file in to your system `Libraries-->Applicationsupport-->iphone simulator-->4.3(its your simulator version)-->applications-->(paste the file here).
Then you can see the app is installed in your system simulator and you can run it after clicking the file.
Copy From Here:
- Run the application in the Xcode.
- Select Finder go to Go and click on select Library Library/Application Support/iPhone Simulator/7.0.3-64/Applications
- Select 32 bit folder Copy your application.
Paste To Here:
- /Applications/Xcode-Beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhone Simulator. SDK/Applications
- Paste here and run the simulator.
With Xcode 6:
It's very possible to build and install on a simulator.
I did it by copying the debug build configuration (I called it SimRelease for my example below) in the project settings. I changed the architectures to i386 and x86_64 (not sure how necessary this was), but key difference to change between the copied build configuration is build for active architecture set to NO. After that a couple simple command line tools will do the rest!
xcodebuild -scheme YOUR_SCHEME -configuration SimRelease -sdk iphonesimulator8.1
Depending on where you have your DerivedData set you need to go find the outputted .app folder. Once you've found it you can simply install it on any simulator device. To find the device UUID's open Xcode and go to Window->Devices you'll see the list of the device instances and you can grab the UUID's. For a trivial script you could grab all of them from: ~/Library/Developer/CoreSimulator/Devices/ and install on every device.
From there the simple command to install on a device is:
xcrun simctl install DEVICE_ID APP_FOLDER_LOCATION
Here's a simple shell script to take the app and install it on every device:
app_dir=$1
current_dir=$(pwd)
cd ~/Library/Developer/CoreSimulator/Devices/
devices=$(ls -d */)
cd "$current_dir"
for device in $devices
do
device_id=${device%/}
xcrun simctl install "$device_id" "$app_dir"
done
Hope this helps! Took me a while to figure out the best way to do it.
Step to run in different simulator without any code repo :-
First create a .app by building your project(under project folder in Xcode) and paste it in a appropriate location (See pic for more clarity)
Download Xcode
Create a demo project and Start simulator in which you want to run the app.
Copy the .app file in particular location(ex :- Desktop).
cd Desktop and Run the command (xcrun simctl install booted appName.app),
App will be installed in the particular booted simulator.
Tested on iPod touch (7th generation) Simulator 13 (iOS 15.0)
Xcode and Xcode Command Line tools are already installed
Since we have an .ipa file, we can get the .app file from it
Rename .ipa file as .zip and extract the contents
Once the zip file is extracted, we can find the Payload folder which contains App_Name.app file
Open Terminal or iTerm2 app
Navigate to the folder which contains .app file
To list all iOS connected devices & iPhone simulators -> Also shows the UDID of all devices
xcrun xctrace list devices
Boot the simulator
xcrun simctl boot <UDID>
Launch the simulator
open -a simulator
Install the .app file
xcrun simctl install booted <App_Name>.app
Just drag and drop .app file to simulator it will install app automatically.
I have checked in iPhone simulator 13(iOS 15.4)