Skip to content

Commit

Permalink
support new __DATA_CONST segment in ios 9 binaries
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric Monti committed Jun 11, 2015
1 parent cce181f commit e128b63
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions Source/CDMachOFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef enum : NSUInteger {
- (NSString *)filetypeDescription;
- (NSString *)flagDescription;

- (CDLCSegment *)dataConstSegment;
- (CDLCSegment *)segmentWithName:(NSString *)segmentName;
- (CDLCSegment *)segmentContainingAddress:(NSUInteger)address;
- (NSString *)stringAtAddress:(NSUInteger)address;
Expand Down
15 changes: 14 additions & 1 deletion Source/CDMachOFile.m
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ - (NSString *)flagDescription;

#pragma mark -

- (CDLCSegment *)dataConstSegment
{
// macho objects from iOS 9 appear to store various sections
// in __DATA_CONST that were previously found in __DATA
CDLCSegment *seg = [self segmentWithName:@"__DATA_CONST"];

// Fall back on __DATA if it is not found for earlier behavior
if (!seg) {
seg = [self segmentWithName:@"__DATA"];
}
return seg;
}

- (CDLCSegment *)segmentWithName:(NSString *)segmentName;
{
for (id loadCommand in _loadCommands) {
Expand Down Expand Up @@ -558,7 +571,7 @@ - (BOOL)hasObjectiveC2Data;
// 0xced: @gparker I was hoping for a flag, but that will do it, thanks.
// 0xced: @gparker Did you mean __DATA,__objc_imageinfo instead of __DATA,__objc_info ?
// gparker: @0xced Yes, it's __DATA,__objc_imageinfo.
return [[self segmentWithName:@"__DATA"] sectionWithName:@"__objc_imageinfo"] != nil;
return [[self dataConstSegment] sectionWithName:@"__objc_imageinfo"] != nil;
}

- (Class)processorClass;
Expand Down
8 changes: 4 additions & 4 deletions Source/CDObjectiveC2Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ @implementation CDObjectiveC2Processor

- (void)loadProtocols;
{
CDSection *section = [[self.machOFile segmentWithName:@"__DATA"] sectionWithName:@"__objc_protolist"];
CDSection *section = [[self.machOFile dataConstSegment] sectionWithName:@"__objc_protolist"];

CDMachOFileDataCursor *cursor = [[CDMachOFileDataCursor alloc] initWithSection:section];
while ([cursor isAtEnd] == NO)
Expand All @@ -36,7 +36,7 @@ - (void)loadProtocols;

- (void)loadClasses;
{
CDSection *section = [[self.machOFile segmentWithName:@"__DATA"] sectionWithName:@"__objc_classlist"];
CDSection *section = [[self.machOFile dataConstSegment] sectionWithName:@"__objc_classlist"];

CDMachOFileDataCursor *cursor = [[CDMachOFileDataCursor alloc] initWithSection:section];
while ([cursor isAtEnd] == NO) {
Expand All @@ -50,7 +50,7 @@ - (void)loadClasses;

- (void)loadCategories;
{
CDSection *section = [[self.machOFile segmentWithName:@"__DATA"] sectionWithName:@"__objc_catlist"];
CDSection *section = [[self.machOFile dataConstSegment] sectionWithName:@"__objc_catlist"];

CDMachOFileDataCursor *cursor = [[CDMachOFileDataCursor alloc] initWithSection:section];
while ([cursor isAtEnd] == NO) {
Expand Down Expand Up @@ -490,7 +490,7 @@ - (NSArray *)protocolAddressListAtAddress:(uint64_t)address;

- (CDSection *)objcImageInfoSection;
{
return [[self.machOFile segmentWithName:@"__DATA"] sectionWithName:@"__objc_imageinfo"];
return [[self.machOFile dataConstSegment] sectionWithName:@"__objc_imageinfo"];
}

@end

0 comments on commit e128b63

Please sign in to comment.