前言:
純粹為了學習,所以引用了很多人的資料,不是為了指導他人,只是記錄這段時間的學習成果
一: 開發pass 前的準備
1: 獲取LLVM源碼
git clone [http://llvm.org/git/llvm.git](http://llvm.org/git/llvm.git)
git clone [http://llvm.org/git/clang.git](http://llvm.org/git/clang.git) llvm/tools/clang
git clone [http://llvm.org/git/clang-tools-extra.git](http://llvm.org/git/clang-tools-extra.git) llvm/tools/clang/tools/extra
git clone [http://llvm.org/git/compiler-rt.git](http://llvm.org/git/compiler-rt.git) llvm/projects/compiler-rt
或者也可以獲取Ollvm 的源碼
https://github.com/obfuscator-llvm/obfuscator
其他的還有交大維護的孤挺花(Armariris)項目
clone git@github.com:gossip-sjtu/Armariris.git
最好的選擇是張總的Hikari 項目
https://github.com/HikariObfuscator/Hikari/releases
2:編譯成xcode項目
mkdir build
cd build
// 使用編譯器cmake 創建xcode 項目,項目地址在llvm目錄下
cmake -G Xcode CMAKE_BUILD_TYPE="Debug" ../llvm
open LLVM.xcodeproj
其中ollvm的編譯流程
mkdir obf
cd obf
clone [git@github.com](mailto:git@github.com):gossip-sjtu/Armariris.git
cmake -DCMAKE_BUILD_TYPE:String=Release ./Armariris
make -j4
3: pass 中結構劃分
在LLVM中
Module: 程序的基本單位是模塊(Module),比如一個.c或.cpp文件
Function: 函數是模塊的基本組成單位,代表文件中的一個函數,所以一個Module由一個或多個函數組成。
BasicBlock: 函數的基本組成單位 (每個函數會被劃分為一些block,它的劃分標準是:
一個block只有一個入口和一個出口所以一個Function由一個或多個Basic Block組成)
Instructions: 指令是Basic Block的基本組成單位,所以一個Basic Block由一個或多個Instructions組成
二: 開發流程
1 我們需要繼承指定的pass
比如:
struct functionObfuscation : public FunctionPass
2 實現其中的方法
virtual bool runOnFunction(Function &F)
3 需要將我們自己寫的pass 注冊
static RegisterPass<functionObfuscation> X(“funcobf", "Hello World Pass");
4 編譯我們自己的pass稱為動態庫
opt -load path/to/LLVMPassDemo.dylib -funcobf -time-passes -disable-output test.bc
其中動態庫就是存放編譯后我們寫的pass, funcobf選項就是指運行functionObfuscation這個pass