安装使用llvm-obfuscator

安装环境:Ubuntu16.04

  1. 安装autoconf

下载llvm obfuscator的源代码

 git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git 
  1. 增加String Obfuscator功能模块
    进入到项目https://github.com/GoSSIP-SJTU/Armariris中,找到lib/Transforms/Obfuscation下面的StringObfuscation.cpp并拷贝到下载好的obfuscator相应的目录下面,当然,也可以进入到/obfuscator/lib/Transforms/Obfuscation,使用下面的命令:
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));
  1. 编译

进入源码目录下创建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
  1. 参考文献
    https://blog.csdn.net/marketandtechnology/article/details/81077082

猜你喜欢

转载自blog.csdn.net/vincentuva/article/details/82993563