-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from BruceWind/dev-libsodium
integrating libsodium.
- Loading branch information
Showing
60 changed files
with
1,198 additions
and
2,276 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
*.so filter=lfs diff=lfs merge=lfs -text | ||
*.a filter=lfs diff=lfs merge=lfs -text | ||
*.zip filter=lfs diff=lfs merge=lfs -text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
How to locate where native crash at? | ||
------------ | ||
1.ensure you ndk is set into environment. | ||
|
||
2.run **ndk-stack** to analyze logcat and **symbol file** to find where crash printed. | ||
``` | ||
//gradlew build with ndkBuild: | ||
adb logcat | ndk-stack -sym ./aesjni/build/intermediates/ndkBuild/debug/obj/local/arm64-v8a/objs-debug/ | ||
//gradlew build with CMake: | ||
adb logcat | ndk-stack -sym ./aesjni/build/intermediates/cmake/debug/obj/arm64-v8a | ||
//if you run ndk-build command: | ||
adb logcat | ndk-stack -sym ./aesjni/src/main/obj/local/x86/ | ||
``` | ||
> **../obj/local/x86/** and **../obj/local/armeabi-v7a/** is symbol file directory. | ||
|
||
### Example: | ||
|
||
I got crash logs: | ||
|
||
```logs | ||
$ ./test_in_executing.sh | ||
2021-02-24 17:03:48.242 12059-12059/? A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 in tid 12059 (test), pid 12059 (test) | ||
2021-02-24 17:03:48.251 12063-12063/? A/DEBUG: *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** | ||
2021-02-24 17:03:48.251 12063-12063/? A/DEBUG: Build fingerprint: 'google/sdk_gphone_x86_arm/generic_x86_arm:11/RSR1.201013.001/6903271:userdebug/dev-keys' | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: Revision: '0' | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: ABI: 'x86' | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: Timestamp: 2021-02-24 17:03:48+0800 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: pid: 12059, tid: 12059, name: test >>> /data/local/tmp/test <<< | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: uid: 2000 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: Cause: null pointer dereference | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: eax 00000000 ebx 60915ef0 ecx f482efe0 edx f482efe0 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: edi fff9e924 esi 608f0c20 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: ebp fff9e848 esp fff9e78c eip 60857ef3 | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: backtrace: | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: NOTE: Function names and BuildId information is missing for some frames due | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: NOTE: to unreadable libraries. For unwinds of apps, only shared libraries | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: NOTE: found under the lib/ directory are readable. | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: NOTE: On this device, run setenforce 0 to make the libraries readable. | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: #00 pc 0000bef3 /data/local/tmp/test | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: #01 pc 0000532e /data/local/tmp/test | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: #02 pc 000058f7 /data/local/tmp/test | ||
2021-02-24 17:03:48.252 12063-12063/? A/DEBUG: #03 pc 000522e3 /apex/com.android.runtime/lib/bionic/libc.so (__libc_init+115) (BuildId: 6e3a0180fa6637b68c0d181c343e6806) | ||
``` | ||
|
||
I run ndk-stack: | ||
```log | ||
$ adb logcat | ndk-stack -sym ./aesjni/src/main/obj/local/x86 | ||
********** Crash dump: ********** | ||
Build fingerprint: 'google/sdk_gphone_x86_arm/generic_x86_arm:11/RSR1.201013.001/6903271:userdebug/dev-keys' | ||
pid: 12059, tid: 12059, name: test >>> /data/local/tmp/test <<< | ||
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x0 | ||
Stack frame #00 pc 0000bef3 /data/local/tmp/test: Routine crypto_aead_aes256gcm_beforenm at ??:? | ||
Stack frame #01 pc 0000532e /data/local/tmp/test: Routine test_aead_aes256gcm at ~/Documents/git/AESJniEncrypt/aesjni/src/main/jni/main_unit_test.c:48 | ||
Stack frame #02 pc 000058f7 /data/local/tmp/test: Routine main at ~/Documents/git/AESJniEncrypt/aesjni/src/main/jni/main_unit_test.c:142 | ||
Stack frame #03 pc 000522e3 /apex/com.android.runtime/lib/bionic/libc.so (__libc_init+115) (BuildId: 6e3a0180fa6637b68c0d181c343e6806) | ||
``` | ||
|
||
`at ~/Documents/git/AESJniEncrypt/aesjni/src/main/jni/main_unit_test.c:48` show me that | ||
executable file crash at `line 48 from main_unit_test.c`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,69 @@ | ||
cmake_minimum_required(VERSION 3.4.1) #普通版本的clang | ||
|
||
# specify the C++ standard | ||
set(CMAKE_CXX_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
add_library( # Sets the name of the library. | ||
JNIEncrypt | ||
# -------configure import libsodium begin------ | ||
if (${ANDROID_ABI} STREQUAL "armeabi-v7a") | ||
set(ARCH_PREFIX "armv7-a") | ||
elseif (${ANDROID_ABI} STREQUAL "arm64-v8a") | ||
set(ARCH_PREFIX "armv8-a") | ||
elseif (${ANDROID_ABI} STREQUAL "armeabi") | ||
set(ARCH_PREFIX "armv6") | ||
elseif (${ANDROID_ABI} STREQUAL "x86") | ||
set(ARCH_PREFIX "i686") | ||
elseif (${ANDROID_ABI} STREQUAL "mips") | ||
set(ARCH_PREFIX "mips32") | ||
else () | ||
#set(ARCH_PREFIX ${ANDROID_ABI}) | ||
message(FATAL_ERROR "${ANDROID_ABI} static libraries might doesn't exist.") | ||
endif () | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# Provides a relative path to your source file(s). | ||
src/main/cpp/JNIEncrypt.c | ||
src/main/cpp/checksignature.h | ||
src/main/cpp/checksignature.c | ||
src/main/cpp/check_emulator.h | ||
src/main/cpp/check_emulator.c | ||
src/main/cpp/debugger.h | ||
src/main/cpp/debugger.c | ||
src/main/cpp/aes.h | ||
src/main/cpp/base64.h | ||
src/main/cpp/aes.c | ||
src/main/cpp/base64.c | ||
) | ||
set(distribution_DIR ${CMAKE_CURRENT_SOURCE_DIR}/src/main/jni/sodium_include/libsodium-android-${ARCH_PREFIX}) | ||
|
||
# 搜索指定的预构建库并将路径存储为变量。 因为默认情况下,CMake在搜索路径中包含系统库, | ||
# 所以您只需要指定公共NDK库的名称你想添加。 在完成构建之前,CMake验证库存在。 | ||
message(STATUS "Current build include : ${distribution_DIR} ") | ||
add_library(libsodium STATIC IMPORTED) | ||
set_target_properties(libsodium PROPERTIES IMPORTED_LOCATION | ||
${distribution_DIR}/lib/libsodium.a) | ||
# include C export files. | ||
include_directories(${distribution_DIR}/include) | ||
# -------configure import libsodium end------ | ||
|
||
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 ) | ||
set(DEBUG_FILE_C "src/main/jni/debugger.c") | ||
|
||
# 指定CMake应链接到目标库的库。 您可以链接多个库,例如在此构建脚本中定义的库,预构建的第三方库或系统库。 | ||
if (${CMAKE_BUILD_TYPE} STREQUAL "Debug") | ||
set(DEBUG_FILE_C "src/main/jni/debugger_test.c") | ||
endif () | ||
|
||
target_link_libraries( # Specifies the target library. | ||
JNIEncrypt | ||
add_library( # Sets the name of the library. | ||
JNIEncrypt | ||
|
||
# Sets the library as a shared library. | ||
SHARED | ||
|
||
# included in the NDK. | ||
${log-lib} ) | ||
# Provides a relative path to your source file(s). | ||
src/main/jni/checksignature.h | ||
src/main/jni/checksignature.c | ||
src/main/jni/check_emulator.h | ||
src/main/jni/check_emulator.c | ||
src/main/jni/debugger.h | ||
${DEBUG_FILE_C} | ||
src/main/jni/logger.h | ||
src/main/jni/keys_generator.h | ||
src/main/jni/keys_generator.c | ||
src/main/jni/base64.h | ||
src/main/jni/base64.c | ||
src/main/jni/str_utils.cpp | ||
src/main/jni/JNIEncrypt.c | ||
) | ||
|
||
find_library(log-lib | ||
log) | ||
|
||
target_link_libraries( # Specifies the target library. | ||
JNIEncrypt | ||
libsodium | ||
${log-lib}) |
Oops, something went wrong.