Skip to content

Commit

Permalink
修复崩溃bug,修复私有库没过滤导致部分系统方法被混淆。
Browse files Browse the repository at this point in the history
  • Loading branch information
chenxiancai committed Aug 2, 2018
1 parent 2330afa commit 2d5a6df
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 139 deletions.
81 changes: 0 additions & 81 deletions STCDefination.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,6 @@
#ifndef SDWebImageCombinedOperation
#define SDWebImageCombinedOperation _STC4A67C81062FFB09CD7DDBB52215D72A5_
#endif
#ifndef serializer
#define serializer _STCF3FD8E1EFA847CCF3622D0768BA82665_
#endif
#ifndef cachePathForKey
#define cachePathForKey _STC2BD38762C83998FEA4B5DDC1DE30C92B_
#endif
Expand Down Expand Up @@ -202,9 +199,6 @@
#ifndef diskImageForKey
#define diskImageForKey _STCF877AC81169C4F414CA798A87E5336E9_
#endif
#ifndef defaultPolicy
#define defaultPolicy _STC79A1234797AFF55F08077C4FD617CD93_
#endif
#ifndef shouldDecodeImage
#define shouldDecodeImage _STC3F697CF47265D41D1BC4070895DF7592_
#endif
Expand Down Expand Up @@ -283,9 +277,6 @@
#ifndef storeImageDataToDisk
#define storeImageDataToDisk _STC35D9664E535C618B5BDF345017AA4043_
#endif
#ifndef validateResponse
#define validateResponse _STC1CA8F6B32B98D703F7C527D85291EA15_
#endif
#ifndef HEAD
#define HEAD _STC7D01E935D238069E407AF2705562CEE1_
#endif
Expand Down Expand Up @@ -316,9 +307,6 @@
#ifndef evaluateServerTrust
#define evaluateServerTrust _STC01308F0D37F55A4C7071A90CEB31ED5A_
#endif
#ifndef forDomain
#define forDomain _STC33F5DDE97899B3B3DE0CC593C6358489_
#endif
#ifndef networkRequestDidStart
#define networkRequestDidStart _STC7AE445D905496DD5C2BA52F2D7910617_
#endif
Expand Down Expand Up @@ -349,9 +337,6 @@
#ifndef startMergedTask
#define startMergedTask _STC10E77B98127FC1C2984CFC0E8089075B_
#endif
#ifndef cancelAllDownloads
#define cancelAllDownloads _STCF365505AFE4F6762275666B6E3734D17_
#endif
#ifndef isActiveRequestCountBelowMaximumLimit
#define isActiveRequestCountBelowMaximumLimit _STCBC9BCABE79AEE35935A6A198E73510BA_
#endif
Expand Down Expand Up @@ -439,9 +424,6 @@
#ifndef cancelInternal
#define cancelInternal _STC96F74B285474121E112FFA4E6A6DCE90_
#endif
#ifndef getSize
#define getSize _STC0AFDDCEF914C9C5C0DF03B5064B11D61_
#endif
#ifndef diskImageDataExistsWithKey
#define diskImageDataExistsWithKey _STC82EF090905AB1ECF6B172D05AA744924_
#endif
Expand Down Expand Up @@ -727,15 +709,6 @@
#ifndef setLastAccessDate
#define setLastAccessDate set_STC0072DCEF42EF11BFAA57545C81B33437_
#endif
#ifndef taskDidComplete
#define taskDidComplete _STC0B7228ED8E6196A7CC101CF9CEF47697_
#endif
#ifndef _taskDidComplete
#define _taskDidComplete __STC0B7228ED8E6196A7CC101CF9CEF47697_
#endif
#ifndef setTaskDidComplete
#define setTaskDidComplete set_STC0B7228ED8E6196A7CC101CF9CEF47697_
#endif
#ifndef shouldUseCredentialStorage
#define shouldUseCredentialStorage _STC74342D8A939F07CC91D7D8753EB7F306_
#endif
Expand Down Expand Up @@ -772,15 +745,6 @@
#ifndef setDownloadPrioritizaton
#define setDownloadPrioritizaton set_STCF34844C0009B7A20EEB6E6A643AF3013_
#endif
#ifndef fileManager
#define fileManager _STCFF05D65A1A51C5A46775C7766288ABA6_
#endif
#ifndef _fileManager
#define _fileManager __STCFF05D65A1A51C5A46775C7766288ABA6_
#endif
#ifndef setFileManager
#define setFileManager set_STCFF05D65A1A51C5A46775C7766288ABA6_
#endif
#ifndef maxMemoryCountLimit
#define maxMemoryCountLimit _STCD76456AEA24F67BE1BBE2269586856AA_
#endif
Expand Down Expand Up @@ -907,15 +871,6 @@
#ifndef setCompletionDelayTimer
#define setCompletionDelayTimer set_STC52309E07DED8E84C6AB113999BA2457D_
#endif
#ifndef downloadProgressBlock
#define downloadProgressBlock _STC22B80933A66FF262CADE54F9CE60BF2B_
#endif
#ifndef _downloadProgressBlock
#define _downloadProgressBlock __STC22B80933A66FF262CADE54F9CE60BF2B_
#endif
#ifndef setDownloadProgressBlock
#define setDownloadProgressBlock set_STC22B80933A66FF262CADE54F9CE60BF2B_
#endif
#ifndef cacheOperation
#define cacheOperation _STCCD4C929A35A640788AF163F0778DDF5F_
#endif
Expand Down Expand Up @@ -1105,15 +1060,6 @@
#ifndef setNetworkReachabilityStatus
#define setNetworkReachabilityStatus set_STCD3B862A42B64159E3379225027753D7B_
#endif
#ifndef diskCachePath
#define diskCachePath _STC8BFFC467F8F60ACA7C4CBB14553C209E_
#endif
#ifndef _diskCachePath
#define _diskCachePath __STC8BFFC467F8F60ACA7C4CBB14553C209E_
#endif
#ifndef setDiskCachePath
#define setDiskCachePath set_STC8BFFC467F8F60ACA7C4CBB14553C209E_
#endif
#ifndef requestHeaderModificationQueue
#define requestHeaderModificationQueue _STC484681E6731119FD60C981D91C2D8A03_
#endif
Expand All @@ -1132,15 +1078,6 @@
#ifndef setPropertyforKey
#define setPropertyforKey set_STCECBCBEC3FFA37DDCFF37683BFA05B1BD_
#endif
#ifndef cachedData
#define cachedData _STC074F63E5953C3CA949C58755EE82C075_
#endif
#ifndef _cachedData
#define _cachedData __STC074F63E5953C3CA949C58755EE82C075_
#endif
#ifndef setCachedData
#define setCachedData set_STC074F63E5953C3CA949C58755EE82C075_
#endif
#ifndef coders
#define coders _STC1FA9DAD928A44DDABFE1E03D21747967_
#endif
Expand Down Expand Up @@ -1240,15 +1177,6 @@
#ifndef setHTTPBodyPartEnumerator
#define setHTTPBodyPartEnumerator set_STCFFDFAD3016C50A582836D980BE1DAE32_
#endif
#ifndef responseQueue
#define responseQueue _STC2862AB9FD4790F44C050A0C08A1F0E36_
#endif
#ifndef _responseQueue
#define _responseQueue __STC2862AB9FD4790F44C050A0C08A1F0E36_
#endif
#ifndef setResponseQueue
#define setResponseQueue set_STC2862AB9FD4790F44C050A0C08A1F0E36_
#endif
#ifndef uploadTasks
#define uploadTasks _STCCA4AC171A873DBD8AAE02F606C1B7127_
#endif
Expand Down Expand Up @@ -1690,15 +1618,6 @@
#ifndef setTaskDescriptionForSessionTasks
#define setTaskDescriptionForSessionTasks set_STC82C81D9A2C47F8638D55142174F7050D_
#endif
#ifndef downloadProgress
#define downloadProgress _STCA8091C71177CA1AA54C68CEB1BC3DBE3_
#endif
#ifndef _downloadProgress
#define _downloadProgress __STCA8091C71177CA1AA54C68CEB1BC3DBE3_
#endif
#ifndef setDownloadProgress
#define setDownloadProgress set_STCA8091C71177CA1AA54C68CEB1BC3DBE3_
#endif
#ifndef pinnedPublicKeys
#define pinnedPublicKeys _STC521BB24C9DC67536ABDC2935993F2207_
#endif
Expand Down
2 changes: 1 addition & 1 deletion STCObfuscator.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |s|
s.name = 'STCObfuscator'
s.summary = 'Objective-C obfuscator for Mach-O executables, a runtime utility for obfuscating Objective-C class..'
s.version = '1.2.0'
s.version = '1.3.0'
s.license = { :type => 'MIT', :file => 'LICENSE' }
s.authors = { 'chenxiancai' => 'chenxiancai@hotmail.com' }
s.homepage = 'https://github.com/chenxiancai/STCObfuscator'
Expand Down
Binary file not shown.
63 changes: 47 additions & 16 deletions STCObfuscator/STCObfuscator/STCObfuscator.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,33 @@
#import <CommonCrypto/CommonDigest.h>
#include "ahocorasick.h"

@interface NSString (STCObfuscator)

- (NSString *)stcSubstringToIndex:(NSInteger)index;

- (NSString *)stcSubstringFromIndex:(NSInteger)index;

@end

@implementation NSString (STCObfuscator)
- (NSString *)stcSubstringToIndex:(NSInteger)index
{
if ([self length] > index){
return [self substringToIndex:index];
}
return self;
}

- (NSString *)stcSubstringFromIndex:(NSInteger)index
{
if ([self length] > index){
return [self substringFromIndex:index];
}
return self;
}

@end

#if (DEBUG == 1)
@implementation STCObfuscator

Expand Down Expand Up @@ -186,8 +213,8 @@ - (void)confuseWithRootPath:(NSString *)rootPath
&& [setMethod hasSuffix:@":"]) {
NSString *getMethod = [setMethod stringByReplacingOccurrencesOfString:@"set" withString:@""];
getMethod = [getMethod stringByReplacingOccurrencesOfString:@":" withString:@""];
if ([[[getMethod substringToIndex:1] uppercaseString] isEqualToString:[[method substringToIndex:1]uppercaseString]]
&& [[getMethod substringFromIndex:1] isEqualToString:[method substringFromIndex:1]]) {
if ([[[getMethod stcSubstringToIndex:1] uppercaseString] isEqualToString:[[method stcSubstringToIndex:1]uppercaseString]]
&& [[getMethod stcSubstringFromIndex:1] isEqualToString:[method stcSubstringFromIndex:1]]) {
[confuseProperty addEntriesFromDictionary:@{method: @(YES)}];
[indexSet addIndex:index];
[indexSet addIndex:setIndex];
Expand Down Expand Up @@ -232,9 +259,9 @@ - (void)confuseWithRootPath:(NSString *)rootPath
[unConfuseSymbolsDict addEntriesFromDictionary:@{section: @(YES)}];
// filter set method
} else if ([method hasPrefix:@"set"] && [method hasSuffix:@":"]) {
NSString *property = [method substringFromIndex:3];
NSString *property = [method stcSubstringFromIndex:3];
property = [property stringByReplacingOccurrencesOfString:@":" withString:@""];
property = [[[property substringToIndex:1] lowercaseString] stringByAppendingString:[property substringFromIndex:1]];
property = [[[property stcSubstringToIndex:1] lowercaseString] stringByAppendingString:[property stcSubstringFromIndex:1]];
[confuseProperty addEntriesFromDictionary:@{property: @(YES)}];
[indexSet addIndex:index];
[unConfuseSymbolsDict addEntriesFromDictionary:@{section: @(YES)}];
Expand All @@ -256,8 +283,8 @@ - (void)confuseWithRootPath:(NSString *)rootPath
NSMutableSet *removeProperty = [NSMutableSet set];
[confuseProperty.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSString *property = (NSString *)obj;
NSString *headerStr = [[property substringToIndex:1] uppercaseString];
NSString *tailStr = [property substringFromIndex:1];
NSString *headerStr = [[property stcSubstringToIndex:1] uppercaseString];
NSString *tailStr = [property stcSubstringFromIndex:1];
NSString *similarProperty = [headerStr stringByAppendingString:tailStr];
if (![property isEqualToString:similarProperty]) {
[confuseProperty.allKeys enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
Expand Down Expand Up @@ -319,8 +346,8 @@ - (void)confuseWithRootPath:(NSString *)rootPath

NSString *property = (NSString *)obj;
NSString *str = [property stringByReplacingOccurrencesOfString:@" " withString:@""];
NSString *setStr = [@"set" stringByAppendingString:[[str substringToIndex:1] uppercaseString]];
setStr = [setStr stringByAppendingString:[str substringFromIndex:1]];
NSString *setStr = [@"set" stringByAppendingString:[[str stcSubstringToIndex:1] uppercaseString]];
setStr = [setStr stringByAppendingString:[str stcSubstringFromIndex:1]];
if (str.length > 1
&& ![[unConfuseSymbolsDict objectForKey:str] boolValue]
&& ![[unConfuseSymbolsDict objectForKey:setStr] boolValue]
Expand All @@ -341,8 +368,8 @@ - (void)confuseWithRootPath:(NSString *)rootPath
[jsonObjects addEntriesFromDictionary:@{[@"_" stringByAppendingString:encryptStr]: [@"_" stringByAppendingString:str]}];

// setter
NSString *firstStr = [[str substringToIndex:1] uppercaseString];
NSString *otherStr = [str substringFromIndex:1];
NSString *firstStr = [[str stcSubstringToIndex:1] uppercaseString];
NSString *otherStr = [str stcSubstringFromIndex:1];
newStr = [NSString stringWithFormat:@"#ifndef set%@%@\n#define set%@%@ set%@\n#endif\n", firstStr, otherStr,firstStr,otherStr, encryptStr];
[result appendString:newStr];
[jsonObjects addEntriesFromDictionary:@{[@"set" stringByAppendingString:encryptStr]: [@"set" stringByAppendingString:str]}];
Expand Down Expand Up @@ -388,8 +415,8 @@ - (void)confuseWithRootPath:(NSString *)rootPath
[hardCodeStr appendString:[NSString stringWithFormat:@"#define %@ %@ \n", hardCode, hardCode]];
[hardCodeStr appendString:[NSString stringWithFormat:@"#define _%@ _%@ \n", hardCode, hardCode]];

NSString *setStr = [@"set" stringByAppendingString:[[hardCode substringToIndex:1] uppercaseString]];
setStr = [setStr stringByAppendingString:[hardCode substringFromIndex:1]];
NSString *setStr = [@"set" stringByAppendingString:[[hardCode stcSubstringToIndex:1] uppercaseString]];
setStr = [setStr stringByAppendingString:[hardCode stcSubstringFromIndex:1]];
[hardCodeStr appendString:[NSString stringWithFormat:@"#define %@ %@ \n", setStr, setStr]];
isProperty = YES;
*stop = YES;
Expand Down Expand Up @@ -457,15 +484,18 @@ - (NSMutableDictionary *)systemSymbolsDict
const char ** images = objc_copyImageNames(&imageOutCount);
for (unsigned int i = 0; i < imageOutCount; i++) {
NSString *imageName = [NSString stringWithUTF8String:images[i]];


//NSParagraphStyle Framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/PrivateFrameworks/UIFoundation.framework/UIFoundation, 私有库的类也会放到公开库中使用
/*
if ([imageName containsString:@"PrivateFrameworks"]) {
continue;
}

*/
if ([imageName containsString:@".framework"]
||[imageName containsString:@".dylib"]) {
const char ** class = objc_copyClassNamesForImage(images[i], &classOutCount);
for (unsigned int k = 0; k < classOutCount; k++) {

Class cls = NSClassFromString([NSString stringWithUTF8String:class[k]]);
[classSet addObject:[NSString stringWithUTF8String:class[k]]];

Expand Down Expand Up @@ -552,8 +582,8 @@ - (NSMutableDictionary *)getSymbolsDictWith:(NSArray *)protocols classSet:(NSSet
if (![name hasPrefix:@"_"]) {
[symbolsDict addEntriesFromDictionary:@{name: @(YES)}];
[symbolsDict addEntriesFromDictionary:@{[@"_" stringByAppendingString:name]: @(YES)}];
NSString *setStr = [@"set" stringByAppendingString:[[name substringToIndex:1] uppercaseString]];
[symbolsDict addEntriesFromDictionary:@{[setStr stringByAppendingString:[name substringFromIndex:1]]: @(YES)}];
NSString *setStr = [@"set" stringByAppendingString:[[name stcSubstringToIndex:1] uppercaseString]];
[symbolsDict addEntriesFromDictionary:@{[setStr stringByAppendingString:[name stcSubstringFromIndex:1]]: @(YES)}];
}
}
NSArray *methods = [self allMethodsWithClass:NSClassFromString(className)];
Expand Down Expand Up @@ -1049,4 +1079,5 @@ - (BOOL)isPropertyWithClass:(Class)class andProperty:(NSString *)propertyName
}

@end

#endif
Loading

0 comments on commit 2d5a6df

Please sign in to comment.