首页
社区
课程
招聘
3
[原创] NDK集成最新版Pluto
发表于: 2025-3-31 09:00 1135

[原创] NDK集成最新版Pluto

2025-3-31 09:00
1135

相信Pluto项目的z3导入问题一定挡住了很多想为NDK集成Pluto的人

Ubuntu版本 22.04.5 ndk版本 r25c

安装编译所需环境

1
sudo apt install -y vim git build-essential clang clangd bison flex libz3-dev rsync python3 python-is-python3 python3-pip unzip cmake ninja-build

按照这篇文章里的步骤把r25c的repo sync下来 https://bbs.kanxue.com/thread-271271.htm
编译

1
python toolchain/llvm_android/build.py --no-build windows,lldb --skip-tests

复制Pluto的整个 llvm/lib/Transforms/Obfuscation/ 目录 和 llvm/include/Transforms/Obfuscation/目录到源码中

修改 llvm/lib/Transforms/Obfuscation/CMakeLists.txt
下载z3的linux预编译包,把so加入链接,配置include_path,一定要绝对路径

# Set custom Z3 paths
set(Z3_INCLUDE_DIR "/home/xxx/ndk_obfu/z3/z3-4.14.0-x64-glibc-2.35/include")
set(Z3_LIBRARIES "/home/xxx/ndk_obfu/z3/z3-4.14.0-x64-glibc-2.35/bin/libz3.so")

# Include Z3 headers
include_directories(${Z3_INCLUDE_DIR})

add_llvm_component_library(LLVMObfuscation
  HelloWorld.cpp
  CryptoUtils.cpp
  Flattening.cpp
  MBAUtils.cpp
  MBAObfuscation.cpp
  Substitution.cpp
  IndirectCall.cpp
  BogusControlFlow.cpp
  GlobalEncryption.cpp
  Pipeline.cpp

  LINK_COMPONENTS
  Core
  Support
  Analysis
  TransformUtils
  
  LINK_LIBS
  ${Z3_LIBRARIES}
  )

llvm/lib/Transforms/IPO/CMakeLists.txt 添加内容

1
2
3
4
5
6
7
llvm/lib/Transforms/IPO/CMakeLists.txt
@@ -73,4 +73,5 @@ add_llvm_component_library(LLVMipo
   Vectorize
   Instrumentation
   Scalar
+  Obfuscation
   )

llvm/lib/Transforms/CMakeLists.txt 添加内容

1
2
3
4
5
6
llvm/lib/Transforms/CMakeLists.txt
@@ -9,3 +9,4 @@ add_subdirectory(Hello)
 add_subdirectory(ObjCARC)
 add_subdirectory(Coroutines)
 add_subdirectory(CFGuard)
+add_subdirectory(Obfuscation)

llvm/lib/Passes/PassBuilderPipelines.cpp 添加内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -126,6 +126,7 @@
 #include "llvm/Transforms/Vectorize/LoopVectorize.h"
 #include "llvm/Transforms/Vectorize/SLPVectorizer.h"
 #include "llvm/Transforms/Vectorize/VectorCombine.h"
+#include "llvm/Transforms/Obfuscation/Pipeline.h"
  
 using namespace llvm;
  
@@ -1278,6 +1279,8 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   // Now add the optimization pipeline.
   MPM.addPass(buildModuleOptimizationPipeline(Level, LTOPreLink));
  
+  MPM.addPass(buildObfuscationPipeline());
+
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
       PGOOpt->Action == PGOOptions::SampleUse)
     MPM.addPass(PseudoProbeUpdatePass());
@@ -1777,6 +1780,8 @@ ModulePassManager PassBuilder::buildO0DefaultPipeline(OptimizationLevel Level,
   MPM.addPass(createModuleToPostOrderCGSCCPassAdaptor(std::move(CGPM)));
   MPM.addPass(createModuleToFunctionPassAdaptor(CoroCleanupPass()));
  
+  MPM.addPass(buildObfuscationPipeline());
+
   for (auto &C : OptimizerLastEPCallbacks)
     C(MPM, Level);

llvm/lib/LTO/LTOBackend.cpp 添加内容

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/llvm/lib/LTO/LTOBackend.cpp b/llvm/lib/LTO/LTOBackend.cpp
index 7694c9848384..c6b658c01a97 100644
--- a/llvm/lib/LTO/LTOBackend.cpp
+++ b/llvm/lib/LTO/LTOBackend.cpp
@@ -45,6 +45,7 @@
 #include "llvm/Transforms/Scalar/LoopPassManager.h"
 #include "llvm/Transforms/Utils/FunctionImportUtils.h"
 #include "llvm/Transforms/Utils/SplitModule.h"
+#include "llvm/Transforms/Obfuscation/Pipeline.h"
  
 using namespace llvm;
 using namespace lto;
@@ -306,6 +307,7 @@ static void runNewPMPasses(const Config &Conf, Module &Mod, TargetMachine *TM,
   if (!Conf.DisableVerify)
     MPM.addPass(VerifierPass());
  
+  MPM.addPass(buildLTOObfuscationPipeline());
   MPM.run(Mod, MAM);
 }

打开 toolchain/llvm_android/do_build.py,注释874-882行(删除test流程)

再次编译

1
python toolchain/llvm_android/build.py --no-build windows,lldb --skip-tests

编译完成后打包 out/install/linux-x86/clang-dev
复制并替换原来ndk中的bin目录

1
cp -rf ~/ndk_obfu/clang-dev/bin/* ~/ndk_obfu/android-ndk-r25c/toolchains/llvm/prebuilt/linux-x86_64/bin/

编译测试,输出如下代表成功

图片描述


[注意]看雪招聘,专注安全领域的专业人才平台!

收藏
免费 3
支持
分享
赞赏记录
参与人
雪币
留言
时间
mb_powghrzn
谢谢你的细致分析,受益匪浅!
2025-4-5 07:49
mb_ygbywaup
这个讨论对我很有帮助,谢谢!
2025-3-31 16:24
你瞒我瞒
感谢你的贡献,论坛因你而更加精彩!
2025-3-31 09:13
最新回复 (0)
游客
登录 | 注册 方可回帖
返回

账号登录
验证码登录

忘记密码?
没有账号?立即免费注册