Sunday, February 24, 2013

Illegal instruction: 4

Some old arm v6 binaries that compiled using iPhone-gcc and old sdk have "Illegal instruction: 4" when using devices with A6/A6X CPU such as iPhone 5 / iPad 4 as discussed in http://code.google.com/p/iphone-gcc-full/issues/detail?id=6
The is how to patch these binaries without recompiling or when source code is not available

perl -pe 's/\x{00}\x{30}\x{93}\x{e4}/\x{00}\x{30}\x{93}\x{e5}/g;s/\x{00}\x{30}\x{d3}\x{e4}/\x{00}\x{30}\x{d3}\x{e5}/g;' < old_ios_binary > old_ios_binary_patched
chmod +x old_ios_binary_patched
ldid -s old_ios_binary_patched
mv old_ios_binary old_ios_binary_original
mv old_ios_binary_patched old_ios_binary


If you have gnu sed in iOS or OS X, you can patch directly without the temp file in one step
sed -i'' 's/\x00\x30\x93\xe4/\x00\x30\x93\xe5/g;s/\x00\x30\xd3\xe4/\x00\x30\xd3\xe5/g;' old_ios_binary
ldid -s old_ios_binary


iphone-gcc patched package for iPhone 5 / iPad 4 is here
http://code.google.com/p/apiexplorer/downloads/list

9 comments:

Anonymous said...

Thank you so much for this!!! I was wondering why NTPdate was croaking on my iPhone 5 but was fine on my iPhone 4 and iPad 3 ...

Anonymous said...

This works brilliantly. Many thanks !

Anonymous said...

Okay this looks FANTASTIC! But as a new developer, I am unsure where my ios_binary or the ios_binary_patched is!!!

Can somebody do me the great favor or posting the ACTUAL commands for me??

Litchkis Baggins said...

I have the patched binary... How to I determine my old binary?!

Can somebody do me the great blessing of giving me the steps to follow?

Thanks so much ahead of time, guys.

Safdar said...

Büyük posta. Paylaşım için teşekkürler.

Daniel Ferreira said...

I wrote a small blog post about why this works: http://theiostream.tumblr.com/post/63923259800/patching-iphone-gcc-binaries-to-armv7s

To the author: How did you come up with this?

javacom said...

Ask saurik

Anonymous Skynet said...

After completing those steps it says new error:

gcc: Internal error: Illegal instruction: 4 (program cc1)
Please submit a full bug report.
See for instructions.

What to do?

uname -a: root:xnu-2784.20.34~2/RELEASE_ARM64_T7001 iPad5,4 arm64 J82AP Darwin
uname -m: iPad5,4 (ipad air 2)
dpkg --print-architecture: iphoneos-arm

javacom said...

Because you have an older version of gcc and related libraries on a 64 bit device. please upgrade your gcc to clang in iOS.