Skip to content

Commit

Permalink
strip MH_DYLIB_IN_CACHE, disable header growth
Browse files Browse the repository at this point in the history
thank you to @cgudrian for catching the MH_DYLIB_IN_CACHE flag issue, lldb should finally work now!

also disable something which was causing a regression for the past couple versions
  • Loading branch information
ASentientBot committed Sep 6, 2023
1 parent e310907 commit 57415de
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 32 deletions.
22 changes: 13 additions & 9 deletions Output.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
#define IMPOSTOR_OBJC_OLD "dsce.objc.old"
#define IMPOSTOR_GOT "dsce.got"
#define IMPOSTOR_PAD "dsce.pad"
#define HEADER_EXTRA 0x1000
#define IMPORT_HACK_OFFSET 0x1000000000

// TODO: broken currently

#define HEADER_EXTRA 0 // 0x1000

// https://en.wikipedia.org/wiki/LEB128

NSData* ulebWithLong(long value)
Expand Down Expand Up @@ -127,6 +130,7 @@ -(void)stepImportHeader
self.header=ImageHeader.alloc.initEmpty.autorelease;

self.header.header->flags=self.cacheImage.header.header->flags;
self.header.header->flags&=~MH_DYLIB_IN_CACHE;

__block int copied=0;
__block int skipped=0;
Expand Down Expand Up @@ -903,7 +907,7 @@ -(void)stepFixSelRefs
long* refs=(long*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(long);

trace(@"fixing %x selector refs",count);
trace(@"fix %x selector refs",count);

for(int index=0;index<count;index++)
{
Expand Down Expand Up @@ -943,7 +947,7 @@ -(void)stepFixClasses
long* classes=(long*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(long);

trace(@"fixing %x classes",count);
trace(@"fix %x classes",count);

for(int index=0;index<count;index++)
{
Expand Down Expand Up @@ -973,7 +977,7 @@ -(void)stepFixCats
long* cats=(long*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(long);

trace(@"fixing %x categories",count);
trace(@"fix %x categories",count);

for(int index=0;index<count;index++)
{
Expand All @@ -998,7 +1002,7 @@ -(void)stepFixProtoRefs
long* refs=(long*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(long);

trace(@"fixing %x protocol refs",count);
trace(@"fix %x protocol refs",count);

for(int index=0;index<count;index++)
{
Expand All @@ -1020,7 +1024,7 @@ -(void)stepFixProtos
long* refs=(long*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(long);

trace(@"fixing %x protocols",count);
trace(@"fix %x protocols",count);

for(int index=0;index<count;index++)
{
Expand Down Expand Up @@ -1137,7 +1141,7 @@ -(void)fixMethodListWithAddress:(long)address

-(void)stepFixPointersNew
{
trace(@"scanning %lx rebases",self.fixups.count);
trace(@"scan %lx rebases",self.fixups.count);

long internalCount=0;
long cppCount=0;
Expand Down Expand Up @@ -1259,7 +1263,7 @@ -(void)stepFixInitOffsets
int* offsets=(int*)wrapOffset(self,section->offset).pointer;
int count=section->size/sizeof(int);

trace(@"fixing %x initializer offsets",count);
trace(@"fix %x initializer offsets (delta %lx)",count,self.baseAddressDelta);

for(int index=0;index<count;index++)
{
Expand All @@ -1286,7 +1290,7 @@ -(void)stepSyncHeader
{
// TODO: ensure we don't overrun TEXT

trace(@"syncing modified header (%lx bytes)",self.header.data.length);
trace(@"sync modified header (%lx bytes)",self.header.data.length);

memcpy(self.data.mutableBytes,self.header.data.mutableBytes,self.header.data.length);
}
Expand Down
12 changes: 8 additions & 4 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ Incomplete macOS 12+ dyld cache extractor. Used by [OCLP](https://github.com/dor
- [Hopper Disassembler](https://www.hopperapp.com): Mach-O inspection, Objective-C struct definitions
- [Mach-O Explorer](https://github.com/DeVaukz/MachO-Explorer), [MachOView](https://github.com/mythkiven/MachOView): Mach-O inspection
- [Wikipedia](https://wikipedia.org): [LEB128](https://en.wikipedia.org/wiki/LEB128)
- [Moraea](https://github.com/moraea): guidance, testing, encouragement
- [Moraea](https://github.com/moraea): code, guidance, testing
- [cgudrian](https://github.com/cgudrian): lldb [fix](https://github.com/dortania/PatcherSupportPkg/commit/b95da2eb01cb1f92e9f900c6458f9dee14771ad5#commitcomment-126541027)

## status

- [x] copy header and load commands
- [x] allocate space for additional commands
- [ ] allocate space for additional commands (temporarily disabled)
- [x] copy segments/sections, fixing offsets and alignment
- [x] optionally pad to keep addresses contiguous (produces 2+ GB images)
- [x] generate rebase opcodes
Expand All @@ -40,18 +41,21 @@ Incomplete macOS 12+ dyld cache extractor. Used by [OCLP](https://github.com/dor
- [x] satisfy `install_name_tool -id test`
- [x] satisfy `codesign -fs -`
- [ ] satisfy `dyld_info -objc`
- [x] satisfy Stubber (`nm`, Objective-C runtime, linker)
- [ ] satisfy `lldb` (unlikely outside `pad` mode...)
- [x] satisfy Stubber 2 (`nm`, Objective-C runtime, linker)
- [x] satisfy `lldb`
- [ ] produce working images
- [x] 12.0 DP6 - GeForceAIRPlugin, GeForceMTLDriver
- [ ] 12.0 DP6 - GeForceGLDriver
- [x] 12.6 - AppKit, QuartzCore, CoreGraphics, Carbon, RenderBox, VectorKit, Metal, MetalPerformanceShaders, MTLCompiler, GPUCompiler, AppleGVA, AppleGVACore
- [x] 12.6 - AMDMTLBronzeDriver, AMDShared, AMDRadeonVADriver, AMDRadeonVADriver2
- [x] 13.2.1 - AppKit, QuartzCore, CoreGraphics, Carbon, RenderBox, VectorKit, Metal, MetalPerformanceShaders, MTLCompiler, GPUCompiler
- [ ] 13.2.1 - libSystem, Foundation, Combine, ContactsFoundation, FamilyCircle...
- [x] 14.0 DP6 - AppleIntelKBLGraphicsMTLDriver
- [ ] 14.0 DP6 - AppKit, QuartzCore, Metal...
- [ ] support Big Sur
- [x] support Monterey
- [x] support Ventura
- [ ] support Sonoma
- [ ] support arm64 (unlikely...)
- [ ] use sane amounts of RAM and CPU (getting closer...)
- [ ] write automated tests to detect regressions
22 changes: 3 additions & 19 deletions Run.tool
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=6
VERSION=7

set -e

Expand All @@ -8,23 +8,7 @@ clang++ -fmodules -fcxx-modules -std=c++17 -Wno-unused-getter-return-value -mmac

rm -rf Out

./dsce

# ./dsce /System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64 list

# ./dsce /System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64 search __init_offsets

# ./dsce /System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64 /System/Library/Frameworks/AppKit.framework /System/Library/Frameworks/QuartzCore.framework /System/Library/Frameworks/CoreGraphics.framework /System/Library/Frameworks/Carbon.framework /System/Library/PrivateFrameworks/RenderBox.framework /System/Library/PrivateFrameworks/VectorKit.framework /System/Library/Frameworks/Metal.framework /System/Library/Frameworks/MetalPerformanceShaders.framework /System/Library/PrivateFrameworks/MTLCompiler.framework /System/Library/PrivateFrameworks/GPUCompiler.framework

# ./dsce /System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64 pad /System/Library/Frameworks/AppKit.framework /System/Library/Frameworks/QuartzCore.framework /System/Library/Frameworks/CoreGraphics.framework /System/Library/Frameworks/Carbon.framework /System/Library/PrivateFrameworks/RenderBox.framework /System/Library/PrivateFrameworks/VectorKit.framework /System/Library/Frameworks/Metal.framework /System/Library/Frameworks/MetalPerformanceShaders.framework /System/Library/PrivateFrameworks/MTLCompiler.framework /System/Library/PrivateFrameworks/GPUCompiler.framework
./dsce /System/Cryptexes/OS/System/Library/dyld/dyld_shared_cache_x86_64h /System/Library/Frameworks/AppKit.framework /System/Library/Frameworks/QuartzCore.framework /System/Library/Frameworks/CoreGraphics.framework /System/Library/Frameworks/Carbon.framework /System/Library/PrivateFrameworks/RenderBox.framework /System/Library/PrivateFrameworks/VectorKit.framework /System/Library/Frameworks/Metal.framework /System/Library/Frameworks/MetalPerformanceShaders.framework /System/Library/PrivateFrameworks/MTLCompiler.framework /System/Library/PrivateFrameworks/GPUCompiler.framework

find -d Out -type f -exec codesign -f -s - {} \;
chmod -R 755 Out

# DYLD_FRAMEWORK_PATH="$PWD/Out/System/Library/Frameworks:$PWD/Out/System/Library/PrivateFrameworks" /System/Applications/TextEdit.app/Contents/MacOS/TextEdit

# lldb -n TextEdit

# mount -uw /
# cp -R Out/ /
# reboot
chmod -R 755 Out

0 comments on commit 57415de

Please sign in to comment.