整合 ollvm 进入项目

ollvm 的项目我再这里就不做介绍了。整合进入项目的不过两种:一种是 Theos,另外一种是 Xcode。

不过值得注意的是 ollvm 主要有效的还是 c 的函数,对 OC 对抗效果不明显。对抗分析的问题,请参考半仙的《软件反分析》。

Theos 整合

Theos 主要依赖于 Makefile,因此需要 Makefile 文件来实现功能了。首先在文件里添加:

TARGET_CC = path_to_clang/clang
TARGET_CXX = path_to_clang/clang++
TARGET_LD = path_to_clang/clang++

然后修改 (项目名)_CFLAGS 参数,如果没有则添加:

xxx_CFLAGS = -fobjc-arc -mllvm -fla

这样就可以在项目中应用 ollvm 了。

Xcode 整合

集成进入 Xcode 需要修改几个文件,根据现有的插件进行修改。

具体修改步骤如下:

$ cd /Applications/Xcode.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_4";
Name = "Apple LLVM 5.1"; -> Name = "Obfuscator 3.4";
Description = "Apple LLVM 5.1 compiler"; -> Description = "Obfuscator 3.4";
Vendor = Apple; -> Vendor = HEIG-VD;
Version = "5.0"; -> Version = "3.4";
ExecPath = "clang"; -> ExecPath = "/path/to/obfuscator_bin/clang";

接下来修改显示:

$ cd English.lproj/
$ sudo mv Apple\ LLVM\ 5.1.strings "Obfuscator 3.4.strings"
$ sudo vim Obfuscator\ 3.4.strings

修改为:

"Name" = "Apple LLVM 5.0"; -> "Name" = "Obfuscator 3.4";
"Description" = "Apple LLVM 5.0 Compiler"; -> "Description" = "Obfuscator 3.4";
"Version" = "5.0"; -> "Version" = "3.4";
"Vendor" = "Apple"; -> "Vendor" = "HEIG-VD";

重启一下你的 Xcode,然后再 Build Options 里面,可以设置 Compiler for C/C++/Objective-C 为 Obfuscator 3.4。

如果想要添加 cflag,可以在 CustomFlags 中自行添加。

目前的问题

如果你用起来,现在 ARM64 解决还有问题,我正在研究,如果你知道如何解决,欢迎指出。

➜  xxx  make
Making all for tweak xxx...
 Preprocessing xxx.x...
 Compiling xxx.x...
clang-3.4: error: invalid arch name '-arch arm64'
make[2]: *** [xxx.x.585e736e.o] Error 1
make[1]: *** [internal-library-all_] Error 2
make: *** [xxx.all.tweak.variables] Error 2
Built with Hugo
主题 StackJimmy 设计