Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions dyld/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Language: Cpp
BasedOnStyle: WebKit

AlignConsecutiveDeclarations: true
AlignOperands: false
AlignTrailingComments: true
IndentWidth: 4

Standard: Cpp11

UseTab: Never

SortIncludes: false
8 changes: 8 additions & 0 deletions dyld/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
build
dyld.xcodeproj/kledzik.mode1v3
dyld.xcodeproj/kledzik.pbxuser
dyld.xcodeproj/project.xcworkspace/
dyld.xcodeproj/xcuserdata/
.DS_Store
.pyc

367 changes: 367 additions & 0 deletions dyld/APPLE_LICENSE

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions dyld/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CXXFLAGS = -Wall
CXX = clang++

.PHONY: all clean

all: dsc_extractor

dsc_extractor: dsc_extractor.o dsc_iterator.o
$(CXX) -o $@ $^

clean:
-rm -f dsc_extractor dsc_extractor.o dsc_iterator.o
-rm -f *~
27 changes: 27 additions & 0 deletions dyld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Dynamic Shared Cache Extractor

Apple dyld (*dynamic link editor*) loads and links the shared/dynamic libraries (`.dylib` files in Apple OSes: macOS, iOS).
It is provided as open source software by Apple; you can [browse it](https://opensource.apple.com/source/dyld/) or you can download [dyld tarballs](https://opensource.apple.com/tarballs/dyld/).
There is an [unofficial repository](https://github.com/opensource-apple/dyld) that's currently (December 2017) not updated to the latest dyld provided by Apple (`519.2.1`).

As told by [the iPhoneDevWiki](http://iphonedevwiki.net/index.php/Dyld_shared_cache) "all system (private and public) libraries have been combined into a big cache file to improve performance".
This file is named `dyld_shared_cache_...` with a suffix denoting the architecture.
Extraction of libraries from the dyld shared cache is not trivial since certain symbols are updated ("redacted").

Based on [ant4g0nist's blog post](http://ant4g0nist.blogspot.ro/2015/04/ios-shared-cache-extraction-to-solve.html), we downloaded the latest [dyld tarball](https://opensource.apple.com/tarballs/dyld/) (`dyld-519.2.1.tar.gz`), copied the contents of the `launch-cache/` subfolder in the repository and added a `Makefile` to build `dsc_extractor` (*dyld shared cache extractor*).
`dsc_extractor` is used to extract the library files from the dyld shared cache.
In the `dsc_extractor.cpp` source code file we enabled the `main` function to allow the building of the `dsc_exctractor` executable.

Building and running `dsc_extractor` requires macOS.
To build the `dsc_extractor` executable run `make`:

```
make
```

To run `dsc_extractor` pass it two arguments: the path to the dyld shared cache file and the output folder that will store the extracted library files.
The command below extracts the shared library files for an iOS 9 dyld shared cache in the current directory:

```
./dsc_extractor /mnt/ios/iPhone5,1_9.3_13E237/System/Library/Caches/com.apple.dyld/dyld_shared_cache_armv7s .
```
66 changes: 66 additions & 0 deletions dyld/bin/expand.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/perl

use strict;


my $sdk = $ENV{"SDKROOT"};
my $availCmd = $sdk . "/usr/local/libexec/availability.pl";

sub expandVersions
{
my $macroPrefix = shift;
my $availArg = shift;

my $cmd = $availCmd . " " . $availArg;
my $versionList = `$cmd`;
my $tmp = $versionList;
while ($tmp =~ m/^\s*([\S]+)(.*)$/) {
my $vers = $1;
$tmp = $2;

my $major = 0;
my $minor = 0;
my $revision = 0;
my $uvers;

if ($vers =~ m/^(\d+)$/) {
$major = $1;
$uvers = sprintf("%d_0", $major);
} elsif ($vers =~ m/^(\d+).(\d+)$/) {
$major = $1;
$minor = $2;
$uvers = sprintf("%d_%d", $major, $minor);
} elsif ($vers =~ m/^(\d+).(\d+).(\d+)$/) {
$major = $1;
$minor = $2;
$revision = $3;
if ($revision == 0) {
$uvers = sprintf("%d_%d", $major, $minor);
}
else {
$uvers = sprintf("%d_%d_%d", $major, $minor, $revision);
}
}
printf "#define %s%-18s 0x00%02X%02X%02X\n", $macroPrefix, $uvers, $major, $minor, $revision;
}
}




while(<STDIN>)
{
if(m/^\/\/\@MAC_VERSION_DEFS\@$/) {
expandVersions("DYLD_MACOSX_VERSION_", "--macosx");
}
elsif(m/^\/\/\@IOS_VERSION_DEFS\@$/) {
expandVersions("DYLD_IOS_VERSION_", "--ios");
}
elsif(m/^\/\/\@WATCHOS_VERSION_DEFS\@$/) {
expandVersions("DYLD_WATCHOS_VERSION_", "--watchos");
}
else {
print $_;
}
}

30 changes: 30 additions & 0 deletions dyld/bin/set-alt-dyld
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/perl -w

use strict;
undef $/;

if(@ARGV == 0)
{
print "Usage: $0 <macho-executable> [<macho-executable> ...]\n";
exit 1;
}

my $arg;
foreach $arg (@ARGV)
{
open IN, "<$arg" or die $!;
my $in = <IN>;
close IN or die $!;

if($in =~ s{/usr/lib/dyld}{/usr/local/dy})
{
open OUT, ">$arg" or die $!;
print OUT $in;
close OUT or die $!;
}
else
{
print STDERR "ERROR: $arg\n";
exit 1;
}
}
Empty file added dyld/configs/base.xcconfig
Empty file.
2 changes: 2 additions & 0 deletions dyld/configs/closured.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

CODE_SIGN_ENTITLEMENTS[sdk=embedded*] = dyld3/closured/closured_entitlements.plist
21 changes: 21 additions & 0 deletions dyld/configs/dyld.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ALIGNMENT[arch=armv7s] = -Wl,-segalign,0x4000

ENTRY[sdk=*simulator*] = -Wl,-e,_start_sim
ENTRY[sdk=iphoneos*] = -Wl,-e,__dyld_start
ENTRY[sdk=macosx*] = -Wl,-e,__dyld_start

EXPORTED_SYMBOLS_FILE[sdk=*simulator*] = $(SRCROOT)/src/dyld_sim.exp
EXPORTED_SYMBOLS_FILE[sdk=iphoneos*] = $(SRCROOT)/src/dyld.exp
EXPORTED_SYMBOLS_FILE[sdk=macosx*] = $(SRCROOT)/src/dyld.exp

PRODUCT_NAME[sdk=*simulator*] = dyld_sim
PRODUCT_NAME[sdk=iphoneos*] = dyld
PRODUCT_NAME[sdk=macosx*] = dyld

INSTALL_PATH = /usr/lib

//:configuration = Debug
GCC_PREPROCESSOR_DEFINITIONS = DYLD_IN_PROCESS=1 DYLD_VERSION=$(RC_ProjectSourceVersion) BUILDING_DYLD=1 DEBUG=1

//:configuration = Release
GCC_PREPROCESSOR_DEFINITIONS = DYLD_IN_PROCESS=1 DYLD_VERSION=$(RC_ProjectSourceVersion) BUILDING_DYLD=1
14 changes: 14 additions & 0 deletions dyld/configs/libdyld.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

LIBSYSTEM_LIBS[sdk=*simulator*] = -Wl,-upward-lsystem_sim_platform -Wl,-upward-lsystem_malloc -Wl,-upward-lsystem_c -Wl,-upward-lsystem_sim_pthread -Wl,-upward-lxpc -Wl,-upward-lsystem_blocks -Wl,-upward-lsystem_sim_kernel -Wl,-upward-lsystem_sandbox -Wl,-upward-ldispatch -Wl,-upward-lcommonCrypto -Wl,-upward-lclosured
LIBSYSTEM_LIBS[sdk=embedded*] = -Wl,-upward-lsystem_platform -Wl,-upward-lsystem_malloc -Wl,-upward-lsystem_c -Wl,-upward-lsystem_pthread -Wl,-upward-lxpc -Wl,-upward-lsystem_blocks -Wl,-upward-lsystem_kernel -Wl,-upward-lsystem_sandbox -Wl,-upward-ldispatch -Wl,-upward-lcommonCrypto -Wl,-upward-lclosured -Wl,-upward-lcompiler_rt
LIBSYSTEM_LIBS[sdk=macosx*] = -Wl,-upward-lsystem_platform -Wl,-upward-lsystem_malloc -Wl,-upward-lsystem_c -Wl,-upward-lsystem_pthread -Wl,-upward-lxpc -Wl,-upward-lsystem_blocks -Wl,-upward-lsystem_kernel -Wl,-upward-lsystem_sandbox -Wl,-upward-ldispatch -Wl,-upward-lcommonCrypto -Wl,-upward-lclosured

INSTALL_PATH = /usr/lib/system


//:configuration = Debug
GCC_PREPROCESSOR_DEFINITIONS = DYLD_IN_PROCESS=1 BUILDING_LIBDYLD=1 DEBUG=1

//:configuration = Release
GCC_PREPROCESSOR_DEFINITIONS = DYLD_IN_PROCESS=1 BUILDING_LIBDYLD=1

4 changes: 4 additions & 0 deletions dyld/configs/update_dyld_shared_cache.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@


CODE_SIGN_ENTITLEMENTS = dyld3/shared-cache/update_dyld_shared_cache_entitlements.plist

3 changes: 3 additions & 0 deletions dyld/configs/update_dyld_sim_shared_cache.xcconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

#include "<DEVELOPER_DIR>/AppleInternal/XcodeConfig/PlatformSupportHost.xcconfig"

Loading