forked from Polidea/ios-class-guard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Polidea#4 from marcinkiewiczblazej/xcdatamodel
Added Storyboard and Xib files obfuscation
- Loading branch information
Showing
17 changed files
with
339 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "CDParserSharedBase.h" | ||
|
||
@class GDataXMLElement; | ||
|
||
|
||
@interface CDCoreDataModelParser : CDParserSharedBase | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#import "CDCoreDataModelParser.h" | ||
#import "GDataXMLNode.h" | ||
|
||
|
||
@implementation CDCoreDataModelParser | ||
|
||
- (void)addSymbolsFromNode:(GDataXMLElement *)element toArray:(NSMutableArray *)symbolsArray { | ||
NSArray *childNodes = element.children; | ||
|
||
// Get the class name | ||
GDataXMLNode *className = [element attributeForName:@"representedClassName"]; | ||
if (className) { | ||
[symbolsArray addObject:[NSString stringWithFormat:@"!%@", className.stringValue]]; | ||
} | ||
|
||
// Get the class name | ||
GDataXMLNode *parentClassName = [element attributeForName:@"parentEntity"]; | ||
if (parentClassName) { | ||
[symbolsArray addObject:[NSString stringWithFormat:@"!%@", parentClassName.stringValue]]; | ||
} | ||
|
||
// Recursively process rest of the elements | ||
for (GDataXMLElement *childNode in childNodes) { | ||
// Skip comments | ||
if ([childNode isKindOfClass:[GDataXMLElement class]]) { | ||
[self addSymbolsFromNode:childNode toArray:symbolsArray]; | ||
} | ||
} | ||
} | ||
|
||
- (void)obfuscateElement:(GDataXMLElement *)element usingSymbols:(NSDictionary *)symbols { | ||
// TODO implement later | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
|
||
@interface CDCoreDataModelProcessor : NSObject | ||
- (NSArray *)coreDataModelSymbolsToExclude; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#import "CDCoreDataModelProcessor.h" | ||
#import "CDCoreDataModelParser.h" | ||
|
||
|
||
@implementation CDCoreDataModelProcessor | ||
|
||
- (NSArray *)coreDataModelSymbolsToExclude { | ||
NSMutableArray *coreDataModelSymbols = [NSMutableArray array]; | ||
CDCoreDataModelParser *parser = [[CDCoreDataModelParser alloc] init]; | ||
|
||
__weak CDCoreDataModelProcessor *weakSelf = self; | ||
|
||
|
||
void (^modelCallback)(NSURL *) = ^(NSURL *url){ | ||
NSLog(@"Fetching symbols from CoreData model at path %@", url); | ||
[coreDataModelSymbols addObjectsFromArray:[parser symbolsInData:[NSData dataWithContentsOfURL:url]]]; | ||
}; | ||
|
||
void (^xcdatamodelCallback)(NSURL *) = ^(NSURL *url){ | ||
[weakSelf findFileWithSuffix:@"contents" inDirectoryURL:url foundCallback:modelCallback]; | ||
}; | ||
|
||
void (^xcdatamodeldCallback)(NSURL *) = ^(NSURL *url){ | ||
[weakSelf findDirectoryWithSuffix:@".xcdatamodel/" inDirectoryURL:url foundCallback:xcdatamodelCallback]; | ||
}; | ||
|
||
|
||
[self findDirectoryWithSuffix:@".xcdatamodeld/" inDirectoryURL:[NSURL URLWithString:@"."] foundCallback:xcdatamodeldCallback]; | ||
|
||
return coreDataModelSymbols; | ||
} | ||
|
||
- (void)findFileWithSuffix:(NSString *)string inDirectoryURL:(NSURL *)URL foundCallback:(void (^)(NSURL *))callback { | ||
[self findFilesOrDirectoryWithString:string isDirectory:NO URL:URL callback:callback]; | ||
} | ||
|
||
- (void)findDirectoryWithSuffix:(NSString *)string inDirectoryURL:(NSURL *)URL foundCallback:(void (^)(NSURL *))callback { | ||
[self findFilesOrDirectoryWithString:string isDirectory:YES URL:URL callback:callback]; | ||
} | ||
|
||
- (void)findFilesOrDirectoryWithString:(NSString *)string isDirectory:(BOOL)directory URL:(NSURL *)URL callback:(void (^)(NSURL *))callback { | ||
NSFileManager *fileManager = [NSFileManager defaultManager]; | ||
NSArray *keys = [NSArray arrayWithObject:NSURLIsDirectoryKey]; | ||
|
||
NSDirectoryEnumerator *enumerator = [fileManager | ||
enumeratorAtURL:URL | ||
includingPropertiesForKeys:keys | ||
options:0 | ||
errorHandler:^(NSURL *url, NSError *error) { | ||
// Handle the error. | ||
// Return YES if the enumeration should continue after the error. | ||
return YES; | ||
}]; | ||
|
||
for (NSURL *url in enumerator) { | ||
NSError *error; | ||
NSNumber *isDirectory = nil; | ||
|
||
if ([url getResourceValue:&isDirectory forKey:NSURLIsDirectoryKey error:&error] && [isDirectory boolValue] == directory) { | ||
if ([url.absoluteString hasSuffix:string]) { | ||
if (callback) { | ||
callback(url); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@class GDataXMLElement; | ||
|
||
@interface CDParserSharedBase : NSObject | ||
- (NSArray *)symbolsInData:(NSData *)data; | ||
|
||
- (NSData *)obfuscatedXmlData:(NSData *)data symbols:(NSDictionary *)symbols; | ||
|
||
- (void)addSymbolsFromNode:(GDataXMLElement *)xmlDictionary toArray:(NSMutableArray *)symbolsArray; | ||
- (void)obfuscateElement:(GDataXMLElement *)element usingSymbols:(NSDictionary *)symbols; | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#import "CDParserSharedBase.h" | ||
#import "GDataXMLNode.h" | ||
|
||
|
||
@implementation CDParserSharedBase | ||
|
||
- (NSArray *)symbolsInData:(NSData *)data { | ||
NSMutableArray *array = [NSMutableArray array]; | ||
|
||
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data error:nil]; | ||
|
||
[self addSymbolsFromNode:doc.rootElement toArray:array]; | ||
|
||
return array; | ||
} | ||
|
||
- (NSData *)obfuscatedXmlData:(NSData *)data symbols:(NSDictionary *)symbols { | ||
GDataXMLDocument *doc = [[GDataXMLDocument alloc] initWithData:data error:nil]; | ||
|
||
[self obfuscateElement:doc.rootElement usingSymbols:symbols]; | ||
|
||
return doc.XMLData; | ||
} | ||
|
||
- (void)addSymbolsFromNode:(GDataXMLElement *)xmlDictionary toArray:(NSMutableArray *)symbolsArray {} | ||
- (void)obfuscateElement:(GDataXMLElement *)element usingSymbols:(NSDictionary *)symbols {} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
Source/CDSymoblsGeneratorVisitor.h → Source/CDSymbolsGeneratorVisitor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
#import <Foundation/Foundation.h> | ||
#import "CDParserSharedBase.h" | ||
|
||
|
||
@interface CDXibStoryboardParser : NSObject | ||
|
||
- (NSData *)obfuscatedXmlData:(NSData *)data symbols:(NSDictionary *)symbols; | ||
@interface CDXibStoryboardParser : CDParserSharedBase | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#import <Kiwi/Kiwi.h> | ||
|
||
#import "CDCoreDataModelParser.h" | ||
|
||
SPEC_BEGIN(CDCoreDataModelParserSpec) | ||
|
||
describe(@"CDCoreDataModelParser", ^{ | ||
__block CDCoreDataModelParser *parser; | ||
|
||
|
||
__block NSURL *fileUrl; | ||
NSString *className = @"TestEntityA"; | ||
NSString *parentClass = @"TestParentEntity"; | ||
|
||
beforeEach(^{ | ||
parser = [[CDCoreDataModelParser alloc] init]; | ||
for (NSBundle *bundle in [NSBundle allBundles]) { | ||
NSURL *url = [bundle URLForResource:@"contents" withExtension:nil]; | ||
if (url) { | ||
fileUrl = url; | ||
} | ||
} | ||
}); | ||
|
||
describe(@"parsing core data model", ^{ | ||
it(@"should generate symbol for class name", ^{ | ||
NSArray *symbols = [parser symbolsInData:[NSData dataWithContentsOfURL:fileUrl]]; | ||
|
||
[[symbols should] contain:[NSString stringWithFormat:@"!%@", className]]; | ||
}); | ||
|
||
it(@"should generate symbol for parent class name", ^{ | ||
NSArray *symbols = [parser symbolsInData:[NSData dataWithContentsOfURL:fileUrl]]; | ||
|
||
[[symbols should] contain:[NSString stringWithFormat:@"!%@", parentClass]]; | ||
}); | ||
}); | ||
}); | ||
|
||
SPEC_END |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | ||
<model userDefinedModelVersionIdentifier="" type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="5064" systemVersion="13E28" minimumToolsVersion="Xcode 4.3" macOSVersion="Automatic" iOSVersion="Automatic"> | ||
<entity name="TestEntityA" representedClassName="TestEntityA" syncable="YES"> | ||
<attribute name="attributeA" optional="YES" attributeType="Integer 32" defaultValueString="0" syncable="YES"/> | ||
<relationship name="bs" optional="YES" toMany="YES" deletionRule="Nullify" destinationEntity="TestEntityB" inverseName="a" inverseEntity="TestEntityB" syncable="YES"/> | ||
</entity> | ||
<entity name="TestEntityB" representedClassName="TestEntityB" syncable="YES"> | ||
<attribute name="attributeB" optional="YES" attributeType="String" syncable="YES"/> | ||
<relationship name="a" optional="YES" maxCount="1" deletionRule="Nullify" destinationEntity="TestEntityA" inverseName="bs" inverseEntity="TestEntityA" syncable="YES"/> | ||
</entity> | ||
<entity name="TestEntityC" representedClassName="TestEntityC" parentEntity="TestParentEntity" syncable="YES"/> | ||
<entity name="TestParentEntity" representedClassName="TestParentEntity" syncable="YES"/> | ||
<elements> | ||
<element name="TestEntityA" positionX="-63" positionY="-18" width="128" height="73"/> | ||
<element name="TestEntityB" positionX="-54" positionY="-9" width="128" height="73"/> | ||
<element name="TestEntityC" positionX="-45" positionY="27" width="128" height="43"/> | ||
<element name="TestParentEntity" positionX="-36" positionY="36" width="128" height="43"/> | ||
</elements> | ||
</model> |
Oops, something went wrong.