android studio使用openssl


逆向的基础是开发, 逆向分析时很多时候会使用一些公开的加密函数来对数据进行加密,通过使用 openssl 熟悉下。


首先得先编译出来 openssl,然后把它们复制到你的工程目录下。

includeopenssl 的头文件。lib 下的那些是编译出来的so。

然后修改 build.gradle 中的 cmake 项:

cppFlags 是编译选项, abiFilters指定编译so的 abi,和 刚才 lib 目录中的目录项对应。后面会用到。


jniLibs.srcDirs 的值为openssl so的目录。表示打包时直接复制这些就行了。
最终的 build.gradle

apply plugin: ''

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.administrator.oi"
        minSdkVersion 19
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner ""
        externalNativeBuild {
            cmake {
                cppFlags "-std=c++11 -frtti -fexceptions"
                abiFilters 'armeabi', 'armeabi-v7a'
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

    sourceSets {
        main {
            jniLibs.srcDirs = ["C:\\Users\\Administrator\\AndroidStudioProjects\\oi\\app\\openssl_resouce\\lib"]

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation ''
    implementation ''
    testImplementation 'junit:junit:4.12'
    androidTestImplementation ''
    androidTestImplementation ''

然后修改 CMakeLists.txt, 中文注释的地方就是修改的地方。

# For more information about using CMake with Android Studio, read the
# documentation:

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

# 设置头文件加载的目录

add_library(openssl SHARED IMPORTED )
add_library(ssl SHARED IMPORTED )

#引入第三方.so库,根据${ANDROID_ABI} 引用不同的库
set_target_properties(openssl PROPERTIES IMPORTED_LOCATION C:/Users/Administrator/AndroidStudioProjects/oi/app/openssl_resouce/lib/${ANDROID_ABI}/
set_target_properties(ssl PROPERTIES IMPORTED_LOCATION C:/Users/Administrator/AndroidStudioProjects/oi/app/openssl_resouce/lib/${ANDROID_ABI}/

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.

             # Sets the library as a shared library.

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

# 设置链接选项
target_link_libraries( # Specifies the target library.

                       # Links the target library to the log library
                       # included in the NDK.
                       ${log-lib} )



posted @ 2018-08-03 23:45  hac425  阅读(688)  评论(0编辑  收藏  举报