1. 编译 ollvm-9.0.1
下载源码进行编译
https://github.com/heroims/obfuscator/tree/llvm-9.0.1
编译
这里有坑要注意 不能使用最新的 mingw 8.0.1 编译会报错
报错内容如下:
PS D:\OLLVM\obfuscator-llvm-9.0.1\build> cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release ..\..\obfuscator-llvm-9.0.1\
CMake Deprecation Warning at CMakeLists.txt:3 (cmake_minimum_required):
Compatibility with CMake < 3.5 will be removed from a future version of
CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell
CMake that the project does not need compatibility with older versions.
CMake Error at CMakeLists.txt:49 (project):
The CMAKE_C_COMPILER:
C:/MinGW/bin/gcc.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:49 (project):
The CMAKE_CXX_COMPILER:
C:/MinGW/bin/c++.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
CMake Error at CMakeLists.txt:49 (project):
The CMAKE_ASM_COMPILER:
C:/MinGW/bin/gcc.exe
is not a full path to an existing compiler tool.
Tell CMake where to find the compiler by setting either the environment
variable "ASM" or the CMake cache entry CMAKE_ASM_COMPILER to the full path
to the compiler, or to the compiler name if it is in the PATH.
-- Configuring incomplete, errors occurred!
猜测可能的原因是 cmake版本和 mingw版本 对ollvm-9.0.1的cmakelists.txt的兼容性问题引起的
然后我重新下载mingw旧版本 我用的是 x86_64-5.4.0-release-posix-seh-rt_v5-rev0
mingw下载地址
编译命令
解压下载文件 后 进入解压文件目录
mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../../obfuscator-llvm-9.0.1
cmake --build .
配置Android NDK
下载 NDK 21.4.7075529
将编译内容复制到 下载的NDK21指定目录下
- 复制一份下载好的ndk 命名为21.4.7075529Ollvm9.0.1
- 复制 编译后的ollvm目录下的 obfuscator-llvm-9.0.1\build\bin 的clang.exe clang++.exe clang-format.exe 到21.4.7075529Ollvm9.0.1\toolchains\llvm\prebuilt\windows-x86_64/bin 目录下的
3.复制 /build/lib/clang/9.0.1/include下面 stdarg.h 、stddef.h 、__stddef_max_align_t.h 、float.h 这四个文件复制到
复制到 AndroidStudio使用的NDK目录 /toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include 文件夹下
在CMakeLists.txt中修改如下
#设置llvm debug模式混淆编译
SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mllvm -fla -mllvm -sobf")
SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mllvm -fla -mllvm -sobf")
#设置llvm release模式混淆编译
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mllvm -fla -mllvm -sub -mllvm -bcf -mllvm -sobf")
SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mllvm -fla -mllvm -sub -mllvm -bcf -mllvm -sobf")
单个函数混淆
__attribute((__annotate__("bcf")))
__attribute((__annotate__("fla")))
__attribute((__annotate__("sub")))
__attribute((__annotate__("split")))
__attribute((__annotate__("sobf")))
void func(){
xxx
}
深度混淆
SET(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mllvm -bcf -mllvm -bcf_loop=4 -mllvm -bcf_prob=100 -mllvm -sub -mllvm -sub_loop=2 -mllvm -fla -mllvm -sobf -mllvm -split")
Android 编译错误
我在Android studio 下 使用cmake 版本’3.18.1’ 报错 编译不成功
Build command failed.
Error while executing process D:\AndroidSDK\cmake\3.18.1\bin\ninja.exe with arguments {-C D:\AndroidCool\MyOllVM\app\.cxx\Debug\4q1o1o60\arm64-v8a myollvm}
ninja: Entering directory `D:\AndroidCool\MyOllVM\app\.cxx\Debug\4q1o1o60\arm64-v8a'
[1/2] Building CXX object CMakeFiles/myollvm.dir/native-lib.cpp.o
FAILED: CMakeFiles/myollvm.dir/native-lib.cpp.o
D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android21 --gcc-toolchain=D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot -Dmyollvm_EXPORTS -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -D_FORTIFY_SOURCE=2 -Wformat -Werror=format-security -std=c++11 -O0 -fno-limit-debug-info -mllvm -fla -fPIC -MD -MT CMakeFiles/myollvm.dir/native-lib.cpp.o -MF CMakeFiles\myollvm.dir\native-lib.cpp.o.d -o CMakeFiles/myollvm.dir/native-lib.cpp.o -c D:/AndroidCool/MyOllVM/app/src/main/cpp/native-lib.cpp
Stack dump:
0. Program arguments: D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe -cc1 -triple aarch64-none-linux-android21 -emit-obj -mrelax-all -mnoexecstack -disable-free -disable-llvm-verifier -discard-value-names -main-file-name native-lib.cpp -mrelocation-model pic -pic-level 2 -mthread-model posix -mdisable-fp-elim -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu generic -target-feature +neon -target-abi aapcs -mllvm -aarch64-fix-cortex-a53-835769=1 -fallow-half-arguments-and-returns -dwarf-column-info -debug-info-kind=standalone -dwarf-version=4 -debugger-tuning=gdb -ffunction-sections -fdata-sections -coverage-notes-file D:\AndroidCool\MyOllVM\app\.cxx\Debug\4q1o1o60\arm64-v8a\CMakeFiles/myollvm.dir/native-lib.cpp.gcno -resource-dir D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\9.0.1 -dependency-file CMakeFiles\myollvm.dir\native-lib.cpp.o.d -sys-header-deps -MT CMakeFiles/myollvm.dir/native-lib.cpp.o -D myollvm_EXPORTS -D ANDROID -D _FORTIFY_SOURCE=2 -isysroot D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot -internal-isystem D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/c++/v1 -internal-isystem D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/local/include -internal-isystem D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\lib\clang\9.0.1\include -internal-externc-isystem D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include/aarch64-linux-android -internal-externc-isystem D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/include -internal-externc-isystem D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include -O0 -Wformat -Werror=format-security -std=c++11 -fdeprecated-macro -fdebug-compilation-dir D:\AndroidCool\MyOllVM\app\.cxx\Debug\4q1o1o60\arm64-v8a -ferror-limit 19 -fmessage-length 0 -stack-protector 2 -fno-signed-char -fobjc-runtime=gcc -fcxx-exceptions -fexceptions -fdiagnostics-show-option -mllvm -fla -o CMakeFiles/myollvm.dir/native-lib.cpp.o -x c++ D:/AndroidCool/MyOllVM/app/src/main/cpp/native-lib.cpp
1. D:/AndroidSDK/ndk/21.1.6352462_OLLVM/toolchains/llvm/prebuilt/windows-x86_64/sysroot/usr/include\stdlib.h:44:28: current parser token ';'
#0 0x000000000326fea4 clang::ASTContext::adjustFunctionType(clang::FunctionType const*, clang::FunctionType::ExtInfo) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x2e6fea4)
#1 0x00000000031847b1 handleFunctionTypeAttr((anonymous namespace)::TypeProcessingState&, clang::ParsedAttr&, clang::QualType&) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x2d847b1)
#2 0x000000000318d82e processTypeAttrs((anonymous namespace)::TypeProcessingState&, clang::QualType&, TypeAttrLocation, clang::ParsedAttributesView&) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x2d8d82e)
#3 0x000000000319482d GetFullTypeForDeclarator((anonymous namespace)::TypeProcessingState&, clang::QualType, clang::TypeSourceInfo*) (.constprop.994) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x2d9482d)
#4 0x000000000319b6eb clang::Sema::GetTypeForDeclarator(clang::Declarator&, clang::Scope*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x2d9b6eb)
#5 0x0000000002dd2ea6 clang::Sema::HandleDeclarator(clang::Scope*, clang::Declarator&, llvm::MutableArrayRef<clang::TemplateParameterList*>) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x29d2ea6)
#6 0x0000000002dd38dc clang::Sema::ActOnDeclarator(clang::Scope*, clang::Declarator&) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x29d38dc)
#7 0x0000000002bec540 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27ec540)
#8 0x0000000002bf90b1 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::SourceLocation*, clang::Parser::ForRangeInit*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27f90b1)
#9 0x0000000002bd45a5 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d45a5)
#10 0x0000000002bd4e61 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.245.constprop.249) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d4e61)
#11 0x0000000002bd4e9b clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d4e9b)
#12 0x0000000002bd8619 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d8619)
#13 0x0000000002c0bb8c clang::Parser::ParseLinkage(clang::ParsingDeclSpec&, clang::DeclaratorContext) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x280bb8c)
#14 0x0000000002bd4870 clang::Parser::ParseDeclOrFunctionDefInternal(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d4870)
#15 0x0000000002bd4e61 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (.part.245.constprop.249) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d4e61)
#16 0x0000000002bd4e9b clang::Parser::ParseDeclarationOrFunctionDefinition(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d4e9b)
#17 0x0000000002bd8619 clang::Parser::ParseExternalDeclaration(clang::Parser::ParsedAttributesWithRange&, clang::ParsingDeclSpec*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d8619)
#18 0x0000000002bd9720 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, bool) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d9720)
#19 0x0000000002bd19ee clang::ParseAST(clang::Sema&, bool, bool) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x27d19ee)
#20 0x000000000255b506 clang::CodeGenAction::ExecuteAction() (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x215b506)
#21 0x000000000208e449 clang::FrontendAction::Execute() (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x1c8e449)
#22 0x000000000205fae0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x1c5fae0)
#23 0x000000000211129a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x1d1129a)
#24 0x00000000004025ad cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x25ad)
#25 0x0000000003ce8476 main (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x38e8476)
#26 0x00000000004013e8 __tmainCRTStartup (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x13e8)
#27 0x000000000040151b (D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe+0x151b)
#28 0x00007fff4c757614 (C:\WINDOWS\System32\KERNEL32.DLL+0x17614)
#29 0x00007fff4dc426a1 (C:\WINDOWS\SYSTEM32\ntdll.dll+0x526a1)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Obfuscator-LLVM clang version 9.0.1 (based on Obfuscator-LLVM 9.0.1)
Target: aarch64-none-linux-android21
Thread model: posix
InstalledDir: D:\AndroidSDK\ndk\21.1.6352462_OLLVM\toolchains\llvm\prebuilt\windows-x86_64\bin
clang++: note: diagnostic msg: PLEASE submit a bug report to http://o-llvm.org and include the crash backtrace, preprocessed source, and associated run script.
clang++: note: diagnostic msg:
********************
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: C:\Users\THINKCAR\AppData\Local\Temp\native-lib-6bd552.cpp
clang++: note: diagnostic msg: C:\Users\THINKCAR\AppData\Local\Temp\native-lib-6bd552.sh
clang++: note: diagnostic msg:
********************
ninja: build stopped: subcommand failed.
我经过测试发现 只要使用到 c++ 标准的头文件 类似于下面的
#include <string>
#include <iostream>
程序就会出现上面的错误
不知道为什么 但是我在另外一台电脑上测试 又是可以正常使用这些头文件的 不知道为什么文章来源:https://www.toymoban.com/news/detail-508654.html
#参考
https://www.jianshu.com/p/85e0abbc7f53
https://blog.csdn.net/weixin_42600398/article/details/113572340文章来源地址https://www.toymoban.com/news/detail-508654.html
到了这里,关于Windows下Android studio 搭建 android NDK 搭建 OLLVM 踩坑记录的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!