(给iOS大全加星标,关注iOS动态)
转自:掘金-jackyshan
背景
一些类似的项目会使用重复的代码,导致苹果机审期间被判断为马甲包,还没到人审就被苹果审核拒掉了。为了能够使正常迭代出功能相似的项目过审,要对我们项目的代码进行深度混淆。
方案
1、准备四六级单词库(如果使用随机字符会被机审查出来);2、使用clang过滤出类名和方法名;3、从四六级单词库随机组成,映射对应的类名和方法名;4、通过映射进行混淆操作。
四六级单词库
区分首字母小写和大写的txt
![daf7147e7f1f9e4ec2cf6dc331d5ac63.png](https://img-blog.csdnimg.cn/img_convert/daf7147e7f1f9e4ec2cf6dc331d5ac63.png)
安装clang
pip install clang --user
类名混淆
提取类名
# encoding: utf-8import sysimport osimport reimport clangfrom clang.cindex import *from optparse import OptionParser, OptionGroupdef get_tu(source, lang='c', all_warnings=False, flags=[]): """Obtain a translation unit from source and language. By default, the translation unit is created from source file "t." where is the default file extension for the specified language. By default it is C, so "t.c" is the default file name. Supported languages are {c, cpp, objc}. all_warnings is a convenience argument to enable all compiler warnings. """ args = list(flags) name = 't.c' if lang == 'cpp': name = 't.cpp' args.append('-std=c++11') elif lang == 'objc': name = 't.m' elif lang != 'c': raise Exception('Unknown language: %s' % lang) if all_warnings: args += ['-Wall', '-Wextra'] return TranslationUnit.from_source(name, args, unsaved_files=[(name, source)])def generate_m_file(file_text, result_lines, ret_functions)://略if __name__ == '__main__': libclangPath = '/Library/Developer/CommandLineTools/usr/lib/libclang.dylib' Config.set_library_file(libclangPath) # Find all .h files source_dir = sys.argv[1] g = os.walk(source_dir) h_files = [] ret_functions = [] for path,dir_list,file_list in g: for file_name in file_list: h_files.append(os.path.join(path, file_name)) for f in h_files: with open(f, 'r') as file: # preprocess regex = r'#import|#include|#ifdef|#ifndef|#define|#endif|@property' text = '' result_text_lines = [] line_count = 0 def