安装环境:Ubuntu16.04
下载llvm obfuscator的源代码
git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git
wget https://github.com/GoSSIP-SJTU/Armariris/blob/master/lib/Transforms/Obfuscation/StringObfuscation.cpp
另外,把https://github.com/GoSSIP-SJTU/Armariris中include/llvm/Transforms/Obfuscation/下的StringObfuscation.h拷贝到/obfuscator/include/llvm/Transforms/Obfuscation中,当然,也可以进入到/obfuscator/include/llvm/Transforms/Obfuscation,使用下面的命令:
wget https://github.com/GoSSIP-SJTU/Armariris/blob/master/lib/Transforms/Obfuscation/StringObfuscation.cpp
修改lib/Transform/Obfuscation目录下的CMakeLists.txt文件,将StringObfuscation.cpp添加到编译库中。使用vim添加文件名称即可。
进入到obfuscator/lib/Transforms/IPO下面,编辑PassManagerBuilder.cpp,将StringObfuscation.h写入到其中:
#include "llvm/Transforms/Obfuscation/StringObfuscation.h"
同时,插入命令行调用的参数声明-mllvm -sobf:
static cl::opt<std::string> Seed("seed", cl::init(""),
cl::desc("seed for the random"));
static cl::opt<bool> StringObf("sobf", cl::init(false),
cl::desc("Enable the string obfuscation"));
在PassManagerBuilder()构造函数中添加随机数因子的初始化:
if(!Seed.empty()) {
llvm::cryptoutils->prng_seed(Seed.c_str());
}
添加pss到 PassManagerBuilder::populateModulePassManager中 :
MPM.add(createStringObfuscation(StringObf));
进入源码目录下创建build目录:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ../
在编译过程中,出现如下错误:
CMake Error at cmake/modules/AddLLVM.cmake:1163 (add_custom_target):
add_custom_target cannot create target "check-llvm-bindings-ocaml" because
another target with the same name already exists. The existing target is a
custom target created in source directory
"/home/flow/compiler/obfuscator/test". See documentation for policy
CMP0002 for more details.
那么,使用下面的命令行来解决该问题:
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../
make -j16