Skip to content

Commit

Permalink
Merged PR 2535: Merge mrichter/detect-swift to master
Browse files Browse the repository at this point in the history
This was the cheapest implementation: bubble up the error condition to `class-dump.m` and exit.

Related work items: #17148
  • Loading branch information
Mike Richter committed Sep 13, 2018
2 parents 9d66aae + efe1d86 commit b8e3b58
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 17 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Change Log
### Enhancements:
### Changes:

* Removed references to PPiOS-ControlFlow and PPiOS-Sample-Vie from all other files.
* Removed references to PPiOS-ControlFlow and PPiOS-Sample-Vie from all other files. (\#17218)

### Fixes:

* An explicit error message is now emitted when Swift classes are encountered. (\#17148)


1.2.0
-----------------------
Expand Down
2 changes: 1 addition & 1 deletion Source/CDClassDump.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
@property (readonly) CDTypeController *typeController;

- (BOOL)loadFile:(CDFile *)file error:(NSError **)error depth:(int)depth;
- (void)processObjectiveCData;
- (int)processObjectiveCData;

- (void)recursivelyVisit:(CDVisitor *)visitor;

Expand Down
12 changes: 7 additions & 5 deletions Source/CDClassDump.m
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,18 @@ - (BOOL)loadFile:(CDFile *)file error:(NSError **)error depth:(int)depth {

#pragma mark -

- (void)processObjectiveCData;
- (int)processObjectiveCData;
{
for (CDMachOFile *machOFile in self.machOFiles) {
CDObjectiveCProcessor *processor = [[[machOFile processorClass] alloc] initWithMachOFile:machOFile];
[processor process];
int result = [processor process];
if (result != 0) {
return result;
}
[_objcProcessors addObject:processor];
}

return 0;
}

// This visits everything segment processors, classes, categories. It skips over modules. Need something to visit modules so we can generate separate headers.
Expand All @@ -266,9 +271,6 @@ - (void)recursivelyVisit:(CDVisitor *)visitor;
NSEnumerator *objcProcessors;
objcProcessors = [self.objcProcessors reverseObjectEnumerator];




for (CDObjectiveCProcessor *processor in objcProcessors) {
[processor recursivelyVisit:visitor];
}
Expand Down
1 change: 1 addition & 0 deletions Source/CDOCClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
@property (copy, readonly) NSString *superClassName;
@property (strong) NSArray *instanceVariables;
@property (assign) BOOL isExported;
@property (assign) BOOL isSwiftClass;

@end
9 changes: 7 additions & 2 deletions Source/CDObjectiveC1Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,18 @@ - (id)initWithMachOFile:(CDMachOFile *)machOFile;

#pragma mark -

- (void)process;
- (int)process;
{
if ([self.machOFile isEncrypted] == NO && [self.machOFile canDecryptAllSegments]) {
[super process];
int result = [super process];
if (result != 0) {
return result;
}

[self processModules];
}

return 0;
}

#pragma mark - Formerly private
Expand Down
15 changes: 13 additions & 2 deletions Source/CDObjectiveC2Processor.m
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ - (void)loadProtocols;
[self protocolAtAddress:[cursor readPtr]];
}

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

Expand All @@ -43,9 +43,15 @@ - (void)loadClasses;
uint64_t val = [cursor readPtr];
CDOCClass *aClass = [self loadClassAtAddress:val];
if (aClass != nil) {
if (aClass.isSwiftClass) {
NSLog(@"Error: Swift is not supported: %@", aClass.name);
return 1;
}
[self addClass:aClass withAddress:val];
}
}

return 0;
}

- (void)loadCategories;
Expand Down Expand Up @@ -218,7 +224,11 @@ - (CDOCClass *)loadClassAtAddress:(uint64_t)address;
objc2Class.superclass = [cursor readPtr];
objc2Class.cache = [cursor readPtr];
objc2Class.vtable = [cursor readPtr];
objc2Class.data = [cursor readPtr];

uint64_t value = [cursor readPtr];
BOOL isSwiftClass = (value & 0x1) != 0;
objc2Class.data = value & ~7;

objc2Class.reserved1 = [cursor readPtr];
objc2Class.reserved2 = [cursor readPtr];
objc2Class.reserved3 = [cursor readPtr];
Expand Down Expand Up @@ -254,6 +264,7 @@ - (CDOCClass *)loadClassAtAddress:(uint64_t)address;

CDOCClass *aClass = [[CDOCClass alloc] init];
[aClass setName:str];
aClass.isSwiftClass = isSwiftClass;

for (CDOCMethod *method in [self loadMethodsAtAddress:objc2ClassData.baseMethods])
[aClass addInstanceMethod:method];
Expand Down
4 changes: 2 additions & 2 deletions Source/CDObjectiveCProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

- (void)addCategory:(CDOCCategory *)category;

- (void)process;
- (int)process;
- (void)loadProtocols;
- (void)loadClasses;
- (int)loadClasses;
- (void)loadCategories;

- (void)registerTypesWithObject:(CDTypeController *)typeController phase:(NSUInteger)phase;
Expand Down
12 changes: 9 additions & 3 deletions Source/CDObjectiveCProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ - (void)addCategory:(CDOCCategory *)category;

#pragma mark - Processing

- (void)process;
- (int)process;
{
if (self.machOFile.isEncrypted == NO && self.machOFile.canDecryptAllSegments) {
[self.machOFile.symbolTable loadSymbols];
Expand All @@ -146,19 +146,25 @@ - (void)process;
[self.protocolUniquer createUniquedProtocols];

// Load classes before categories, so we can get a dictionary of classes by address.
[self loadClasses];
int result = [self loadClasses];
if (result != 0) {
return result;
}
[self loadCategories];
}

return 0;
}

- (void)loadProtocols;
{
// Implement in subclasses.
}

- (void)loadClasses;
- (int)loadClasses;
{
// Implement in subclasses.
return 0;
}

- (void)loadCategories;
Expand Down
6 changes: 5 additions & 1 deletion Source/class-dump.m
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,11 @@ int main(int argc, char *argv[])
terminateWithError(1, "Error: %s", [[error localizedFailureReason] UTF8String]);
}

[classDump processObjectiveCData];
int result = [classDump processObjectiveCData];
if (result != 0) {
// errors already reported
exit(result);
}
[classDump registerTypes];
NSArray<NSString *> *classFilters
= assembleClassFilters(classDump, commandLineClassFilters);
Expand Down

0 comments on commit b8e3b58

Please sign in to comment.