Skip to content

Commit 169f5ff

Browse files
author
Mike Richter
committed
Merged PR 5438: Update PPiOS-Rename to support Xcode 12 and iOS 14
The binary format of libraries changed somewhat. A new flag was added to a field indicating that three pointers describing methods would be a compressed relative format. A level of indirection was also added for the name fields (__objc_selrefs) so that these relative pointers pointed into a data region that is an array of pointers pointing to the actual location of the method names (selectors). Related work items: #19525
2 parents 14bfb74 + c82f384 commit 169f5ff

File tree

7 files changed

+48
-11
lines changed

7 files changed

+48
-11
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
Change Log
22
==========
33

4+
1.5.0
5+
-----------------------
6+
7+
### Enhancements:
8+
9+
* Now supports Xcode 12 and iOS 14.
10+
11+
### Changes:
12+
13+
* Xcode 10 is no longer supported.
14+
15+
416
1.4.0
517
-----------------------
618

Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ SPEC CHECKSUMS:
1313

1414
PODFILE CHECKSUM: c3c2eb4605f372c09bc80aa574760a0658292232
1515

16-
COCOAPODS: 1.5.3
16+
COCOAPODS: 1.9.3

Source/CDMachOFile.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,13 @@ - (NSString *)stringAtAddress:(NSUInteger)address;
352352
if (offset == 0)
353353
return nil;
354354

355+
// Support small methods referencing selector names in __objc_selrefs.
356+
CDSection *section = [segment sectionContainingAddress:address];
357+
if ([[section sectionName] isEqualToString:@"__objc_selrefs"]) {
358+
const void * reference = [self.data bytes] + offset;
359+
offset = ([self ptrSize] == 8) ? *((uint64_t *)reference) : *((uint32_t *)reference);
360+
}
361+
355362
ptr = (uint8_t *)[self.data bytes] + offset;
356363

357364
return [[NSString alloc] initWithBytes:ptr length:strlen(ptr) encoding:NSASCIIStringEncoding];

Source/CDMachOFileDataCursor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@
2828

2929
// Read using the current byteOrder and ptrSize (from the machOFile)
3030
- (uint64_t)readPtr;
31+
- (uint64_t)readPtr:(bool)small;
3132

3233
@end

Source/CDMachOFileDataCursor.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,15 @@ - (uint64_t)readPtr;
110110
return 0;
111111
}
112112

113+
- (uint64_t)readPtr:(bool)small;
114+
{
115+
// "small" pointers are signed 32-bit values
116+
if (small) {
117+
// The pointers are relative to the location in the image, so get the offset before reading the offset:
118+
return [self offset] + [self readInt32];
119+
} else {
120+
return [self readPtr];
121+
}
122+
}
123+
113124
@end

Source/CDObjectiveC2Processor.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
#import "CDObjectiveCProcessor.h"
77

8+
#define METHOD_LIST_T_RESERVED_BITS 0x7FFF0003
9+
#define METHOD_LIST_T_SMALL_METHOD_FLAG 0x80000000
10+
#define METHOD_LIST_T_ENTSIZE_MASK (METHOD_LIST_T_RESERVED_BITS|METHOD_LIST_T_SMALL_METHOD_FLAG)
11+
812
@interface CDObjectiveC2Processor : CDObjectiveCProcessor
913

1014
@end

Source/CDObjectiveC2Processor.m

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,19 @@ - (NSArray *)loadMethodsAtAddress:(uint64_t)address extendedMethodTypesCursor:(C
410410

411411
struct cd_objc2_list_header listHeader;
412412

413-
// See getEntsize() from http://www.opensource.apple.com/source/objc4/objc4-532.2/runtime/objc-runtime-new.h
414-
listHeader.entsize = [cursor readInt32] & ~(uint32_t)3;
415-
listHeader.count = [cursor readInt32];
416-
NSParameterAssert(listHeader.entsize == 3 * [self.machOFile ptrSize]);
417-
413+
// See https://opensource.apple.com/source/objc4/objc4-787.1/runtime/objc-runtime-new.h
414+
uint32_t value = [cursor readInt32];
415+
listHeader.entsize = value & ~METHOD_LIST_T_ENTSIZE_MASK;
416+
bool small = (value & METHOD_LIST_T_SMALL_METHOD_FLAG) != 0;
417+
listHeader.count = [cursor readInt32];
418+
NSParameterAssert(listHeader.entsize == 3 * (small ? sizeof(int32_t) : [self.machOFile ptrSize]));
419+
418420
for (uint32_t index = 0; index < listHeader.count; index++) {
419421
struct cd_objc2_method objc2Method;
420-
421-
objc2Method.name = [cursor readPtr];
422-
objc2Method.types = [cursor readPtr];
423-
objc2Method.imp = [cursor readPtr];
422+
423+
objc2Method.name = [cursor readPtr:small];
424+
objc2Method.types = [cursor readPtr:small];
425+
objc2Method.imp = [cursor readPtr:small];
424426
NSString *name = [self.machOFile stringAtAddress:objc2Method.name];
425427
NSString *types = [self.machOFile stringAtAddress:objc2Method.types];
426428

@@ -429,7 +431,7 @@ - (NSArray *)loadMethodsAtAddress:(uint64_t)address extendedMethodTypesCursor:(C
429431
types = [self.machOFile stringAtAddress:extendedMethodTypes];
430432
}
431433

432-
//NSLog(@"%3u: %016lx %016lx %016lx", index, objc2Method.name, objc2Method.types, objc2Method.imp);
434+
//NSLog(@"%3u: %016llx %016llx %016llx", index, objc2Method.name, objc2Method.types, objc2Method.imp);
433435
//NSLog(@"name: %@", name);
434436
//NSLog(@"types: %@", types);
435437

0 commit comments

Comments
 (0)