El estudio de Android en Windows crea el NDK de Android y crea el registro de pasos de OLLVM

1. Compilar ollvm-9.0.1

Descargar código fuente para compilar

https://github.com/heroims/obfuscator/tree/llvm-9.0.1
inserte la descripción de la imagen aquí

compilar

Hay trampas aquí. Tenga cuidado de no usar la última versión de mingw 8.0.1 para compilar, y se informará un error.
El contenido del error es el siguiente:

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!

Se supone que la posible razón se debe a la compatibilidad de la versión cmake y la versión mingw con cmakelists.txt de ollvm-9.0.1

Luego volví a descargar la versión anterior de mingw. Usé la
dirección de descarga x86_64-5.4.0-release-posix-seh-rt_v5-rev0 mingw.

Comando de compilación
Descomprima el archivo descargado e ingrese al directorio de archivos descomprimidos

mkdir build
cd build
cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../../obfuscator-llvm-9.0.1
cmake --build .

inserte la descripción de la imagen aquí

Configurar el NDK de Android

Descargar NDK 21.4.7075529

inserte la descripción de la imagen aquí

Copie el contenido compilado en el directorio especificado del NDK21 descargado

  1. Copie un ndk descargado llamado 21.4.7075529Ollvm9.0.1
  2. Copie clang.exe clang++.exe clang-format.exe de obfuscator-llvm-9.0.1\build\bin en el directorio ollvm compilado en el directorio 21.4.7075529Ollvm9.0.1\toolchains\llvm\prebuilt\windows-x86_64/bin 3. Copie /build/lib/clang/9 Copie los cuatro archivos stdarg.h, stddef .h, __stddef_max_align_t.h y float.h en .0.1/include en el directorio NDK /toolchains/llvm/prebuilt/darwin-x86_64/sysroot/usr/include carpeta utilizada
    por
    AndroidStudio

Modifíquelo en CMakeLists.txt de la siguiente manera

 #设置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")

ofuscación de una sola función

__attribute((__annotate__("bcf")))
__attribute((__annotate__("fla")))
__attribute((__annotate__("sub")))
__attribute((__annotate__("split")))
__attribute((__annotate__("sobf")))
void func(){
    
    
	xxx
}

profunda confusión

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")

Error de compilación de Android

Uso la versión de cmake '3.18.1' en el estudio de Android y la compilación falla

    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.

Después de la prueba, descubrí que siempre que se use el archivo de encabezado del estándar c ++, es similar al siguiente

#include <string> 
#include <iostream>

El error anterior aparecerá en el programa.
No sé por qué, pero puedo usar estos archivos de encabezado normalmente cuando pruebo en otra computadora. No sé por qué.

#Referencia
https://www.jianshu.com/p/85e0abbc7f53
https://blog.csdn.net/weixin_42600398/article/details/113572340

Supongo que te gusta

Origin blog.csdn.net/qq_36535153/article/details/131374150
Recomendado
Clasificación