Hiding sensitive information from NDK learning in Android

Source: Internet
Author: User

Because Android apps are decompiled to see the information in it, and some sensitive information, such as the server IP address and encryption algorithm, we do not want to let others know. How can we hide this information? As far as I know, we can use Android NDK to compile the data in the so file and obtain it through JNI to protect sensitive information, that is, NDK hides sensitive information.
As a result, I have been studying Android NDK development in the last few days. There are many tutorials on the Internet, but it is too troublesome. I will configure it later and it will be very easy to be discouraged.
After successfully running Hello JNI, I want to write a blog and record my problems. If you can help kids shoes that are equally interested in Android NDK, it would be better.
First download the related tools:
1.Download the latest Android developer tools
This is also called ADT. It is an Android Integrated Development Tool recently released by google. After decompression, there are two directories: eclipse and sdk. the eclipse directory is a customized eclipse with sdk plug-ins, ndk plug-ins, c/c (CDT) and other plug-ins installed, less than 400 mb, the sdk directory contains the latest API-level android sdk. We recommend that you download this ADT. If you have downloaded sdks of various versions before, you can copy them and use them normally.
If you do not want to download, you need to install C/C (CDT) and NDK plug-ins in your eclipse.
2.Download Android NDK 294 M
3.If you are a windows user, you may have to install Cygwin 1.7.
We strongly recommend that you abandon windows. In this way, you do not need to do step 3.

Create a project as follows:
1.Create an Android Project
2.Right-click Android Tools and choose Add Native Support.

Enter the name of the so library file. If you have used Baidu map, you should be familiar with this so file. It is located in the armeabi folder in the libs directory of the project, generally libxxxx. so, I entered AppConfig here. After compilation is successful, libAppConfig will be generated. so file. Click "OK". eclipse will change to the C/C editing view. The ndk plug-in will help you create a jni directory under the project and create AppConfig under jni. cpp file and an Android. mk File

Android. mk contains the following content:

 
 
  1. LOCAL_PATH := $(call my-dir) 
  2. include $(CLEAR_VARS) 
  3. LOCAL_MODULE    := AppConfig 
  4. LOCAL_SRC_FILES := AppConfig.cpp 
  5. include $(BUILD_SHARED_LIBRARY) 

AppConfig. cpp has only one line of code: # include <jni. h>

Next, many tutorials on the Internet use javah to generate. h header files.
I follow the procedure below:
1. Write a java class with a native method of getAppUrl (). Because I want to hide the server address, a String is returned here.

 
 
  1. Public class JNIInterface {
  2. Static {
  3. // Load the libAppConfig. so Library File
  4. // AppConfig is the name entered when Android Native Support is added.
  5. // In addition, you can modify the name of LOCAL_MODULE in Android. mk.
  6. System. loadLibrary ("AppConfig ");
  7. }
  8. Public static native String getAppUrl ();
  9. }

2. Compile the AppConfig. cpp file.

 
 
  1. #include <jni.h> 
  2. extern "C" 
  3. jstring  
  4. Java_com_loveplusplus_hellojni_JNIInterface_getAppUrl(JNIEnv* env,jobject thiz) { 
  5. //return (*env)->NewStringUTF(env,"http://www.baidu.com"); //c 
  6. return env->NewStringUTF("http://www.baidu.com"); 

First line of code: Introduce the jni. h header file
The second line of code: Because the c is used here, the size of extern "C" C is
Line 3 Code: The getAppUrl method of the JNIInterface class just written is located in the com. loveplusplus. hellojni package. Therefore, there is a fixed syntax: Java package name class name_method name. This is actually the same as using javah to generate header files in other tutorials. JNIEnv * env and jobject thiz are fixed input parameters.
Line 4 Code: This line of commented-out code is written in C language to return strings
Code of the fifth line: returns a string.

Click the hammer in the red circle, and ndk will compile AppConfig. cpp into the libAppConfig. so file.
Run the following command:

I have studied how to hide sensitive information in androidNDK and share my experiences with you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.