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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Resources/libsystem_kernel.dylib
Binary file not shown.
Binary file added Resources/libsystem_platform.dylib
Binary file not shown.
Binary file added Resources/libsystem_pthread.dylib
Binary file not shown.
49 changes: 49 additions & 0 deletions Source/CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,40 @@ - (BOOL)loadFile:(CDFile *)file error:(NSError **)error depth:(int)depth {
if ([path hasPrefix:loaderPathPrefix]) {
NSString *loaderPath = [machOFile.filename stringByDeletingLastPathComponent];
path = [[path stringByReplacingOccurrencesOfString:loaderPathPrefix withString:loaderPath] stringByStandardizingPath];

} else {

// First of all, God bless me for fixing this stupid issue and hopefully, the owner of this repo will fix the problem fundamentally 🚀 🎉
// Fixing issue#39 : https://github.com/preemptive/PPiOS-Rename/issues/39 🪲
// Why do we need to do these f...g workaround? 🦧
// because It's so common for Apple to ruin our life 😩
// Many things have been changed on the DYLIB files in the new releases so we need to use the old files 🤷🏻‍♂️
// Thanks to the @BillBai that who motivated me to debug this issue with the following response🫡:

/*
This is because the iOS SDK's frameworks binaries from newer version of Xcode are using chained fixups and export trie Mach-O load commands to encode bind/rebase and symbol info. Not the dyld info in the older version. And the ppios-rename does not support these load commands yet.

A quick fix is just download the older version of Xcode (https://xcodereleases.com) ,and use the older version sdk by passing the "--sdk-root" argument.

*/


// I've added old files to a bundle and read them for this particular DYLIB file. 🥳
// We received the error "Unknown load command: 0x80000033" because of these 3 dylibs files even though we passed the old Xcode path as --sdk-root params in our command.
//You might need to add more dylibs files depending on your project requirements. ( You still need to pass the iPhoneOS.sdk path from the old Xcode (e.g 11-12)

if ([path containsString:@"/usr/lib/system/libsystem_kernel.dylib"]) {
path = [self getFilePathForPPiOSBundle:@"libsystem_kernel.dylib"];
} else if ([path isEqualToString:@"/usr/lib/system/libsystem_platform.dylib"]) {
path = [self getFilePathForPPiOSBundle:@"libsystem_platform.dylib"];
} else if ([path isEqualToString:@"/usr/lib/system/libsystem_pthread.dylib"]) {
path = [self getFilePathForPPiOSBundle:@"libsystem_pthread.dylib"];
}
}

// My $1 tip to you guys: you can find what libraries causing "Unknown load command: 0x80000033" by uncommenting the next line and find it in the terminal windows

// NSLog(@"MoLowKey-Debug : %@ \n",path);
[self machOFileWithName:path andDepth:depth+1]; // Loads as a side effect
}
[self.searchPathState popSearchPaths];
Expand Down Expand Up @@ -486,5 +519,21 @@ - (int)alterPrefixPCHFilesIn:(NSString *)prefixPCHDirectory
return 0;
}

#pragma mark - dylibsHelper

-(NSString*)getFilePathForPPiOSBundle:(NSString*)dylibName {

NSString * dylibsPath = [[NSBundle mainBundle] pathForResource:@"ppiOSBundle" ofType:@"bundle"];
if (dylibsPath) {
NSBundle * ppiOSBundle = [NSBundle bundleWithPath:dylibsPath];
if (ppiOSBundle) {
NSString * path = [[ppiOSBundle resourcePath] stringByAppendingPathComponent:dylibName];
return path;
}
}
return nil;

}

@end

2 changes: 2 additions & 0 deletions Source/CDLCSegment.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,12 @@ extern NSString *CDSegmentEncryptionTypeName(CDSegmentEncryptionType type);
- (NSString *)flagDescription;

- (BOOL)containsAddress:(NSUInteger)address;
- (BOOL)containsOffset:(NSUInteger)address;
- (CDSection *)sectionContainingAddress:(NSUInteger)address;
- (CDSection *)sectionWithName:(NSString *)name;
- (NSUInteger)fileOffsetForAddress:(NSUInteger)address;
- (NSUInteger)segmentOffsetForAddress:(NSUInteger)address;
- (NSUInteger)addressForDataOffset:(NSUInteger)offset;

- (void)writeSectionData;

Expand Down
15 changes: 15 additions & 0 deletions Source/CDLCSegment.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ - (NSUInteger)vmaddr;
return _segmentCommand.vmaddr;
}

- (NSUInteger)vmsize;
{
return _segmentCommand.vmsize;
}

- (NSUInteger)fileoff;
{
return _segmentCommand.fileoff;
Expand Down Expand Up @@ -169,6 +174,11 @@ - (BOOL)containsAddress:(NSUInteger)address;
return (address >= _segmentCommand.vmaddr) && (address < _segmentCommand.vmaddr + _segmentCommand.vmsize);
}

- (BOOL)containsOffset:(NSUInteger)address
{
return (address >= _segmentCommand.fileoff) && (address < _segmentCommand.fileoff + _segmentCommand.filesize);
}

- (CDSection *)sectionContainingAddress:(NSUInteger)address;
{
for (CDSection *section in self.sections) {
Expand All @@ -194,6 +204,11 @@ - (NSUInteger)fileOffsetForAddress:(NSUInteger)address;
return [[self sectionContainingAddress:address] fileOffsetForAddress:address];
}

- (NSUInteger)addressForDataOffset:(NSUInteger)offset
{
return self.vmaddr + (offset - self.fileoff);
}

- (NSUInteger)segmentOffsetForAddress:(NSUInteger)address;
{
return [self fileOffsetForAddress:address] - self.fileoff;
Expand Down
1 change: 1 addition & 0 deletions Source/CDMachOFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef enum : NSUInteger {
- (NSString *)stringAtAddress:(NSUInteger)address;

- (NSUInteger)dataOffsetForAddress:(NSUInteger)address;
- (NSUInteger)addressForDataOffset:(NSUInteger)offset;

- (const void *)bytes;
- (const void *)bytesAtOffset:(NSUInteger)offset;
Expand Down
33 changes: 32 additions & 1 deletion Source/CDMachOFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,17 @@ - (CDLCSegment *)segmentContainingAddress:(NSUInteger)address;
return nil;
}

- (CDLCSegment *)segmentContainingOffset:(NSUInteger)offset;
{
for (id loadCommand in _loadCommands) {
if ([loadCommand isKindOfClass:[CDLCSegment class]] && [loadCommand containsOffset:offset]) {
return loadCommand;
}
}

return nil;
}

- (void)showWarning:(NSString *)warning;
{
NSLog(@"Warning: %@", warning);
Expand Down Expand Up @@ -356,7 +367,8 @@ - (NSString *)stringAtAddress:(NSUInteger)address;
CDSection *section = [segment sectionContainingAddress:address];
if ([[section sectionName] isEqualToString:@"__objc_selrefs"]) {
const void * reference = [self.data bytes] + offset;
offset = ([self ptrSize] == 8) ? *((uint64_t *)reference) : *((uint32_t *)reference);
NSUInteger vmaddr = ([self ptrSize] == 8) ? *((uint64_t *)reference) : *((uint32_t *)reference);
offset = [self dataOffsetForAddress:vmaddr];
}

ptr = (uint8_t *)[self.data bytes] + offset;
Expand All @@ -383,6 +395,25 @@ - (NSUInteger)dataOffsetForAddress:(NSUInteger)address;
return [segment fileOffsetForAddress:address];
}

- (NSUInteger)addressForDataOffset:(NSUInteger)offset
{
if (offset == 0)
return 0;

CDLCSegment *segment = [self segmentContainingOffset:offset];
if (segment == nil) {
NSLog(@"Error: Cannot find segment for data offset 0x%08lx in segmentContainingOffset:", offset);
exit(5);
}

if ([segment isProtected]) {
NSLog(@"Error: Segment is protected.");
exit(5);
}

return [segment addressForDataOffset:offset];
}

- (const void *)bytes;
{
return [self.data bytes];
Expand Down
6 changes: 6 additions & 0 deletions Source/CDObjectiveC2Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,12 @@ - (NSArray *)loadMethodsAtAddress:(uint64_t)address extendedMethodTypesCursor:(C
objc2Method.name = [cursor readPtr:small];
objc2Method.types = [cursor readPtr:small];
objc2Method.imp = [cursor readPtr:small];

if (small) {
objc2Method.name = [self.machOFile addressForDataOffset:objc2Method.name];
objc2Method.types = [self.machOFile addressForDataOffset:objc2Method.types];
}

NSString *name = [self.machOFile stringAtAddress:objc2Method.name];
NSString *types = [self.machOFile stringAtAddress:objc2Method.types];

Expand Down
Loading