美文网首页
关于LLVM pass 的学习(1)-- 开发准备

关于LLVM pass 的学习(1)-- 开发准备

作者: ldzSpace | 来源:发表于2018-11-01 17:15 被阅读0次

前言:

纯粹为了学习,所以引用了很多人的资料,不是为了指导他人,只是记录这段时间的学习成果

一: 开发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

相关文章

网友评论

      本文标题:关于LLVM pass 的学习(1)-- 开发准备

      本文链接:https://www.haomeiwen.com/subject/mnbxxqtx.html