前言

逆向的基础是开发, 逆向分析时很多时候会使用一些公开的加密函数来对数据进行加密,通过使用 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/

最新文章

  1. css新增样式
  2. GOOGLE地图坐标拾取方法、GOOGLE地图获取坐标方法
  3. Sharepoint学习笔记—习题系列--70-573习题解析 -(Q28-Q31)
  4. 使用shell测试cdn状态
  5. linx 实用操作命令一
  6. chrome内核浏览器缓存资源找回方法
  7. 一般处理程序(ashx)和页面处理程序(aspx)的区别
  8. 【转】iOS-Core-Animation-Advanced-Techniques(一)
  9. JavaScript插件 Bootstrap自带了13个jQuery插件,这些插件为Bootstrap中的组件赋予了“生命”
  10. 使用程序控制windows service启动/停止
  11. [PGM] Bayes Network and Conditional Independence
  12. Android初级教程Fragment到Fragment的通信初探
  13. HTML5特性之AJAX跨域
  14. php一次性大量数据入库解决方法
  15. SALALchemy Session与scoped_session的源码分析
  16. Android Firebase Android google-cloud-tools
  17. Window下PHP三种运行方式图文详解,window下的php是不是单进程的?
  18. jQuery多文件下载
  19. HttpServletResponse 的 sendError( )方法以及常用的HttpServletResponse常量级错误代码
  20. 基于Prometheus,Alermanager实现Kubernetes自动伸缩

热门文章

  1. (转)Python进阶:函数式编程(高阶函数,map,reduce,filter,sorted,返回函数,匿名函数,偏函数)
  2. (转)linux如何让历史记录不记录敏感命令
  3. Filter应用之-自动登录
  4. 【Java并发编程】:守护线程与线程阻塞的四种情况
  5. inline-block各浏览器兼容以及水平间隙问题解决方案
  6. Ubuntukylin-14.04-desktop( 不带分区)安装步骤详解
  7. 11 - JavaSE之GUI
  8. Java性能调优:利用JMC进行性能分析
  9. Linux网络子系统
  10. 一个基于Socket的http请求监听程序实现