The Blog!

C/C++: Compiling on iOS

C language is great because it’s one of the most used today and has compilers widely available for most architectures. The propose of this post is to explain how to compile your own C/C++ projects under the new iOS versions like 3, 4 and 5.x.

Nowadays, compiling C/C++ for iPhone, isn’t to easy like before, there are three major problems:

- No LibGCC available on Cydia. The famous GCC Compiler has been ported to the iPhone (you can found it as GNU C Compiler on Cydia). GCC depends on LibGCC  witch is no longer available on Cydia (since iOS 2.0) so it’s impossible to install CGG.

- The C Standard Library is not completely installed on iOS.

- Apple Code Sign. Saurik (Cydia developer) has already explain that…

“Starting with the recent beta releases of the iPhoneOS, Apple has started requiring that all code on the device is signed. This is mostly to make it impossible for programs running through Apple’s AppStore to download more software and run it (so no competition for AppStore).”

Fortunately right now an compatible with iOS 5 there’s an open source project that aims to port GCC and it’s dependencies to the iPhone. The project is called iPhone-GCC-Full.

To start you’ll need to get some components:

  • CSU – Go to Cydia and search and install csu.
  • Link Identify Editor (aka ldid) – Go to Cydia and search and install ldid.
  • LibGCC: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=libgcc.deb
  • GCC: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=iphone-gcc.deb
  • Headers/Libraries: http://code.google.com/p/iphone-gcc-full/downloads/detail?name=headers-libs.deb

After downloading those components, launch Cyberduck or your favorite SFTP software and upload the files into /private/var/root on your iPhone.

Now, connect to your iPhone via SSH using Terminal in your Mac and install the downloaded packages:

your-mac:~ you$  ssh root@your-iphone.local

root@your-iphone.local’s password: : …   // The default password is “alpine”

your-iphone:~ you$ dpkg -install libgcc.deb

your-iphone:~ you$  dpkg -install iphone-gcc.deb

your-iphone:~ you$  dpkg -install headers-libs.deb

Now you can compile your applications like you do in your computer, by issuing for e.g. “cpp -o helloworld helloworld.c”.

After compiling if you try to run your app iPhone just says “Killed” when you launch it! This is Code Sign working… In order to solve this issue it’s necessary to sign the application. There are 3 options to sign apps or make it run but, the best option is called Pseudo-Signing:

“To get around this, I wrote a tool called ldid that, among other things, can generate the SHA1 hashes that are checked by Apple’s iPhoneOS kernel” - (The other signing options are here: http://www.saurik.com/id/8)

Issue the following on your iPhone Terminal:

your-iphone:~ you$ ldid -S helloworld

Now if you try to run your app it will work!! Enjoy the freedom of having your small or huge utilities running in your pocket anytime you need them! Don’t forget to install MobileTerminal to run your Apps.

Hope this guide was helpful!

Tip: Disable Google Software Update!

As you might noticed, Google software releases for OS X now include Google Software Update, a background daemon called “Keystone” that checks for/installs updates to Google software with no user intervention and no option to disable it.

Yes… You read it, ” with no user intervention and no option for disabling it”. This is… evil and will waste your bandwidth so you should have an option to disable it.

At Google’s FAQ pages, they say that there’s an option to manage this:

How will I know when there are updates or new programs available?

Google Updater keeps track of the programs you have installed and can alert you when new versions become available. By default, updates are installed automatically. If you don’t want to be notified when updates are available, follow these steps:

From the Finder, choose Go > Applications..
Double-click the Google Updater icon.
Choose Google Updater > Preferences.
Uncheck the box labeled “Notify me when updates are installed”.
Click “Done”.

But seems like now there isn’t a “Google Updater icon” at all. So in this post, will be showing you a possible solution to disable the annoying Google Keystone…

In a first try, I thought I could completely remove the Google Software Update, but… When I did it, google products began to preset some error messages, telling me that there were some missing components and they all just stop working! Well seems like google is doing it’s job.

In a second approach, I thought a different thing. I’ve noticed that Google Keystone has an launchd an it starts with the computer.

So, the following steps, on terminal, will disable Google’s Keystone from booting with the computer and automatically check for updates!

First step, remove all the Keystone info stored in the computer:

sudo rm /Library/LaunchAgents/com.google.keystone.agent.plist
sudo rm /Library/LaunchDaemons/com.google.keystone.daemon.plist
sudo rm /Library/LaunchDaemons/com.google.keystone.daemon4.plist

Second step! Create some new info files, to ensure that Keystone will still work after this when you need it:

sudo touch /Library/LaunchAgents/com.google.keystone.agent.plist
sudo touch /Library/LaunchDaemons/com.google.keystone.daemon.plist
sudo touch /Library/LaunchDaemons/com.google.keystone.daemon4.plist

Last step, give 000 permissions to the files! With means that nobody can write on the files, including Keystone:

sudo chmod 000 /Library/LaunchAgents/com.google.keystone.agent.plist
sudo chmod 000 /Library/LaunchDaemons/com.google.keystone.daemon.plist
sudo chmod 000 /Library/LaunchDaemons/com.google.keystone.daemon4.plist

Creating inaccessible dummy files is important. Without them, the launchd entries can simply be replaced whenever Google Software run. But with these steps taken, no Google App can reinstall the Keystrone launchd entry, unless they:

  • ask for your username and password (to authenticate as root)
  • use different filenames
  • create local launchd entries (~/Library/Launch[…])

Have fun without Google Software Update!

I almost forgot… If someday you need to update google software, just open this cmd file:

~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/CheckForUpdatesNow.command

After running it, Keystone will check and download available updates.

Tech Preview: STKeys for iOS

It’s been a long time since the first announcement of STKeys for the iOS platform but today, I bring you a technology preview about what to expect in the next generation of the famous STKeys!

STKeys Update: 4.1!

STKeys the popular Thomson key recovery App for Mac has been updated!

This update issue the following new features/bug fixes: (4.1 – localized)

  • Experimental Portuguese localization
  • Support for the new 2012 thomson routers

Update your STKeys now, to get the latest features.

If you don’t already have STKeys, check it out here: STKeys 4