├── .gitignore ├── .idea ├── caches │ └── build_file_checksums.ser ├── codeStyles │ └── Project.xml ├── gradle.xml ├── misc.xml └── runConfigurations.xml ├── README.md ├── app ├── .gitignore ├── CMakeLists.txt ├── build.gradle ├── demo.jks ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── chenzhihui │ │ └── demo │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── cpp │ │ └── security.cpp │ ├── java │ │ └── com │ │ │ └── chenzhihui │ │ │ └── demo │ │ │ ├── MainActivity.java │ │ │ └── SecurityUtil.java │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── chenzhihui │ └── demo │ └── 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/libraries 5 | /.idea/modules.xml 6 | /.idea/workspace.xml 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild 11 | -------------------------------------------------------------------------------- /.idea/caches/build_file_checksums.ser: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/.idea/caches/build_file_checksums.ser -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 15 | 16 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 27 | 28 | 29 | 30 | 31 | 32 | 34 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SecurityDemo 2 | ndk进行简单的签名校验,密钥保护 3 | # 使用Cmake进行NDK开发(应用签名校验、密钥保护、so文件适配相关) 4 | 5 | [NDK官方指南](https://developer.android.com/ndk/guides/concepts.html) 6 | 7 | 8 | [CMake官方文档](https://developer.android.com/ndk/guides/cmake.html) 9 | 10 | 11 | [CMake译文](https://www.zybuluo.com/khan-lau/note/254724) 12 | 13 | 14 | [Google官方samples](https://github.com/googlesamples/android-ndk) 15 | 16 | 17 | 18 | ## 从HelloWorld开始咯 19 | 新建项目,勾选include c++ support 20 |
21 | 22 | 23 |
24 | 25 | 建立完成之后,看看现在的项目文件结构 26 |
27 | 28 | 29 |
30 | 31 | build.gradle 32 |
33 | 34 | 35 |
36 | 37 | 多了一个.externalNativeBuild文件夹 38 | main下多了个cpp文件夹 39 | 以及app里面多了CMakeLists.txt 40 | build.gradle文件多了两处externalNativeBuild块 41 | defaultConfig外面的那个externalNativeBuild块主要是指定CMakeLists.txt的文件路径 42 | defaultConfig里面的那个externalNativeBuild块主要填写CMake的命令参数。即由 arguments 中的参数最后转化成一个可执行的 CMake 的命令,可以在.externalNativeBuild/cmake/debug/{abi}/cmake_build_command.txt 中查到 43 |
44 | 45 | 来看看CMakeLists.txt 46 |
47 | 48 | 49 |
50 | 51 | CMakeLists文件里面指出了需要编译的文件 52 |
53 | 54 | 默认已经帮我们生成了一个jni方法,返回一个helloworld字符串 55 |
56 | 57 |
58 | 59 |
60 | 61 | 运行结果: 62 | 63 | 64 | 65 | 66 | ## 做一下简单的密钥保存 67 | 先专门弄一个类来生命native方法和加载so库,就叫SecurityUtil类吧 68 | 放在包名的目录下(注意,定义native方法的时候,跟加载so库所在的类有关系,比如这里的SecurityUtil类,我放在com.a.b目录下,在这个类的静态代码块加载库,System.loadLibrary("native-lib");那么,定义native方法的格式就应该是Java_com_a_b_方法名,而当我放在com.a.b.c下,那native方法的格式就是Java_com_a_b_c_方法名,具体可以查一下jni方法的命名) 69 | 在cpp文件夹新建一个security.cpp文件,改一下CMakeLists文件让他编译我们的cpp文件,新增一个getSecret方法,运行 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 运行效果: 81 | 82 |
83 | 84 | 85 | 86 | 然后可以看到包名/build/intermediate/cmake目录下已经生成了so文件 87 | 88 | 89 | ## 签名校验 90 | 上一步做的密钥保存生成的so库文件其实也不安全,由于jni的机制是反射实现的java端和native端的互相调用,所以在打包时候不能混淆native方法,所以只需要反编译提取出so文件和知道相应的native方法名,自己新建一个应用load一下那个库调用一下方法,那个密钥串就能简单被debug出来,所以我们一般会做应用的签名校验,当签名不一致时直接崩溃就好了。 91 | 92 | java端获取应用签名的方法 93 | ``` 94 | PackageManager pm = context.getPackageManager(); 95 | PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_SIGNATURES); 96 | Signature[] signatures = pi.signatures; 97 | Signature signature0 = signatures[0]; 98 | signature0.toCharsString(); 99 | ``` 100 | 获取签名跟context对象有关,所以假如重写一下context和packagemanager,还是有可能仿冒正确的context对象,这里使用反射ActivityThread类,然后通过invoke反射调用currentApplication方法获取当前的context对象,避免由参数传入context对象的方式增大破解的难度 101 | 对应到native端,获取context的代码就变成了 102 | ``` 103 | static jobject getApplication(JNIEnv *env) { 104 | jobject application = NULL; 105 | jclass activity_thread_clz = env->FindClass("android/app/ActivityThread"); 106 | if (activity_thread_clz != NULL) { 107 | jmethodID currentApplication = env->GetStaticMethodID( 108 | activity_thread_clz, "currentApplication", "()Landroid/app/Application;"); 109 | if (currentApplication != NULL) { 110 | application = env->CallStaticObjectMethod(activity_thread_clz, currentApplication); 111 | } else { 112 | LOGE("Cannot find method: currentApplication() in ActivityThread."); 113 | } 114 | env->DeleteLocalRef(activity_thread_clz); 115 | } else { 116 | LOGE("Cannot find class: android.app.ActivityThread"); 117 | } 118 | 119 | return application; 120 | } 121 | ``` 122 | 验证签名的时机,放在jni的onload方法,也就是当加载动态库的时候就进行签名校验,跟内置的串进行对比,校验不通过直接崩溃。 123 | 124 | 所以最后的cpp文件如下 125 | 126 | ``` 127 | #include 128 | #include 129 | #include 130 | #include 131 | 132 | #define LOGINFO(...) ((void)__android_log_print(ANDROID_LOG_INFO, "security", __VA_ARGS__)) 133 | #define LOGERROR(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "security", __VA_ARGS__)) 134 | 135 | static int verifySign(JNIEnv *env); 136 | 137 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { 138 | JNIEnv *env = NULL; 139 | if (vm->GetEnv((void **) &env, JNI_VERSION_1_4) != JNI_OK) { 140 | return JNI_ERR; 141 | } 142 | if (verifySign(env) == JNI_OK) { 143 | return JNI_VERSION_1_4; 144 | } 145 | LOGERROR("签名不一致!"); 146 | return JNI_ERR; 147 | } 148 | 149 | static jobject getApplication(JNIEnv *env) { 150 | jobject application = NULL; 151 | jclass activity_thread_clz = env->FindClass("android/app/ActivityThread"); 152 | if (activity_thread_clz != NULL) { 153 | jmethodID currentApplication = env->GetStaticMethodID( 154 | activity_thread_clz, "currentApplication", "()Landroid/app/Application;"); 155 | if (currentApplication != NULL) { 156 | application = env->CallStaticObjectMethod(activity_thread_clz, currentApplication); 157 | } else { 158 | LOGERROR("Cannot find method: currentApplication() in ActivityThread."); 159 | } 160 | env->DeleteLocalRef(activity_thread_clz); 161 | } else { 162 | LOGERROR("Cannot find class: android.app.ActivityThread"); 163 | } 164 | 165 | return application; 166 | } 167 | 168 | 169 | static const char *SIGN = "308203533082023ba0030201020204691f1618300d06092a864886f70d01010b0500305a310d300b060355040613046368656e310d300b060355040813046368656e310d300b060355040713046368656e310d300b060355040a13046368656e310d300b060355040b13046368656e310d300b060355040313046368656e301e170d3138303432353038323530355a170d3433303431393038323530355a305a310d300b060355040613046368656e310d300b060355040813046368656e310d300b060355040713046368656e310d300b060355040a13046368656e310d300b060355040b13046368656e310d300b060355040313046368656e30820122300d06092a864886f70d01010105000382010f003082010a02820101008001ead218d523543023e195c065fb807f06313a915f510e59d556c55f192163a5acd4300851ae738a601c2b4a6284beb900c31338d4ce36dd3fe490c16560dc4dfca13685a1993c6705976797a5a23841edd261c95a419da6e62ebe17a25b787e1ff2097a9b112f48a3fe03b7777b9833799680bae0a9a1d423296b31a87e65758b6fb56f9ea78c4d0537924663563c8cc59c2877c4ee58704b03f3cd5bdb1383084064be54b0a8de408ca51ecb0c68194fc6adb643d5827053371a34d75d8c98ff7edc4d929747afe48a7e6701d9dfd7897a221ba82b63c27bf2ce8c0784c5810f425526e28b840c429d9f0984b44671d3d5a1b77827f529c7aad6877f3c450203010001a321301f301d0603551d0e0416041403a7a9f045b7ab586c6102c49ced45e8879d350a300d06092a864886f70d01010b050003820101007dc1ae5fabc39101d74987f535be17e9c80b71daf55193b4c6abd381adf59042dabeeebd59d8f2ad1cbe0dd4feaee803e62b9b4b425a0936a4041245b7893a51c40fe0f10ea67a0a00e6360c25c703c5801f8e8740c544ce3d3874620dc26efbf5331020d30ac9e0ae1b217ab841959386a56aab61981ba01a1d62ede59866d936d1ade91d6723ea5569128a6bd5a8158733bb18499f8100a29beee19713be64b82ba348bb4d8eb5591cd5b09323746ccd5b9b115c6c1462f07165070eab6cfd9f18af717e94f384059b72ee3866553adc6d248b7d4a7f945666edb822eb20d2229d3b8c8b1038b1f11640b7a00e8f79623ffedf697da528af1ac828b009af53"; 170 | 171 | static int verifySign(JNIEnv *env) { 172 | // Application object 173 | jobject application = getApplication(env); 174 | if (application == NULL) { 175 | return JNI_ERR; 176 | } 177 | // Context(ContextWrapper) class 178 | jclass context_clz = env->GetObjectClass(application); 179 | // getPackageManager() 180 | jmethodID getPackageManager = env->GetMethodID(context_clz, "getPackageManager", 181 | "()Landroid/content/pm/PackageManager;"); 182 | // android.content.pm.PackageManager object 183 | jobject package_manager = env->CallObjectMethod(application, getPackageManager); 184 | // PackageManager class 185 | jclass package_manager_clz = env->GetObjectClass(package_manager); 186 | // getPackageInfo() 187 | jmethodID getPackageInfo = env->GetMethodID(package_manager_clz, "getPackageInfo", 188 | "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;"); 189 | // context.getPackageName() 190 | jmethodID getPackageName = env->GetMethodID(context_clz, "getPackageName", 191 | "()Ljava/lang/String;"); 192 | // call getPackageName() and cast from jobject to jstring 193 | jstring package_name = (jstring) (env->CallObjectMethod(application, getPackageName)); 194 | // PackageInfo object 195 | jobject package_info = env->CallObjectMethod(package_manager, getPackageInfo, package_name, 64); 196 | // class PackageInfo 197 | jclass package_info_clz = env->GetObjectClass(package_info); 198 | // field signatures 199 | jfieldID signatures_field = env->GetFieldID(package_info_clz, "signatures", 200 | "[Landroid/content/pm/Signature;"); 201 | jobject signatures = env->GetObjectField(package_info, signatures_field); 202 | jobjectArray signatures_array = (jobjectArray) signatures; 203 | jobject signature0 = env->GetObjectArrayElement(signatures_array, 0); 204 | jclass signature_clz = env->GetObjectClass(signature0); 205 | 206 | jmethodID toCharsString = env->GetMethodID(signature_clz, "toCharsString", 207 | "()Ljava/lang/String;"); 208 | // call toCharsString() 209 | jstring signature_str = (jstring) (env->CallObjectMethod(signature0, toCharsString)); 210 | 211 | // release 212 | env->DeleteLocalRef(application); 213 | env->DeleteLocalRef(context_clz); 214 | env->DeleteLocalRef(package_manager); 215 | env->DeleteLocalRef(package_manager_clz); 216 | env->DeleteLocalRef(package_name); 217 | env->DeleteLocalRef(package_info); 218 | env->DeleteLocalRef(package_info_clz); 219 | env->DeleteLocalRef(signatures); 220 | env->DeleteLocalRef(signature0); 221 | env->DeleteLocalRef(signature_clz); 222 | 223 | const char *sign = env->GetStringUTFChars(signature_str, NULL); 224 | if (sign == NULL) { 225 | LOGERROR("分配内存失败"); 226 | return JNI_ERR; 227 | } 228 | //发布记得去掉log!!!!!!! 229 | // LOGINFO("应用中读取到的签名为:%s", sign); 230 | // LOGINFO("native中预置的签名为:%s", SIGN); 231 | int result = strcmp(sign, SIGN); 232 | // LOGINFO("strcmp:%d", result); 233 | // 使用之后要释放这段内存 234 | env->ReleaseStringUTFChars(signature_str, sign); 235 | env->DeleteLocalRef(signature_str); 236 | if (result == 0) { // 签名一致 237 | return JNI_OK; 238 | } 239 | 240 | return JNI_ERR; 241 | } 242 | 243 | 244 | extern "C" JNIEXPORT jstring 245 | 246 | JNICALL 247 | Java_com_chenzhihui_demo_SecurityUtil_getSecret( 248 | JNIEnv *env, 249 | jobject /* this */) { 250 | std::string hello = "hahahahasecrethahahahaha"; 251 | return env->NewStringUTF(hello.c_str()); 252 | } 253 | ``` 254 | 255 | 256 | 换一个签名再运行或者改一下内置的签名串让它不相等: 257 | 258 |
259 | 260 | 261 | 262 |
263 | 264 | 这样就完成了签名校验过程 265 | 打个包会发现 包名/build/intermediate/cmake目录下已经生成了各个abi对应的so文件,当然也可以在gradle文件指定需要的abi 266 | 267 | 268 | 269 | ## so文件相关 270 | 不同 Android 手机使用不同的 CPU,因此支持不同的指令集。CPU 与指令集的每种组合都有其自己的应用二进制界面(或 ABI)。 ABI 可以非常精确地定义应用的机器代码在运行时如何与系统交互。 您必须为应用要使用的每个 CPU 架构指定 ABI。 271 |
272 | [官网对abi的介绍](https://developer.android.com/ndk/guides/abis.html) 273 | 274 | 275 | 276 | 277 | ### 兼容方面 278 | 对于CPU来说,不同的架构并不意味着一定互不兼容,根据目前Android共支持七种不同类型的CPU架构,其兼容特点可总结如下: 279 | - armeabi设备只兼容armeabi; 280 | - armeabi-v7a设备兼容armeabi-v7a、armeabi; 281 | - arm64-v8a设备兼容arm64-v8a、armeabi-v7a、armeabi; 282 | - X86设备兼容X86、armeabi; 283 | - X86_64设备兼容X86_64、X86、armeabi; 284 | - mips64设备兼容mips64、mips; 285 | - mips只兼容mips; 286 | armeabi的so能运行在除了mips和mips64的设备上(在非armeabi上性能有所损耗) 287 | 64位的CPU架构总能向下兼容其对应的32位指令集 288 | 289 | ### 适配方面 290 | - ARM架构几乎垄断,而且绝大部分都是armeabi-v7a、arm64-v8a,几乎可以不考虑X86、X86_64、mips、mips64架构 291 | - 假如你只提供了armeabi,而没有提供v7a,v8a,且某些so文件在v7a或v8a架构中使用armeabi的so时性能差距明显,则可以考虑单独把那份so的v7a,v8a的so文件也放进armeabi的文件夹,通过代码判断当前cpu架构然后再来加载对应的so文件 292 | 293 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | *.iml 3 | .gradle 4 | /local.properties 5 | /.idea/workspace.xml 6 | /.idea/libraries 7 | .DS_Store 8 | /build 9 | /captures 10 | .externalNativeBuild -------------------------------------------------------------------------------- /app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.4.1) 7 | 8 | # Creates and names a library, sets it as either STATIC 9 | # or SHARED, and provides the relative paths to its source code. 10 | # You can define multiple libraries, and CMake builds them for you. 11 | # Gradle automatically packages shared libraries with your APK. 12 | 13 | add_library( # Sets the name of the library. 14 | security 15 | 16 | # Sets the library as a shared library. 17 | SHARED 18 | 19 | # Provides a relative path to your source file(s). 20 | src/main/cpp/security.cpp ) 21 | 22 | # Searches for a specified prebuilt library and stores the path as a 23 | # variable. Because CMake includes system libraries in the search path by 24 | # default, you only need to specify the name of the public NDK library 25 | # you want to add. CMake verifies that the library exists before 26 | # completing its build. 27 | 28 | find_library( # Sets the name of the path variable. 29 | log-lib 30 | 31 | # Specifies the name of the NDK library that 32 | # you want CMake to locate. 33 | log ) 34 | 35 | # Specifies libraries CMake should link to your target library. You 36 | # can link multiple libraries, such as libraries you define in this 37 | # build script, prebuilt third-party libraries, or system libraries. 38 | 39 | target_link_libraries( # Specifies the target library. 40 | security 41 | 42 | # Links the target library to the log library 43 | # included in the NDK. 44 | ${log-lib} ) -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 27 5 | defaultConfig { 6 | applicationId "com.chenzhihui.demo" 7 | minSdkVersion 15 8 | targetSdkVersion 27 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | // externalNativeBuild { 13 | // cmake { 14 | // cppFlags "" 15 | // } 16 | // } 17 | } 18 | 19 | signingConfigs { 20 | debug { 21 | storeFile file('./demo.jks') 22 | storePassword "123456" 23 | keyAlias "demoalias" 24 | keyPassword "123456" 25 | } 26 | 27 | release { 28 | storeFile file('./demo.jks') 29 | storePassword "123456" 30 | keyAlias "demoalias" 31 | keyPassword "123456" 32 | } 33 | } 34 | 35 | 36 | 37 | 38 | buildTypes { 39 | 40 | debug { 41 | debuggable true 42 | minifyEnabled false 43 | zipAlignEnabled false 44 | shrinkResources false 45 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 46 | signingConfig signingConfigs.debug 47 | } 48 | release { 49 | debuggable false//注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意注意 50 | minifyEnabled true 51 | zipAlignEnabled true 52 | shrinkResources true 53 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 54 | signingConfig signingConfigs.release 55 | } 56 | 57 | } 58 | 59 | externalNativeBuild { 60 | cmake { 61 | path "CMakeLists.txt" 62 | } 63 | } 64 | } 65 | 66 | dependencies { 67 | implementation fileTree(dir: 'libs', include: ['*.jar']) 68 | implementation 'com.android.support:appcompat-v7:27.1.1' 69 | implementation 'com.android.support.constraint:constraint-layout:1.1.0' 70 | testImplementation 'junit:junit:4.12' 71 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 72 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 73 | } 74 | -------------------------------------------------------------------------------- /app/demo.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/demo.jks -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -keep class com.chenzhihui.demo.SecurityUtil 23 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/chenzhihui/demo/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.chenzhihui.demo; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.chenzhihui.demo", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /app/src/main/cpp/security.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #define LOGINFO(...) ((void)__android_log_print(ANDROID_LOG_INFO, "security", __VA_ARGS__)) 7 | #define LOGERROR(...) ((void)__android_log_print(ANDROID_LOG_ERROR, "security", __VA_ARGS__)) 8 | 9 | static int verifySign(JNIEnv *env); 10 | 11 | jint JNI_OnLoad(JavaVM *vm, void *reserved) { 12 | JNIEnv *env = NULL; 13 | if (vm->GetEnv((void **) &env, JNI_VERSION_1_4) != JNI_OK) { 14 | return JNI_ERR; 15 | } 16 | if (verifySign(env) == JNI_OK) { 17 | return JNI_VERSION_1_4; 18 | } 19 | LOGERROR("签名不一致!"); 20 | return JNI_ERR; 21 | } 22 | 23 | static jobject getApplication(JNIEnv *env) { 24 | jobject application = NULL; 25 | jclass activity_thread_clz = env->FindClass("android/app/ActivityThread"); 26 | if (activity_thread_clz != NULL) { 27 | jmethodID currentApplication = env->GetStaticMethodID( 28 | activity_thread_clz, "currentApplication", "()Landroid/app/Application;"); 29 | if (currentApplication != NULL) { 30 | application = env->CallStaticObjectMethod(activity_thread_clz, currentApplication); 31 | } else { 32 | LOGERROR("Cannot find method: currentApplication() in ActivityThread."); 33 | } 34 | env->DeleteLocalRef(activity_thread_clz); 35 | } else { 36 | LOGERROR("Cannot find class: android.app.ActivityThread"); 37 | } 38 | 39 | return application; 40 | } 41 | 42 | 43 | static const char *SIGN = "308203533082023ba0030201020204691f1618300d06092a864886f70d01010b0500305a310d300b060355040613046368656e310d300b060355040813046368656e310d300b060355040713046368656e310d300b060355040a13046368656e310d300b060355040b13046368656e310d300b060355040313046368656e301e170d3138303432353038323530355a170d3433303431393038323530355a305a310d300b060355040613046368656e310d300b060355040813046368656e310d300b060355040713046368656e310d300b060355040a13046368656e310d300b060355040b13046368656e310d300b060355040313046368656e30820122300d06092a864886f70d01010105000382010f003082010a02820101008001ead218d523543023e195c065fb807f06313a915f510e59d556c55f192163a5acd4300851ae738a601c2b4a6284beb900c31338d4ce36dd3fe490c16560dc4dfca13685a1993c6705976797a5a23841edd261c95a419da6e62ebe17a25b787e1ff2097a9b112f48a3fe03b7777b9833799680bae0a9a1d423296b31a87e65758b6fb56f9ea78c4d0537924663563c8cc59c2877c4ee58704b03f3cd5bdb1383084064be54b0a8de408ca51ecb0c68194fc6adb643d5827053371a34d75d8c98ff7edc4d929747afe48a7e6701d9dfd7897a221ba82b63c27bf2ce8c0784c5810f425526e28b840c429d9f0984b44671d3d5a1b77827f529c7aad6877f3c450203010001a321301f301d0603551d0e0416041403a7a9f045b7ab586c6102c49ced45e8879d350a300d06092a864886f70d01010b050003820101007dc1ae5fabc39101d74987f535be17e9c80b71daf55193b4c6abd381adf59042dabeeebd59d8f2ad1cbe0dd4feaee803e62b9b4b425a0936a4041245b7893a51c40fe0f10ea67a0a00e6360c25c703c5801f8e8740c544ce3d3874620dc26efbf5331020d30ac9e0ae1b217ab841959386a56aab61981ba01a1d62ede59866d936d1ade91d6723ea5569128a6bd5a8158733bb18499f8100a29beee19713be64b82ba348bb4d8eb5591cd5b09323746ccd5b9b115c6c1462f07165070eab6cfd9f18af717e94f384059b72ee3866553adc6d248b7d4a7f945666edb822eb20d2229d3b8c8b1038b1f11640b7a00e8f79623ffedf697da528af1ac828b009af53"; 44 | 45 | static int verifySign(JNIEnv *env) { 46 | // Application object 47 | jobject application = getApplication(env); 48 | if (application == NULL) { 49 | return JNI_ERR; 50 | } 51 | // Context(ContextWrapper) class 52 | jclass context_clz = env->GetObjectClass(application); 53 | // getPackageManager() 54 | jmethodID getPackageManager = env->GetMethodID(context_clz, "getPackageManager", 55 | "()Landroid/content/pm/PackageManager;"); 56 | // android.content.pm.PackageManager object 57 | jobject package_manager = env->CallObjectMethod(application, getPackageManager); 58 | // PackageManager class 59 | jclass package_manager_clz = env->GetObjectClass(package_manager); 60 | // getPackageInfo() 61 | jmethodID getPackageInfo = env->GetMethodID(package_manager_clz, "getPackageInfo", 62 | "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;"); 63 | // context.getPackageName() 64 | jmethodID getPackageName = env->GetMethodID(context_clz, "getPackageName", 65 | "()Ljava/lang/String;"); 66 | // call getPackageName() and cast from jobject to jstring 67 | jstring package_name = (jstring) (env->CallObjectMethod(application, getPackageName)); 68 | // PackageInfo object 69 | jobject package_info = env->CallObjectMethod(package_manager, getPackageInfo, package_name, 64); 70 | // class PackageInfo 71 | jclass package_info_clz = env->GetObjectClass(package_info); 72 | // field signatures 73 | jfieldID signatures_field = env->GetFieldID(package_info_clz, "signatures", 74 | "[Landroid/content/pm/Signature;"); 75 | jobject signatures = env->GetObjectField(package_info, signatures_field); 76 | jobjectArray signatures_array = (jobjectArray) signatures; 77 | jobject signature0 = env->GetObjectArrayElement(signatures_array, 0); 78 | jclass signature_clz = env->GetObjectClass(signature0); 79 | 80 | jmethodID toCharsString = env->GetMethodID(signature_clz, "toCharsString", 81 | "()Ljava/lang/String;"); 82 | // call toCharsString() 83 | jstring signature_str = (jstring) (env->CallObjectMethod(signature0, toCharsString)); 84 | 85 | // release 86 | env->DeleteLocalRef(application); 87 | env->DeleteLocalRef(context_clz); 88 | env->DeleteLocalRef(package_manager); 89 | env->DeleteLocalRef(package_manager_clz); 90 | env->DeleteLocalRef(package_name); 91 | env->DeleteLocalRef(package_info); 92 | env->DeleteLocalRef(package_info_clz); 93 | env->DeleteLocalRef(signatures); 94 | env->DeleteLocalRef(signature0); 95 | env->DeleteLocalRef(signature_clz); 96 | 97 | const char *sign = env->GetStringUTFChars(signature_str, NULL); 98 | if (sign == NULL) { 99 | LOGERROR("分配内存失败"); 100 | return JNI_ERR; 101 | } 102 | //发布记得去掉log!!!!!!! 103 | // LOGINFO("应用中读取到的签名为:%s", sign); 104 | // LOGINFO("native中预置的签名为:%s", SIGN); 105 | int result = strcmp(sign, SIGN); 106 | // LOGINFO("strcmp:%d", result); 107 | // 使用之后要释放这段内存 108 | env->ReleaseStringUTFChars(signature_str, sign); 109 | env->DeleteLocalRef(signature_str); 110 | if (result == 0) { // 签名一致 111 | return JNI_OK; 112 | } 113 | 114 | return JNI_ERR; 115 | } 116 | 117 | 118 | extern "C" JNIEXPORT jstring 119 | 120 | JNICALL 121 | Java_com_chenzhihui_demo_SecurityUtil_getSecret( 122 | JNIEnv *env, 123 | jobject /* this */) { 124 | std::string hello = "hahahahasecrethahahahaha"; 125 | return env->NewStringUTF(hello.c_str()); 126 | } 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /app/src/main/java/com/chenzhihui/demo/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.chenzhihui.demo; 2 | 3 | import android.content.pm.PackageInfo; 4 | import android.content.pm.PackageManager; 5 | import android.content.pm.Signature; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.util.Log; 9 | import android.widget.TextView; 10 | 11 | public class MainActivity extends AppCompatActivity { 12 | 13 | @Override 14 | protected void onCreate(Bundle savedInstanceState) { 15 | super.onCreate(savedInstanceState); 16 | setContentView(R.layout.activity_main); 17 | 18 | TextView tv = findViewById(R.id.sample_text); 19 | String text = "secret = " + SecurityUtil.getSecret() + " sign = " + getSignJava(); 20 | tv.setText(text); 21 | Log.e("sign = ", ""+getSignJava()); 22 | } 23 | 24 | private String getSignJava() { 25 | String sign = ""; 26 | try { 27 | PackageManager pm = getPackageManager(); 28 | PackageInfo pi = pm.getPackageInfo(getPackageName(), PackageManager.GET_SIGNATURES); 29 | Signature[] signatures = pi.signatures; 30 | Signature signature0 = signatures[0]; 31 | sign = signature0.toCharsString(); 32 | } catch (Exception e) { 33 | e.printStackTrace(); 34 | } 35 | return sign; 36 | } 37 | 38 | 39 | } 40 | -------------------------------------------------------------------------------- /app/src/main/java/com/chenzhihui/demo/SecurityUtil.java: -------------------------------------------------------------------------------- 1 | package com.chenzhihui.demo; 2 | 3 | public class SecurityUtil { 4 | static { 5 | System.loadLibrary("security"); 6 | } 7 | 8 | public static native String getSecret(); 9 | } 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #3F51B5 4 | #303F9F 5 | #FF4081 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | SecurityDemo 3 | 4 | -------------------------------------------------------------------------------- /app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/test/java/com/chenzhihui/demo/ExampleUnitTest.java: -------------------------------------------------------------------------------- 1 | package com.chenzhihui.demo; 2 | 3 | import org.junit.Test; 4 | 5 | import static org.junit.Assert.*; 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * @see Testing documentation 11 | */ 12 | public class ExampleUnitTest { 13 | @Test 14 | public void addition_isCorrect() { 15 | assertEquals(4, 2 + 2); 16 | } 17 | } -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | 5 | repositories { 6 | google() 7 | jcenter() 8 | } 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:3.1.1' 11 | 12 | 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | } 23 | } 24 | 25 | task clean(type: Delete) { 26 | delete rootProject.buildDir 27 | } 28 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chenzhihui28/SecurityDemo/d75a949c023398c94867bddb7589092cc1f6b01d/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Apr 25 09:37:10 CST 2018 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | --------------------------------------------------------------------------------