The best of OpenSource.Apple.Com for iOS

02/05/2016, Jonathan Levin, http://NewOSXBook.com/ @Morpheus______

What is this?

You already know that Apple releases most components of Darwin (at least, the trivial ones) as open sources on OpenSource.Apple.com. What you may or may not know is that compiling them often runs into annoying challenges, which stem from all sorts of #ifdef blocks and private headers. Some of the private headers are simply portable from XNU's own (usually along with a #define PRIVATE or #define KERNEL_PRIVATE to unlock them for user mode use). Others are not as simple to figure out, containing references to constants that need to be reverse-engineered out of the compiled binary.

iOS users have long relied on Cydia packages to bring back that functionality. I also did, for the longest time, but ran into minor annoyances, namely:

I do a LOT of work on the i-Devices directly, thus decided to compile my own versions. Before certain crazy attention-seeking libel-spreading (but nonethless highly talented) individuals accuse me of any piracy (false claims, but you never know), I'll state that what I'm doing is within the realms of the Apple Public Source License. In fact, I went to great lengths to maintain the source information. This will be evident in the LC_SOURCE_VERSION, and the little known but rather useful what(1) command (also included):

morpheus@Zephyr(~)$ jtool -arch arm64 -l ~/iOSBinaries/usr/bin/what | grep SOURCE_
LC 10: LC_SOURCE_VERSION     	Source Version:          187.0.0.0.0
morpheus@Zephyr(~)$ what ~/iOSBinaries/usr/bin/what
/Users/morpheus/iOSBinaries/usr/bin/what
	 Copyright (c) 1980, 1988, 1993 The Regents of the University of California.  All rights reserved.
	 PROGRAM: what	PROJECT:shell_cmds-187
	 Compiled by Jonathan Levin, http://NewOSXBook.com/
	 Copyright (c) 1980, 1988, 1993 The Regents of the University of California.  All rights reserved.
	 PROGRAM: what	PROJECT:shell_cmds-187
	 Compiled by Jonathan Levin, http://NewOSXBook.com/
	 PROGRAM: what	PROJECT:shell_cmds-187
	 Compiled by Jonathan Levin, http://NewOSXBook.com/
	 Copyright (c) 1980, 1988, 1993 The Regents of the University of California.  All rights reserved.

Now, why is that output shown three times? Because all commands I'm supplying here are multi-architecture fat binaries - x86_64, arm64, and arm32. That way you can plop them into any device (arguably, the x86_64 version is redundant..). If you need the disk space, simply use jtool -arch ... -e arch (or lipo -thin) to extract the architecture slice you need.

All binaries are also self signed (jtool --sign) for iOS, and with appropriate entitlements, if necessary. The OS X versions are not signed, because SIP on 10.11 will actually kill (invalid) self-signed binaries. And for the most part, you can use the default OS X binaries - at least in theory my binaries should be largely (up to addressing) identical.

List of binaries:

TL;DR

Full list

drwxr-xr-x  0 morpheus staff       0 Feb  1 14:22 bin/
-rwxr-xr-x  0 root     staff  169396 Feb  1 14:22 bin/chmod
-rwxr-xr-x  0 root     staff  151437 Jan 31 16:26 bin/cp
-rwxr-xr-x  0 root     staff  168377 Jan 31 16:24 bin/dd
-rwxr-xr-x  0 root     staff  150432 Jan 31 16:33 bin/df
-rwxr-xr-x  0 root     staff  132639 Jan 25 18:52 bin/kill
-rwxr-xr-x  0 root     staff  204081 Feb  1 14:16 bin/ls
-rwxr-xr-x  0 root     staff  150749 Jan 31 16:30 bin/mv
-rwxr-xr-x  0 root     staff  222326 Jan 31 15:19 bin/ps
-rwxr-xr-x  0 root     staff  151085 Feb  1 12:04 bin/rm
-rwxr-xr-x  0 morpheus staff 1922892 Jan 31 15:32 bin/zsh 
drwxr-xr-x  0 morpheus staff       0 Jan 31 16:01 etc/
-r--r--r--  0 morpheus staff    2992 Jan 31 15:33 etc/zshrc
# The essentials. And, yes, kextunload works :-)
drwxr-xr-x  0 root     staff       0 Feb  1 19:57 sbin/
-rwxr-xr-x  0 root     staff  132224 Jan 25 15:24 sbin/dmesg
-rwxr-xr-x  0 root     staff  307515 Feb  1 17:44 sbin/ifconfig
-rwxr-xr-x  0 root     staff  190189 Feb  1 13:55 sbin/kextunload
-rwxr-xr-x  0 root     admin  151710 Feb  1 13:22 sbin/md5
-rwxr-xr-x  0 root     staff  219315 Feb  1 17:54 sbin/ping
...
# VIM support files. No emacs for you.
...
-rw-r--r--  0 root     wheel    4679 Aug 31  2009 usr/share/vim/vim73/autoload/xml/xsl.vim
# sbin binaries
-rwxr-xr-x  0 root     staff  149872 Jan 31 16:36 usr/sbin/chown
-rwxr-xr-x  0 root     staff  221492 Feb  1 20:07 usr/sbin/ioreg
-rwxr-xr-x  0 root     staff  206752 Feb  1 12:35 usr/sbin/kextstat
-rwxr-xr-x  0 root     staff  150063 Jan 15 11:15 usr/sbin/ltop
-rwxr-xr-x  0 root     staff  422954 Feb  1 19:55 usr/sbin/netstat
-rwxr-xr-x  0 root     staff  152020 Feb  2 11:10 usr/sbin/nvram
-rwxr-xr-x  0 root     staff  150641 Jan 25 15:02 usr/sbin/sysctl
drwxr-xr-x  0 root     staff       0 Feb  1 15:56 usr/local/bin/
drwxr-xr-x  0 morpheus staff       0 Jan 31 15:31 usr/local/lib/
drwxr-xr-x  0 morpheus staff       0 Jan 31 15:31 usr/local/lib/zsh/
# ... zsh support files
...
# Excellent SSH clone, MUCH better than compiling OpenSSL (pure torture)
-rwxr-xr-x  0 root     staff  659565 Feb  1 15:44 usr/local/bin/dbclient
-rwxr-xr-x  0 root     staff  690749 Feb  1 15:51 usr/local/bin/dropbear
-rwxr-xr-x  0 root     staff  462404 Feb  1 15:55 usr/local/bin/dropbearconvert
-rwxr-xr-x  0 root     staff  445360 Feb  1 15:52 usr/local/bin/dropbearkey
# usr/bin
-rwxr-xr-x  0 root     staff  152643 Jan 25 11:29 usr/bin/arch
-rwxr-xr-x  0 root     staff  148978 Feb  1 11:59 usr/bin/chflags
-rwxr-xr-x  0 root     admin  150734 Feb  1 12:16 usr/bin/cut
-rwxr-xr-x  1 root     staff  150880 Feb  6 18:17 usr/bin/du
-rwxr-xr-x  0 root     staff  256599 Jan 31 16:12 usr/bin/find
-rwxr-xr-x  0 root     admin  149052 Feb  1 12:11 usr/bin/head
-rwxr-xr-x  0 root     staff  185270 Jan 31 16:16 usr/bin/hexdump
-rwxr-xr-x  0 root     staff  132515 Jan 25 11:24 usr/bin/hostinfo
-rwxr-xr-x  0 morpheus staff  675177 Jan 19 06:08 usr/bin/less
-rwxr-xr-x  0 root     staff  153316 Jan 17 17:11 usr/bin/login
-rwxr-xr-x  0 root     staff  201940 Jan 15 11:28 usr/bin/lsmp  
-rwxr-xr-x  0 morpheus staff  675177 Jan 19 06:08 usr/bin/more
-rwxr-xr-x  0 root     staff  132560 Feb  4 19:39 usr/bin/nohup
-rwxr-xr-x  0 root     staff  149649 Jan 25 18:46 usr/bin/printf
-rwxr-xr-x  0 root     staff  204359 Jan 31 15:22 usr/bin/sc_usage
-rwxr-xr-x  0 root     wheel 1213063 Jan 17 17:07 usr/bin/screen
-rwxr-xr-x  0 root     staff  150913 Jan 17 17:09 usr/bin/script
-rwxr-xr-x  0 root     admin  219970 Feb  1 12:19 usr/bin/sed
-rwxr-xr-x  0 root     admin  166512 Feb  1 12:22 usr/bin/split
-rwxr-xr-x  0 root     staff  514543 Jan 17 16:56 usr/bin/syslog
-rwxr-xr-x  0 root     admin  151549 Feb  1 12:09 usr/bin/tail
-rwxr-xr-x  0 root     staff  132384 Feb  4 19:35 usr/bin/tee
-rwxr-xr-x  0 root     staff  132400 Jan 25 18:56 usr/bin/uname
-rwxr-xr-x  0 root     staff 6162256 Feb  2 10:52 usr/bin/vim
-rwxr-xr-x  0 root     staff  149746 Jan 31 17:17 usr/bin/vm_stat
-rwxr-xr-x  0 root     admin  149533 Feb  1 12:17 usr/bin/wc
-rwxr-xr-x  0 root     staff  132096 Feb  5 13:42 usr/bin/what
-rwxr-xr-x  0 root     staff  132800 Jan 17 17:08 usr/bin/which
-rwxr-xr-x  0 root     staff  150944 Feb  4 19:31 usr/bin/xargs
-rwxr-xr-x  1 root     staff  149664 Feb  6 15:21 usr/bin/xxd

morpheus@Zephyr(~)$ md5 iosbinpack.tgz 
MD5(iosbinpack.tgz)= bb80d61b8fba9f7550e2243d272a4863
morpheus@Zephyr(~)$ openssl sha1 !$ 
openssl sha1 iosbinpack.tgz 
SHA1(iosbinpack.tgz)= bb3ee7d871c39f3e7dbeced9beb43ab89ad5e98e

Download

The full tgz pack. You can always open and remove stuff you don't want
The 64-bit tgz pack. Also with login fix for 9.2 +

Install

SCP to your iOS device, go to root directory (cd /), and tar -k xvf. BE CAREFUL NOT TO OVERRIDE ANY EXISTING BINARIES.

Q&A

Changelog

Hashes:
[root@Qilin tools]# md5sum iosbin*
a03904fb94e405bdde44617c7c85a017  iosbinback.tgz
5cf75e99d7e4636f99de437f738f3346  iosbinpack64.tgz
5edceb29d239f8bd48b6c5b34dc4e67e  iosbinpack.tgz
[root@Qilin tools]# openssl sha1 iosbin*
SHA1(iosbinback.tgz)= fa666479c14fd7f5c1b1cd86b09bfbd289f2ec68
SHA1(iosbinpack64.tgz)= 9c9bd6fe046a73635bf3a601ae1facd85d95c787
SHA1(iosbinpack.tgz)= 08a2abd834a1ed2e74c1e8ccde17a0868fb40d90