鸿蒙HAR混淆

📅 2026/7/8 5:58:43
鸿蒙HAR混淆
参考文档中心# Define project specific obfuscation rules here. # You can include the obfuscation configuration files in the current modules build-profile.json5. # # For more details, see # https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/source-obfuscation-V5 # Obfuscation options: # -disable-obfuscation: disable all obfuscations # -enable-property-obfuscation: obfuscate the property names # -enable-toplevel-obfuscation: obfuscate the names in the global scope # -compact: remove unnecessary blank spaces and all line feeds # -remove-log: remove all console.* statements # -print-namecache: print the name cache that contains the mapping from the old names to new names # -apply-namecache: reuse the given cache file # Keep options: # -keep-property-name: specifies property names that you want to keep # -keep-global-name: specifies names that you want to keep in the global scope # 启用属性混淆这代码中的属性名称将被替换为混淆后的名称 -enable-property-obfuscation # 启用顶层混淆这将混淆代码中的所有顶层元素包括类、函数和变量名称。 -enable-toplevel-obfuscation # 启用文件名混淆这将混淆源代码文件中的文件名以增加代码的隐私性。 -enable-filename-obfuscation # 启用导出混淆这将混淆代码中的导出元素如函数和类以防止未授权的访问。 -enable-export-obfuscation # 删除编译生成的声明文件中的JsDoc注释 -remove-comments # 允许在源码中使用 // KeepAsConsumer 和 // KeepSymbol 注解 -use-keep-in-source # 允许将源码中的注解白名单同步应用到编译生成的对外 .d.ts 声明文件中 源码里的白名单规则能不能对最终生成的 .d.ts 文件生效 -keep-dts # 这个只能保留文件的名称文件内部的方法名和字段名称还是被混淆的 # 不支持路径写法只支持名称或名称通配符 -keep-file-name ./src/main/ets/xxxSDK.ets ./src/main/ets/pay/xxxPaySDK.ets ./src/main/ets/iface/IUserData ./src/main/ets/pay/listener/IPayListener #对外导出 ./Index.ets #-keep # 保留该文件夹内所有类名、属性名等需与keep-file-name同时配置 # 该方法支持通配例如./src/main/ets/iface/ # 但是该方法会导致所有关联引用的文件全部被 keep keep传递所以此处不用使用 // KeepAsConsumer 注解来替代 # KeepSymbol 只管“保护自己”而 KeepAsConsumer 还能“传给别人”自动生成到 obfuscation.txt 中并传给下游 # KeepAsConsumer 会自动获取需要保护的名称注入到 obfuscation.txt 文件夹 # 需要保留有效的变量不然json序列化中字段会变成 f5 # for getRegisterRequestInfo() -keep-property-name thirdDeviceId systemVersion appName appVersion deviceModel manufacturer -keep-global-name xxxSDK xxxPaySDKhar 有个不一样的就是 不使用 -keep 因为 keep 会传递导致引用到的文件都被keep最终效果就是几乎所有的文件都keep 住。所以使用 KeepAsConsumer 来指定保护的文件。但是这个只能保护文件内部的内容所以还需要配合 -keep-file-name使用KeepAsConsumer 需要先打开-use-keep-in-source -keep-dts