Now many apk in development in order to ensure that the code is not easy to reverse out of the key code to adopt the NDK development approach.
What is the Android NDK?
The Android NDK (Native Development Kit) is a set of tools that allow you to implement parts of your application in the same way as the C + + language. At the same time, the Android NDK is just a component of the Android SDK, which can help us generate a JNI-compatible shared library that runs on an arm CPU larger than the Android1.5 platform, and copies the generated shared library to the appropriate program engineering path location. To ensure that they are automatically added to your APK package.
So learning to analyze. So files (loading process, mode, etc.) is more important to Android in reverse.
So, how do you analyze Java layer function calls in general?
by System.loadlibrary find the corresponding so file of the method, using Ida loading to find the export function, native function registration two forms:
Static registration: Java_xxx_xxx_xxx_ Class Name _ Method name (parameter)
Dynamic registration: Registernatives
When Android loads a. So file, it first looks at whether the. Init or. Init_array segment exists, and if so, run the content first, and if it does not exist, then check if there is a jni_onload presence.
Actually analyze a crackme.apk bar.
1) decompile apk file to get Smali code
After analysis, you can see that the check function that is defined in the. so file is called, and then the check function is bound to the OnClick event of the button, which can be used to determine if the check is the correct function for the user to enter key.
2) Analysis of libqtfreet.so with IDA
First of all, see if there is java_com_qtfreet_crackme001_check such a function, if there is a. So file does not dynamically register the check function, java_com_qtfreet_crackme001_ Check is the Check function prototype called in Smali, directly analysis can be.
If no such function is found, then the check function called by Smali is dynamically registered, and the registered location needs to be found.
Because. Init or. Init_array is not displayed at the time of IDA dynamic debugging, so it is necessary to statically analyze the offset of these two sections and then calculate the absolute position when dynamically debugging, and then make code (shortcut: C) so that you can see the contents of the content within that paragraph.
There are two ways to view the address of the. Init_array segment:
1. You can use IDA to load the. So file and create a new "segments" view that lists the different types of code snippet information, as shown in.
2. You can use the binary tool readelf to view the structure of the. So file, which can be replaced with greadelf on OS x.
3) You can see both of these instructions. Init_array exists, and the offset is 0x20790,ida to the location to view.
After Init_array executes, it jumps to jni_onload, and IDA jumps to jni_onload F5 the pseudo-code.
See the highlighted registernatives, go in the third parameter off_21458 location to view the saved content.
4) You can see that this is the last execution of a memcmp so you can be sure that sub_8a64 start is the key judgment code, directly memcmp the return value modification can be successfully cracked crackme.
Android Reverse Combat (i)