不想麻煩自己編譯的直接用這個(gè)成品
https://github.com/KomiMoe/Arkari 下載地址
源碼部分
網(wǎng)上的教程還是很多的 ,這里記錄一下自己的編譯之路
llvm源碼
用到的ollvm源碼目前感覺還不錯(cuò)的主要是以下三個(gè)
- https://github.com/heroims/obfuscator
- https://github.com/GoSSIP-SJTU/Armariris
- https://github.com/amimo/goron
- https://github.com/0x3f97/ollvm-12.x
- https://github.com/bluesadi/Pluto-Obfuscator
插件so
https://github.com/SsageParuders/SsagePass/tree/master
這里我用到的是第一個(gè) heroims-ollvm
NDK版本:21.1.6352462
CMake版本:3.10.2.4988404
heroims-ollvm:https://github.com/heroims/obfuscator/tree/llvm-9.0.1
首先還是下載源碼
git clone -b llvm-9.0.1 https://github.com/heroims/obfuscator.git
再或者直接 download 都行
編譯源碼
windows下的編譯就以下兩條路
使用CMake生成 Visual Studio工程 或是 MinGW Makefiles
使用mingw進(jìn)行編譯 需要使用版本8.1窿春,若使用6.x 必報(bào)錯(cuò)
建議 Visual Studio 進(jìn)行編譯 https://github.com/heroims 12+以上的ollvm
12+ 以上的源碼 獨(dú)立拆開了 clang
參見:https://llvm.org/docs/GettingStarted.html
在12 以前 clang 作為 tools 放在 llvm 中
在12 以后是獨(dú)立作為 plugin
// 生成 Visual Studio 工程
cmake -G "Visual Studio 16 2019" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release ../llvm
cmake -DLLVM_ENABLE_PROJECTS="clang;libcxx" -G "Visual Studio 16 2019" -A x64 -Thost=x64 -DCMAKE_BUILD_TYPE=Release ..\llvm
// 生成 Ninja 工程 (速度是真的比其他兩個(gè)快很多)
cmake -G "Ninja" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DBUILD_SHARED_LIBS=OFF ../llvm
// 生成 MinGW Makefiles
cmake -G "MinGW Makefiles" -DLLVM_ENABLE_PROJECTS="clang" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../llvm
// mingw編譯
cmake --build .
編譯完成后谷羞,從 obfuscator-llvm-9.0.1\build\lib\clang\9.0.1\include 復(fù)制
stdarg.h
stddef.h
__stddef_max_align_t.h
float.h
到 21.1.6352462\toolchains\llvm\prebuilt\windows-x86_64\sysroot\usr\include 即可
對(duì)應(yīng)替換bin目錄下的對(duì)應(yīng)的 三個(gè) exe
clang.exe
clang++.exe
clang-format.exe
注意事項(xiàng)
- 編譯不成功 : versionhelpers.h : not such file or directory
cmake加個(gè)參數(shù):-DLLVM_INCLUDE_BENCHMARKS=OFF 或者修改cmakelists.txt中的LLVM_INCLUDE_BENCHMARKS ON 改成OFF - 編譯90%退出
... z3/bin/libz3.lib: error adding symbols: File format not recognized
collect2.exe: error: ld returned 1 exit status
安裝一個(gè)z3 特石,和你平臺(tái)對(duì)應(yīng)莺债,32位還是64位
OLLVM 的使用
-
Instructions Substitution (指令替換)
- -mllvm -sub: 啟用instructions substitution
- -mllvm -sub_loop=3: 對(duì)每個(gè)函數(shù)混淆3次槐雾,默認(rèn)1詞
-
Control Flow Flattening (控制流平坦化)
- -mllvm -fla: 啟用control flow flattening
- -mllvm -split: 啟用block切分砌们,提升平展程度
- -mllvm -split_num=3: 對(duì)每個(gè)block混淆3次赤嚼,默認(rèn)1詞
-
Bogus Control Flow (虛假控制流)
- -mllvm -bcf: 啟用 bogus control flow
- -mllvm -bcf_loop=3: 對(duì)一個(gè)函數(shù)混淆3次,默認(rèn)1次
- -mllvm -bcf_prob=40: 代碼塊被混淆的概率是40%辅髓,默認(rèn)30%
-mllvm -sobf: 字符串加密
函數(shù)注解的使用
//Functions annotations
int foo() __attribute((annotate(("sub"))));
int foo() {
return 2;
}
CMakeLists.txt
#debug and release all enable
set(CMAKE_CXX_FLAGS "-mllvm -fla -mllvm -sub -mllvm -sobf ")
#so體積優(yōu)化
#SET(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
#SET(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -Os -Wall -s")
#設(shè)置llvm debug模式混淆編譯
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mllvm -fla")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mllvm -fla")
#設(shè)置llvm release模式混淆編譯
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mllvm -fla -mllvm -sub -mllvm -bcf")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mllvm -fla -mllvm -sub -mllvm -bcf")
#set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -s -O3 -Wall -fvisibility=hidden -mllvm -fla")
參考
https://sourceforge.net/projects/mingw-w64/files/mingw-w64/
ps:若在編譯的成品 clang 運(yùn)行出現(xiàn)了一下情況泣崩,請(qǐng)使用 vs studio 重新編譯(不要使用mingw32-make)
NDK版本對(duì)應(yīng)的clang版本
版本:21.1.6352462
Android (6317467 based on r365631c1) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project e0caee08e5f09b374a27a676d04978c81fcb1928) (based on LLVM 9.0.8svn)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:21.2.6472646
Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:21.3.6528147
Android (6454773 based on r365631c2) clang version 9.0.8 (https://android.googlesource.com/toolchain/llvm-project 98c855489587874b2a325e7a516b99d838599c6f) (based on LLVM 9.0.8svn)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:21.4.7075529
Android (7019983 based on r365631c3) clang version 9.0.9 (https://android.googlesource.com/toolchain/llvm-project a2a1e703c0edb03ba29944e529ccbf457742737b) (based on LLVM 9.0.9svn)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:22.0.7026061
Android (6875598, based on r399163b) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:22.1.7171670
Android (7155654, based on r399163b1) clang version 11.0.5 (https://android.googlesource.com/toolchain/llvm-project 87f1315dfbea7c137aa2e6d362dbb457e388158d)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:23.0.7599858
Android (7284624, based on r416183b) clang version 12.0.5 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:23.1.7779620
Android (7714059, based on r416183c1) clang version 12.0.8 (https://android.googlesource.com/toolchain/llvm-project c935d99d7cf2016289302412d708641d52d2f7ee)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:24.0.8215888
Android (8075178, based on r437112b) clang version 14.0.1 (https://android.googlesource.com/toolchain/llvm-project 8671348b81b95fc603505dfc881b45103bee1731)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:25.1.8937393
Android (8490178, based on r450784d) clang version 14.0.6 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6)
Target: x86_64-w64-windows-gnu
Thread model: posix
------------------------------------------------------------------------------------
版本:25.2.9519653
Android (9352603, based on r450784d1) clang version 14.0.7 (https://android.googlesource.com/toolchain/llvm-project 4c603efb0cca074e9238af8b4106c30add4418f6)
Target: x86_64-w64-windows-gnu
Thread model: posix