Ubuntu18.04
AndroidStudio4.0.1

NDK 16.1.4479499,CMake3.10.2

下載,編譯ollvm4.0
git clone -b llvm-4.0 https://github.com/obfuscator-llvm/obfuscator.git
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_INCLUDE_TESTS=OFF ../obfuscator/
make -j$(nproc)
-mllvm -fla:控制流扁平化
-mllvm -sub:指令替換
-mllvm -bcf:虛假控制流程
有人又進行了移植,如果你用的移植版本,還有字串加密:
-mllvm -sobf
之后直接把build目錄下生成的bin, lib檔案夾,復制覆寫到NDK目錄的這個位置:比如:
~/Android/Sdk/ndk/16.1.4479499/toolchains/llvm/prebuilt/linux-x86_64
然后添加到CMakeList.txt中這個:
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -mllvm -sub -mllvm -sobf -mllvm -fla -mllvm -bcf")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -mllvm -sub -mllvm -sobf -mllvm -fla -mllvm -bcf")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -mllvm -sub -mllvm -sobf -mllvm -fla -mllvm -bcf" )
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -mllvm -sub -mllvm -sobf -mllvm -fla -mllvm -bcf" )
之后Build會報錯說<asm/......>下的頭檔案找不到,這里在
~/Android/Sdk/ndk/16.1.4479499/build/cmake/android.toolchain.cmake
最后新添加:
if (${ANDROID_ABI} STREQUAL "x86_64")
include_directories(${ANDROID_SYSROOT}/usr/include/x86_64-linux-android)
elseif (${ANDROID_ABI} STREQUAL "x86")
include_directories(${ANDROID_SYSROOT}/usr/include/i686-linux-android)
elseif (${ANDROID_ABI} STREQUAL "arm64-v8a")
include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
elseif (${ANDROID_ABI} STREQUAL "armeabi-v7a")
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
就可以了,
附上我的Gradle組態檔:
app/build.gradle
android{ ...... ndk { abiFilters 'arm64-v8a', 'armeabi-v7a' // arm64-v8a, armeabi-v7a, x86_64, x86 } externalNativeBuild { cmake { path "CMakeLists.txt" } } signingConfigs { projname { keyAlias "alias-key" keyPassword "123456" storeFile file("../key.jks") storePassword "123456" } } buildTypes { release { lintOptions { checkReleaseBuilds false abortOnError false } minifyEnabled true signingConfig signingConfigs.projname } debug{ minifyEnabled true signingConfig signingConfigs.projname } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:25.3.1' implementation "com.android.support.constraint:constraint-layout:1.1.3" testCompile 'junit:junit:4.12' }./build.gradle
// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { repositories { jcenter() maven { url 'https://maven.google.com/' name 'Google' } google() } dependencies { classpath 'com.android.tools.build:gradle:4.0.0' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() maven { url 'https://maven.google.com/' name 'Google' } } } task clean(type: Delete) { delete rootProject.buildDir }./local.properties
ndk.dir=/home/a/Android/Sdk/ndk/16.1.4479499 sdk.dir=/home/a/Android/Sdkapp/CMakeLists.txt
cmake_minimum_required(VERSION 3.4.1) add_library( # Sets the name of the library. Libs # Sets the library as a shared library. SHARED # Provides a relative path to your source file(s). src/main/cpp/secure-lib.cpp ) SET(CMAKE_CXX_FLAGS "-mllvm -fla -mllvm -sub -mllvm -bcf") find_library( # Sets the name of the path variable. log-lib # Specifies the name of the NDK library that # you want CMake to locate. log ) target_link_libraries( # Specifies the target library. Libs # Links the target library to the log library # included in the NDK. ${log-lib} )
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/259499.html
標籤:其他
上一篇:Codeforces Round #701 (Div. 2) D. Multiples and Power Differences 構造lcm
