├── .gitignore ├── .idea ├── .name ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── CarSlave.keystore ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── innotechx │ │ └── ndkaesdemo │ │ └── ApplicationTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── innotechx │ │ │ ├── jni │ │ │ └── NativeUtils.java │ │ │ └── ndkaesdemo │ │ │ └── MainActivity.java │ ├── jni │ │ ├── Android.mk │ │ └── NativeUtils.cpp │ ├── jniLibs │ │ ├── arm64-v8a │ │ │ └── libnativeUtils.so │ │ ├── armeabi-v7a │ │ │ └── libnativeUtils.so │ │ ├── armeabi │ │ │ └── libnativeUtils.so │ │ ├── mips │ │ │ └── libnativeUtils.so │ │ ├── mips64 │ │ │ └── libnativeUtils.so │ │ ├── x86 │ │ │ └── libnativeUtils.so │ │ └── x86_64 │ │ │ └── libnativeUtils.so │ └── res │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-hdpi │ │ └── ic_launcher.png │ │ ├── mipmap-mdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxhdpi │ │ └── ic_launcher.png │ │ ├── mipmap-xxxhdpi │ │ └── ic_launcher.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── innotechx │ └── ndkaesdemo │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | -------------------------------------------------------------------------------- /.idea/.name: -------------------------------------------------------------------------------- 1 | NdkDemo -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | Android 39 | 40 | 41 | Android Lint 42 | 43 | 44 | Java 45 | 46 | 47 | Java language level migration aidsJava 48 | 49 | 50 | 51 | 52 | Android 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 74 | 75 | 76 | 77 | 78 | 79 | 84 | 85 | 86 | 87 | 88 | 89 | Android API 19 Platform 90 | 91 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /CarSlave.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/CarSlave.keystore -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NdkDemo 2 | android通过ndk加解密和防apk反编译。 3 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.1" 6 | defaultConfig { 7 | applicationId "com.innotechx.ndkaesdemo" 8 | minSdkVersion 14 9 | targetSdkVersion 23 10 | versionCode 1 11 | versionName "1.0" 12 | 13 | ndk { 14 | moduleName "aesUtils" 15 | ldLibs "log" //实现__android_log_print 16 | abiFilters "armeabi", "armeabi-v7a", "x86" 17 | } 18 | } 19 | 20 | signingConfigs { 21 | release { 22 | keyAlias 'carSlave' 23 | keyPassword 'carSlave' 24 | storeFile file('/Users/sunyuqin/git/android_studio/NdkDemo/CarSlave.keystore') 25 | storePassword 'carSlave' 26 | } 27 | } 28 | 29 | buildTypes { 30 | debug { 31 | 32 | } 33 | release { 34 | minifyEnabled true 35 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 36 | debuggable false 37 | jniDebuggable false 38 | signingConfig signingConfigs.release 39 | } 40 | } 41 | } 42 | 43 | dependencies { 44 | compile fileTree(dir: 'libs', include: ['*.jar']) 45 | testCompile 'junit:junit:4.12' 46 | compile 'com.android.support:appcompat-v7:23.4.0' 47 | } 48 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /Users/sunyuqin/Library/Android/sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/innotechx/ndkaesdemo/ApplicationTest.java: -------------------------------------------------------------------------------- 1 | package com.innotechx.ndkaesdemo; 2 | 3 | import android.app.Application; 4 | import android.test.ApplicationTestCase; 5 | 6 | /** 7 | * Testing Fundamentals 8 | */ 9 | public class ApplicationTest extends ApplicationTestCase { 10 | public ApplicationTest() { 11 | super(Application.class); 12 | } 13 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/java/com/innotechx/jni/NativeUtils.java: -------------------------------------------------------------------------------- 1 | package com.innotechx.jni; 2 | 3 | import android.content.Context; 4 | 5 | public class NativeUtils { 6 | 7 | static { 8 | System.loadLibrary("nativeUtils"); 9 | } 10 | 11 | /** 12 | * 获取签名信息. 13 | * @param context 14 | * @return 15 | */ 16 | public static native String getSignature(Context context); 17 | 18 | /** 19 | * 检查签名是否被更改过。 20 | * @param context 21 | * @return 22 | */ 23 | public static native boolean checkSignature(Context context); 24 | 25 | /** 26 | * 获取私有的key(用与加解密或者和服务器约定好的key). 27 | * @param context 28 | * @return 29 | */ 30 | public static native String getPrivateKey(Context context); 31 | 32 | } 33 | -------------------------------------------------------------------------------- /app/src/main/java/com/innotechx/ndkaesdemo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.innotechx.ndkaesdemo; 2 | 3 | import android.content.pm.ApplicationInfo; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.TextView; 9 | import android.widget.Toast; 10 | 11 | import com.innotechx.jni.NativeUtils; 12 | 13 | 14 | public class MainActivity extends AppCompatActivity { 15 | 16 | @Override 17 | protected void onCreate(Bundle savedInstanceState) { 18 | super.onCreate(savedInstanceState); 19 | setContentView(R.layout.activity_main); 20 | 21 | boolean isDebuggable = (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)); 22 | Log.i("test", "isDebuggable : " + isDebuggable); 23 | } 24 | 25 | public void getPrivateKey(View view) { 26 | String privateKey = NativeUtils.getPrivateKey(this); 27 | Toast.makeText(this, privateKey, Toast.LENGTH_SHORT).show(); 28 | } 29 | 30 | public void checkSignature(View view) { 31 | boolean flag = NativeUtils.checkSignature(this); 32 | if (flag) { 33 | Toast.makeText(this, "签名没问题", Toast.LENGTH_SHORT).show(); 34 | } else { 35 | Toast.makeText(this, "签名被篡改", Toast.LENGTH_SHORT).show(); 36 | } 37 | } 38 | 39 | public void getSignature(View view) { 40 | TextView textView1 = (TextView) findViewById(R.id.text); 41 | textView1.setText("Signature的hashCode=" + NativeUtils.getSignature(this)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /app/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | LOCAL_PATH := $(call my-dir) 2 | 3 | include $(CLEAR_VARS) 4 | 5 | LOCAL_LDLIBS :=-llog 6 | 7 | LOCAL_MODULE := nativeUtils 8 | 9 | LOCAL_SRC_FILES := NativeUtils.cpp 10 | 11 | include $(BUILD_SHARED_LIBRARY) 12 | -------------------------------------------------------------------------------- /app/src/main/jni/NativeUtils.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define LOG_TAG "AesUtils" 7 | #define LOGI(fmt, args...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, fmt, ##args) 8 | 9 | extern "C" { 10 | 11 | static bool checkSignature = false; 12 | 13 | // 获取签名信息 14 | JNIEXPORT jstring JNICALL Java_com_innotechx_jni_NativeUtils_getSignature 15 | (JNIEnv *env, jclass clazz, jobject context_object) { 16 | jclass context_class = env->GetObjectClass(context_object); 17 | 18 | //context.getPackageManager() 19 | jmethodID methodId = env->GetMethodID(context_class, "getPackageManager", "()Landroid/content/pm/PackageManager;"); 20 | jobject package_manager_object = env->CallObjectMethod(context_object, methodId); 21 | if (package_manager_object == NULL) { 22 | __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageManager() Failed!"); 23 | return NULL; 24 | } 25 | 26 | //context.getPackageName() 27 | methodId = env->GetMethodID(context_class, "getPackageName", "()Ljava/lang/String;"); 28 | jstring package_name_string = (jstring)env->CallObjectMethod(context_object, methodId); 29 | if (package_name_string == NULL) { 30 | __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageName() Failed!"); 31 | return NULL; 32 | } 33 | 34 | env->DeleteLocalRef(context_class); 35 | 36 | //PackageManager.getPackageInfo(Sting, int) 37 | jclass pack_manager_class = env->GetObjectClass(package_manager_object); 38 | methodId = env->GetMethodID(pack_manager_class, "getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;"); 39 | env->DeleteLocalRef(pack_manager_class); 40 | jobject package_info_object = env->CallObjectMethod(package_manager_object, methodId, package_name_string, 64); 41 | if (package_info_object == NULL) { 42 | __android_log_print(ANDROID_LOG_INFO, "JNITag","getPackageInfo() Failed!"); 43 | return NULL; 44 | } 45 | 46 | env->DeleteLocalRef(package_manager_object); 47 | 48 | //PackageInfo.signatures[0] 49 | jclass package_info_class = env->GetObjectClass(package_info_object); 50 | jfieldID fieldId = env->GetFieldID(package_info_class, "signatures", "[Landroid/content/pm/Signature;"); 51 | env->DeleteLocalRef(package_info_class); 52 | jobjectArray signature_object_array = (jobjectArray)env->GetObjectField(package_info_object, fieldId); 53 | if (signature_object_array == NULL) { 54 | __android_log_print(ANDROID_LOG_INFO, "JNITag","PackageInfo.signatures[] is null"); 55 | return NULL; 56 | } 57 | jobject signature_object = env->GetObjectArrayElement(signature_object_array, 0); 58 | 59 | env->DeleteLocalRef(package_info_object); 60 | 61 | //Signature.toCharsString() 62 | jclass signature_class = env->GetObjectClass(signature_object); 63 | // methodId = env->GetMethodID(signature_class, "toCharsString", "()Ljava/lang/String;"); 64 | // env->DeleteLocalRef(signature_class); 65 | // jstring signature_string = (jstring) env->CallObjectMethod(signature_object, methodId); 66 | // return signature_string; 67 | 68 | //Signature.hashCode() 69 | jmethodID methodID_hc = env->GetMethodID(signature_class, "hashCode", "()I"); 70 | int hash_code = env->CallIntMethod(signature_object, methodID_hc); 71 | char str[32]; 72 | sprintf(str, "%u", hash_code); 73 | return env->NewStringUTF(str); 74 | } 75 | 76 | // jstring转char* 77 | char* jstringTostring(JNIEnv* env, jstring jstr) { 78 | char* rtn = NULL; 79 | jclass clsstring = env->FindClass("java/lang/String"); 80 | jstring strencode = env->NewStringUTF("utf-8"); 81 | jmethodID mid = env->GetMethodID(clsstring, "getBytes", "(Ljava/lang/String;)[B"); 82 | jbyteArray barr= (jbyteArray)env->CallObjectMethod(jstr, mid, strencode); 83 | jsize alen = env->GetArrayLength(barr); 84 | jbyte* ba = env->GetByteArrayElements(barr, JNI_FALSE); 85 | if (alen > 0) { 86 | rtn = (char*)malloc(alen + 1); 87 | memcpy(rtn, ba, alen); 88 | rtn[alen] = 0; 89 | } 90 | env->ReleaseByteArrayElements(barr, ba, 0); 91 | return rtn; 92 | } 93 | 94 | // 检查签名是否被更改过 95 | JNIEXPORT jboolean JNICALL Java_com_innotechx_jni_NativeUtils_checkSignature 96 | (JNIEnv *env, jclass clazz, jobject context_object) { 97 | jstring signature = Java_com_innotechx_jni_NativeUtils_getSignature(env, clazz, context_object); 98 | const char *orginalSignature = "244699197"; 99 | const char *currentSignature = jstringTostring(env, signature); 100 | int result = strcmp(orginalSignature, currentSignature); 101 | return result == 0 ? true : false; 102 | } 103 | 104 | // 获取私有的key(用与加解密或者和服务器约定好的key) 105 | JNIEXPORT jstring JNICALL Java_com_innotechx_jni_NativeUtils_getPrivateKey 106 | (JNIEnv *env, jclass clazz, jobject context_object) { 107 | LOGI("-----> : checkSignature %d", checkSignature); 108 | 109 | if (false == checkSignature) { 110 | checkSignature = Java_com_innotechx_jni_NativeUtils_checkSignature(env, clazz, context_object); 111 | } 112 | if (checkSignature) { 113 | return env->NewStringUTF("获取privateKey成功"); 114 | } 115 | return env->NewStringUTF("获取失败"); 116 | } 117 | } -------------------------------------------------------------------------------- /app/src/main/jniLibs/arm64-v8a/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/arm64-v8a/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi-v7a/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/armeabi-v7a/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/armeabi/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/armeabi/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/mips/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/mips/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/mips64/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/mips64/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/x86/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/jniLibs/x86_64/libnativeUtils.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZhangLiuCheng/NdkDemo/3364731e68e3932a6876f4430c1a50fb672c71c7/app/src/main/jniLibs/x86_64/libnativeUtils.so -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 |