文档自定义规则
自定义规则
预计阅读时间:10 分钟
概述
自定义规则允许您精确控制混淆行为,包括自定义混淆前缀、命名规则、 正则表达式匹配等,满足复杂项目的特殊需求。
混淆前缀配置
自定义混淆后标识符的前缀:
{
"prefix": {
"class": "CF_", // 类名前缀
"method": "cf_", // 方法名前缀
"property": "cf_", // 属性前缀
"protocol": "CFP_" // 协议前缀
}
}效果:
UserManager→CF_8xK9m命名规则
随机字符模式
使用随机字母数字组合
"nameStyle": "random" // 结果: ZFJ_8xK9mN字典模式
使用预定义的单词组合
"nameStyle": "dictionary" // 结果: ZFJ_AppleTree哈希模式
基于原名称生成哈希值
"nameStyle": "hash" // 结果: ZFJ_a1b2c3d4正则表达式规则
使用正则表达式批量匹配需要混淆或排除的内容:
{
"rules": {
"include": [
"^My.*", // 混淆所有 My 开头的类
".*Manager$", // 混淆所有 Manager 结尾的类
"^(get|set).*" // 混淆 get/set 开头的方法
],
"exclude": [
".*Model$", // 排除 Model 结尾的类
".*Delegate$", // 排除 Delegate 结尾的类
"^init.*" // 排除 init 开头的方法
]
}
}完整配置示例
{
"version": "1.0",
"prefix": {
"class": "CF_",
"method": "cf_",
"property": "cf_"
},
"nameStyle": "random",
"randomLength": 6,
"obfuscation": {
"class": true,
"method": true,
"property": true,
"protocol": true
},
"rules": {
"include": ["^My.*", ".*Service$"],
"exclude": [".*Model$", ".*Entity$"]
},
"whitelist": {
"classes": ["AppDelegate"],
"methods": ["viewDidLoad"],
"prefixes": ["UI", "NS", "AF", "SD"]
}
}使用自定义规则文件
1
创建配置文件
在项目根目录创建 codefog.config.json
2
编写规则
按照上述格式编写自定义规则
3
导入配置
在 CodeFog 中选择 文件 → 导入配置