OLLVM + NDK 混淆編譯環境搭建


Obfuscator-LLVM is a project initiated in June 2010 by the information security group of the University of Applied Sciences and Arts Western Switzerland of Yverdon-les-Bains (HEIG-VD).
The aim of this project is to provide an open-source fork of the LLVM compilation suite able to provide increased software security through code obfuscation and tamper-proofing. As we currently mostly work at the Intermediate Representation (IR) level, our tool is compatible with all programming languages (C, C++, Objective-C, Ada and Fortran) and target platforms (x86, x86-64, PowerPC, PowerPC-64, ARM, Thumb, SPARC, Alpha, CellSPU, MIPS, MSP430, SystemZ, and XCore) currently supported by LLVM.

0x01 環境信息 

系統環境:MacOS
系統版本:10.12.5
NDK版本:android-ndk-r14b

0x02 下載編譯 

github 上最新版本是4.0,可以直接 clone github 項目編譯,可參考提供的 wiki 文檔:  Installation
這裏編譯的時候需要 cmake 工具,可以通過 Homebrew 直接安裝。編譯成功後,生成的文檔在 build/bin 下

0x03 與 NDK 集成 

新建編譯鏈 

在 android-ndk-r14b/toolchains 下新建目錄 ollvm-4.0/prebuilt/darwin-x86_64,把前一步編譯生成的結果拷貝到此目錄下(主要是bin和lib)。
這裏最好直接複製 llvm 目錄,然後進行修改。手動創建的時候遇到過編譯失敗,直接複製修改就沒這種問題。

配置編譯鏈 

在 android-ndk-r14b/build/core/toolchains 目錄下,新建目錄 arm-linux-androideabi-clang-ollvm4.0,拷貝目錄 arm-linux-androideabi-clang 下的文檔 config.mk 與 setup.mk 到 arm-linux-androideabi-clang-ollvm4.0 中,修改setup.mk文檔。

config.mk 保存的是該編譯鏈對應的 CPU 架構,所以上面修改完只能編譯 armeabi 和 armeabi-v7a 架構的 so。如果需要編譯其他架構需要做相應的修改。文檔夾名也必須按照嚴格的格式,如 mips 的需要添加文檔夾:mipsel-linux-android-clang-ollvm4.0,修改相應的 setup.mk 文檔。

0x04 OLLVM 使用 

使用 ollvm 進行 ndk 的編譯需要對 Application.mk 和 Android.mk 文檔做相應的修改。
Android.mk 中添加混淆編譯參數:

參數相關的文檔可以看 github 上的wiki:  https://github.com/obfuscator-llvm/obfuscator/wiki
Application.mk 中配置 NDK_TOOLCHAIN_VERSION

评论

此博客中的热门博文

How to Build a Cocos2d-x Android App for Multiple Architectures

Android跨平台编译 —— libevent

开源 C++ 库列表