android studio使用openssl

來源:互聯網
上載者:User

標籤:pes   連結   name   find   lag   config   amp   jar   oca   

前言

逆向的基礎是開發, 逆向分析時很多時候會使用一些公開的加密函數來對資料進行加密,通過使用 openssl 熟悉下。

本文

首先得先編譯出來 openssl,然後把它們複製到你的工程目錄下。

includeopenssl 的標頭檔。lib 下的那些是編譯出來的so。

然後修改 build.gradle 中的 cmake 項:

cppFlags 是編譯選項, abiFilters指定編譯so的 abi,和 剛才 lib 目錄中的目錄項對應。後面會用到。

增加

jniLibs.srcDirs 的值為openssl so的目錄。表示打包時直接複製這些就行了。
最終的 build.gradle

apply plugin: ‘com.android.application‘android {    compileSdkVersion 26    defaultConfig {        applicationId "com.example.administrator.oi"        minSdkVersion 19        targetSdkVersion 26        versionCode 1        versionName "1.0"        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"        externalNativeBuild {            cmake {                cppFlags "-std=c++11 -frtti -fexceptions"                abiFilters ‘armeabi‘, ‘armeabi-v7a‘            }        }    }    buildTypes {        release {            minifyEnabled false            proguardFiles getDefaultProguardFile(‘proguard-android.txt‘), ‘proguard-rules.pro‘        }    }    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 ‘com.android.support:appcompat-v7:26.1.0‘    implementation ‘com.android.support.constraint:constraint-layout:1.0.2‘    testImplementation ‘junit:junit:4.12‘    androidTestImplementation ‘com.android.support.test:runner:1.0.1‘    androidTestImplementation ‘com.android.support.test.espresso:espresso-core:3.0.1‘}

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

# For more information about using CMake with Android Studio, read the# documentation: https://d.android.com/studio/projects/add-native-code.html# Sets the minimum version of CMake required to build the native library.cmake_minimum_required(VERSION 3.4.1)# 設定標頭檔載入的目錄include_directories(C:/Users/Administrator/AndroidStudioProjects/oi/app/openssl_resouce/include)#動態方式載入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}/libcrypto.so)set_target_properties(ssl PROPERTIES IMPORTED_LOCATION C:/Users/Administrator/AndroidStudioProjects/oi/app/openssl_resouce/lib/${ANDROID_ABI}/libssl.so)# 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.             native-lib             # Sets the library as a shared library.             SHARED             # 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.              log-lib              # 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.                       native-lib                       openssl                       ssl                       # Links the target library to the log library                       # included in the NDK.                       ${log-lib} )

然後就可以使用了。

項目路徑

https://gitee.com/hac425/android_openssl/

android studio使用openssl

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.