基于开源 Obfuscator-LLVM方案

下载安装最新版本 Obfuscator-LLVM,目前3.6.1

$ git clone -b llvm-3.6.1 https://github.com/obfuscator-llvm/obfuscator.git

$ mkdir build

$ cd build

$ cmake -DCMAKE_BUILD_TYPE:String=Release ../obfuscator/

$ make -j5

将build/bin加入环境变量

$vim ~/.bash_profile

export PATH=/Users/dream/ollvm/build/bin:$PATH

$source ~/.bash_profile

配置Xcode,当前版本 7.1

基于现有插件修改如下:

$ cd /Applications/Xcode-beta.app/Contents/PlugIns/Xcode3Core.ideplugin/Contents/SharedSupport/Developer/Library/Xcode/Plug-ins/

$ sudo cp -r Clang\ LLVM\ 1.0.xcplugin/ Obfuscator.xcplugin

$ cd Obfuscator.xcplugin/Contents/

$ sudo plutil -convert xml1 Info.plist

$ sudo vim Info.plist

修改文件内容(修改前->修改后)

<string>com.apple.compilers.clang</string> -> <string>com.apple.compilers.obfuscator</string>

<string>Clang LLVM 1.0 Compiler Xcode Plug-in</string> -> <string>Obfuscator Xcode Plug-in</string>

接下来修改Info.plist

$ sudo plutil -convert binary1 Info.plist

$ cd Resources/

$ sudo mv Clang\ LLVM\ 1.0.xcspec Obfuscator.xcspec

$ sudo vim Obfuscator.xcspec

修改为:

Identifier = "com.apple.compilers.llvm.clang.1_0"; -> Identifier = "com.apple.compilers.llvm.obfuscator.3_6_1";

Name = "Apple LLVM 7.0"; -> Name = "Obfuscator 3.6.1";

Description = "Apple LLVM 7.0 compiler"; -> Description = "Obfuscator 3.6.1";

Vendor = Apple; -> Vendor = HEIG-VD;

Version = "7.0"; -> Version = "3.6.1";

ExecPath = "clang"; -> ExecPath = "/Users/dream/ollvm/build/bin/clang";

接下来修改显示:

$ cd English.lproj/

$ sudo mv Apple\ LLVM\ 7.0.strings "Obfuscator 3.6.1.strings"

$ sudo vim Obfuscator\ 3.6.1.strings

修改为:

"Name" = "Apple LLVM 7.0"; -> "Name" = "Obfuscator 3.6.1";

"Description" = "Apple LLVM 7.0 Compiler"; -> "Description" = "Obfuscator 3.6.1";

"Version" = "7.0"; -> "Version" = "3.6.1";

"Vendor" = "Apple"; -> "Vendor" = "HEIG-VD";

重启Xcode,Build Options里面,可以设置Compiler for C/C++/Objective-C为Obfuscator 3.6.1, 在CustomFlags中自行添加 flag:

-mllvm -sub -mllvm -fla -mllvm -bcf

解决几个问题

编译时出错,提示信息如下:

clang-3.6: error: unknown argument: '-gmodules'

clang-3.6: error: unknown argument: '-fembed-bitcode-marker'

Command /Users/dream/ollvm/build/bin/clang failed with exit code 1

在 Build Settings中搜索并修改:

-gmodules: Obfuscator 3.6.1 - Code Generation: Generate Debug Symbols: 原来yes,改成no

-fembed-bitcode-marker: Build Option: Enable Bitcode: 原来yes,改成no

补充

---

2016年10月28日18:56:14

目前该方法兼容最新版xcode:8.0

04-16 17:01