Skip to content

Commit

Permalink
移植 OLLVM 到 LLVM 18,C&C++代码混淆
Browse files Browse the repository at this point in the history
  • Loading branch information
CYRUS-STUDIO committed Dec 22, 2024
1 parent 3b37829 commit 748a2c7
Show file tree
Hide file tree
Showing 7 changed files with 154 additions and 39 deletions.
69 changes: 68 additions & 1 deletion content/posts/移植 OLLVM 到 LLVM 18,C&C++代码混淆.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
+++
title = '移植 OLLVM 到 LLVM 18,C&C++代码混淆'
date = 2024-12-13T03:56:00.307813+08:00
date = 2024-12-23T03:48:18.268921+08:00
draft = false
+++

Expand Down Expand Up @@ -310,6 +310,73 @@ NF->splice(NF->begin(), F)



### **5.4 error C2664: “llvm::AllocaInst llvm::DemoteRegToStack**



```
[193/2642] Building CXX object lib\Passes\CMakeFiles\LLVMPasses.dir\Obfuscation\Utils.cpp.obj
FAILED: lib/Passes/CMakeFiles/LLVMPasses.dir/Obfuscation/Utils.cpp.obj
D:\App\VisualStudio\IDE\VC\Tools\MSVC\14.42.34433\bin\Hostx64\x64\cl.exe /nologo /TP -DUNICODE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_NONSTDC_NO_WARNINGS -D_CRT_SECURE_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_DEPRECATE -D_SCL_SECURE_NO_WARNINGS -D_UNICODE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -ID:\Projects\llvm-project\build\lib\Passes -ID:\Projects\llvm-project\llvm\lib\Passes -ID:\Projects\llvm-project\build\include -ID:\Projects\llvm-project\llvm\include /utf-8 /Zc:inline /Zc:preprocessor /Zc:__cplusplus /Oi /bigobj /permissive- /W4 -wd4141 -wd4146 -wd4244 -wd4267 -wd4291 -wd4351 -wd4456 -wd4457 -wd4458 -wd4459 -wd4503 -wd4624 -wd4722 -wd4100 -wd4127 -wd4512 -wd4505 -wd4610 -wd4510 -wd4702 -wd4245 -wd4706 -wd4310 -wd4701 -wd4703 -wd4389 -wd4611 -wd4805 -wd4204 -wd4577 -wd4091 -wd4592 -wd4319 -wd4709 -wd5105 -wd4324 -w14062 -we4238 /Gw /O2 /Ob2 /DNDEBUG -std:c++17 -MD /EHsc /GR /showIncludes /Folib\Passes\CMakeFiles\LLVMPasses.dir\Obfuscation\Utils.cpp.obj /Fdlib\Passes\CMakeFiles\LLVMPasses.dir\LLVMPasses.pdb /FS -c D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(213): error C2664: “llvm::AllocaInst *llvm::DemoteRegToStack(llvm::Instruction &,bool,llvm::Instruction *)”: 无法将参数 3 从“llvm::ilist_iterator_w_bits<OptionsT,false,false>”转换为“llvm::Instruction *”
with
[
OptionsT=llvm::ilist_detail::node_options<llvm::Instruction,false,false,llvm::ilist_detail::extract_tag<>::type,true>
]
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(213): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
D:\Projects\llvm-project\llvm\include\llvm/Transforms/Utils/Local.h(207): note: 参见“llvm::DemoteRegToStack”的声明
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(213): note: 尝试匹配参数列表“(llvm::Instruction, bool, llvm::ilist_iterator_w_bits<OptionsT,false,false>)” 时
with
[
OptionsT=llvm::ilist_detail::node_options<llvm::Instruction,false,false,llvm::ilist_detail::extract_tag<>::type,true>
]
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(225): error C2664: “llvm::AllocaInst *llvm::DemotePHIToStack(llvm::PHINode *,llvm::Instruction *)”: 无法将 参数 2 从“llvm::ilist_iterator_w_bits<OptionsT,false,false>”转换为“llvm::Instruction *”
with
[
OptionsT=llvm::ilist_detail::node_options<llvm::Instruction,false,false,llvm::ilist_detail::extract_tag<>::type,true>
]
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(225): note: 没有可用于执行该转换的用户定义的转换运算符,或者无法调用该运算符
D:\Projects\llvm-project\llvm\include\llvm/Transforms/Utils/Local.h(214): note: 参见“llvm::DemotePHIToStack”的声明
D:\Projects\llvm-project\llvm\lib\Passes\Obfuscation\Utils.cpp(225): note: 尝试匹配参数列表“(llvm::PHINode *, llvm::ilist_iterator_w_bits<OptionsT,false,false>)”时
with
[
OptionsT=llvm::ilist_detail::node_options<llvm::Instruction,false,false,llvm::ilist_detail::extract_tag<>::type,true>
]
```
DemoteRegToStack 函数调用:在LLVM 18.1.8中,DemoteRegToStack 的参数包括:

- 需要转为栈变量的 Instruction。

- 一个布尔值表示是否添加调试信息。

- 一个插入点指针,指定插入位置。




```
DemoteRegToStack(*I, false, AllocaInsertionPoint->getIterator());
```
改为

```
DemoteRegToStack(*Inst, false, AllocaInsertionPoint); // 修复函数调用
```



```
DemotePHIToStack(cast<PHINode>(I), AllocaInsertionPoint->getIterator());
```
改为

```
DemotePHIToStack(cast<PHINode>(Inst), AllocaInsertionPoint); // 修复函数调用
```


## **6. 其他**


Expand Down
12 changes: 6 additions & 6 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,36 @@ <h1>CYRUS STUDIO</h1>
<ul class="posts-list">

<li class="posts-list-item">
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/">移植 OLLVM 到 LLVM18,修复控制流平坦化报错</a>
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/">移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</a>
<span class="posts-list-item-description">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-calendar">
<title>calendar</title>
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
Dec 21, 2024
Dec 23, 2024
<span class="posts-list-item-separator">-</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-clock">
<title>clock</title>
<circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline>
</svg>
3 min read
12 min read
</span>
</li>

<li class="posts-list-item">
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/">移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</a>
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/">移植 OLLVM 到 LLVM18,修复控制流平坦化报错</a>
<span class="posts-list-item-description">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-calendar">
<title>calendar</title>
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
Dec 13, 2024
Dec 21, 2024
<span class="posts-list-item-separator">-</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-clock">
<title>clock</title>
<circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline>
</svg>
11 min read
3 min read
</span>
</li>

Expand Down
16 changes: 8 additions & 8 deletions public/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,22 @@
<description>Recent content on CYRUS STUDIO</description>
<generator>Hugo</generator>
<language>zh-cn</language>
<lastBuildDate>Sat, 21 Dec 2024 23:02:07 +0800</lastBuildDate>
<lastBuildDate>Mon, 23 Dec 2024 03:48:18 +0800</lastBuildDate>
<atom:link href="https://cyrus-studio.github.io/blog/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</title>
<link>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/</link>
<pubDate>Mon, 23 Dec 2024 03:48:18 +0800</pubDate>
<guid>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/</guid>
<description>版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/&#xA;OLLVM 简介 OLLVM (Obfuscator-LLVM) 是一个基于 LLVM 的代码混淆工具。&#xA;LLVM 是一个广泛使用的编译器框架,OLLVM 在其基础上提供了多种混淆技术,旨在增加程序逆向分析和反编译的难度,从而提高程序的安全性。&#xA;OLLVM 通过在编译过程中对中间表示(IR)和目标代码应用多种混淆技术,生成更加复杂和难以理解的二进制代码。&#xA;OLLVM 项目地址:https://github.com/obfuscator-llvm/obfuscator&#xA;下载源码 目前最新版本的是分支名为 llvm-4.0,基于 LLVM 团队发布的版本 4.0.1&#xA;最新版本的 LLVM 可以看这里:https://github.com/llvm/llvm-project/releases&#xA;下载 OLLVM 的 llvm-4.0 分支源码到本地&#xA;git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git 构建 OLLVM&#xA;mkdir build&#xD;cd build&#xD;cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/&#xD;make -j7 OLLVM 项目介绍 obfuscator/&#xD;│&#xD;├── include/llvm/Transforms/Obfuscation # 公共头文件目录&#xD;│ ├── BogusControlFlow.h # 虚假控制流头文件&#xD;│ ├── Flattening.h # 控制流平坦化头文件&#xD;│ ├── Split.h # 基本块拆分头文件&#xD;│ ├── Substitution.</description>
</item>
<item>
<title>移植 OLLVM 到 LLVM18,修复控制流平坦化报错</title>
<link>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/</link>
<pubDate>Sat, 21 Dec 2024 23:02:07 +0800</pubDate>
<guid>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/</guid>
<description>版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/&#xA;前言 把 OLLVM 移植到 LLVM18 后,发现 -fla(控制流平坦化)并不能正常使用。&#xA;关于移植过程可以参考这篇文章 【移植 OLLVM 到 LLVM 18,C&amp;amp;C++代码混淆】&#xA;测试代码 fla.c&#xA;#include &amp;lt;stdlib.h&amp;gt;&#xD;int main(int argc, char** argv) {&#xD;int a = atoi(argv[1]);&#xD;if(a == 0)&#xD;return 1;&#xD;else&#xD;return 10;&#xD;return 0;&#xD;} 使用 clang 编译并启用 Control Flow Flattening(控制流平坦化)报错如下:&#xA;D:\Projects\llvm-project\build&amp;gt;clang -mllvm -fla fla.c -o fla.exe&#xD;[OLLVM] run.PipelineStartEPCallback&#xD;PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.</description>
</item>
<item>
<title>移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</title>
<link>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/</link>
<pubDate>Fri, 13 Dec 2024 03:56:00 +0800</pubDate>
<guid>https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/</guid>
<description>版权归作者所有,如有转发,请注明文章出处:https://cyrus-studio.github.io/blog/&#xA;OLLVM 简介 OLLVM (Obfuscator-LLVM) 是一个基于 LLVM 的代码混淆工具。&#xA;LLVM 是一个广泛使用的编译器框架,OLLVM 在其基础上提供了多种混淆技术,旨在增加程序逆向分析和反编译的难度,从而提高程序的安全性。&#xA;OLLVM 通过在编译过程中对中间表示(IR)和目标代码应用多种混淆技术,生成更加复杂和难以理解的二进制代码。&#xA;OLLVM 项目地址:https://github.com/obfuscator-llvm/obfuscator&#xA;下载源码 目前最新版本的是分支名为 llvm-4.0,基于 LLVM 团队发布的版本 4.0.1&#xA;最新版本的 LLVM 可以看这里:https://github.com/llvm/llvm-project/releases&#xA;下载 OLLVM 的 llvm-4.0 分支源码到本地&#xA;git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git 构建 OLLVM&#xA;mkdir build&#xD;cd build&#xD;cmake -DCMAKE_BUILD_TYPE=Release ../obfuscator/&#xD;make -j7 OLLVM 项目介绍 obfuscator/&#xD;│&#xD;├── include/llvm/Transforms/Obfuscation # 公共头文件目录&#xD;│ ├── BogusControlFlow.h # 虚假控制流头文件&#xD;│ ├── Flattening.h # 控制流平坦化头文件&#xD;│ ├── Split.h # 基本块拆分头文件&#xD;│ ├── Substitution.</description>
</item>
<item>
<title>编译 LLVM 源码,使用 Clion 调试 clang</title>
<link>https://cyrus-studio.github.io/blog/posts/%E7%BC%96%E8%AF%91-llvm-%E6%BA%90%E7%A0%81%E4%BD%BF%E7%94%A8-clion-%E8%B0%83%E8%AF%95-clang/</link>
Expand Down
12 changes: 6 additions & 6 deletions public/posts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,36 +55,36 @@ <h1>Posts</h1>
<ul class="posts-list">

<li class="posts-list-item">
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/">移植 OLLVM 到 LLVM18,修复控制流平坦化报错</a>
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/">移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</a>
<span class="posts-list-item-description">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-calendar">
<title>calendar</title>
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
Dec 21, 2024
Dec 23, 2024
<span class="posts-list-item-separator">-</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-clock">
<title>clock</title>
<circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline>
</svg>
3 min read
12 min read
</span>
</li>

<li class="posts-list-item">
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm-18cc&#43;&#43;%E4%BB%A3%E7%A0%81%E6%B7%B7%E6%B7%86/">移植 OLLVM 到 LLVM 18,C&amp;C&#43;&#43;代码混淆</a>
<a class="posts-list-item-title" href="https://cyrus-studio.github.io/blog/posts/%E7%A7%BB%E6%A4%8D-ollvm-%E5%88%B0-llvm18%E4%BF%AE%E5%A4%8D%E6%8E%A7%E5%88%B6%E6%B5%81%E5%B9%B3%E5%9D%A6%E5%8C%96%E6%8A%A5%E9%94%99/">移植 OLLVM 到 LLVM18,修复控制流平坦化报错</a>
<span class="posts-list-item-description">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-calendar">
<title>calendar</title>
<rect x="3" y="4" width="18" height="18" rx="2" ry="2"></rect><line x1="16" y1="2" x2="16" y2="6"></line><line x1="8" y1="2" x2="8" y2="6"></line><line x1="3" y1="10" x2="21" y2="10"></line>
</svg>
Dec 13, 2024
Dec 21, 2024
<span class="posts-list-item-separator">-</span>
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="icon icon-clock">
<title>clock</title>
<circle cx="12" cy="12" r="10"></circle><polyline points="12 6 12 12 16 14"></polyline>
</svg>
11 min read
3 min read
</span>
</li>

Expand Down
Loading

0 comments on commit 748a2c7

Please sign in to comment.