Reverse engineering for beginners. Protect Android applications from reverse engineering

Sometimes someone wants to see, but what is the filling in a particular program? Then he has to use reverse engineering. What it is? How does it work? How is this process going? You can learn about all this from this article.

What is reverse engineering software?

reverse engineering
This is the name of the application parsing process in order to understand how it works in order to recreate this process in the future with the necessary changes. Typically, a debugger and assembler are used for these purposes. Depending on the quality of the software used, the result and the amount of time that needs to be spent on its normalization will differ. Explaining reverse engineering for beginners is best done with an example. This will be an application written for Android. And now let's find out what and how.

Work with Android applications

reverse engineering programs
First you need to clarify some points. Applications use bytecode and LogCat. These are local counterparts to the previously mentioned debugger and assembler. It is also necessary to understand the structure of the applications themselves. So, each program is a file with the apk extension. It is packed with zip. We are interested in its contents - application resources, classes.dex and AndroidManifest.xml. If you are programming on Android, then there should be no questions with the first and last. But classes.dex is the bytecode of the program, which is compiled specifically for the virtual machine. It is not possible to get the java source code from the means presented on the Internet. But it is possible to get dalvik opcodes - a special set of commands that are used for a virtual machine. For analogy, we can say that this is an assembler of the local spill. Also classes.dex can be turned into a file with the jar extension. Already in this case, after its decompilation, you can get java code that will be more or less readable. This is the way we will go.

Decompilation

This process will be carried out using the Apk Manger program. Before starting work, you need to make sure that there are the necessary drivers for the device to work, and also the USB-debugging mode is functioning. Initially, we will need to move the file, which will be parsed into the apk_manager \ place-apk-here-for-modding directive. After that you should run Script.bat. If there are no problems, then the console will start, on which there will be green labels. Select item number nine - β€œDecompile”. After the process is started, it is necessary not to close the console. Then you should open the apk file of interest using the archiver and extract classes.dex from it, which you need to process with the dex2jar program. For the result we need, we need to move it to an object with the extension .bat. A file appears that ends in .jar. So far, the window does not close.

Analyzing data

reverse engineering for beginners
To get information about the application, you must open its manifest. According to it, we determine what acts as the main activity. It is this that is of the greatest importance to us now. It is also advisable to look at the very bottom of the program. If below is information about the license manager, this will significantly complicate the implementation of reverse engineering. If we switch to jd-gui and expand the tree, we will see several namespaces. Let's say there are three of them. The first contains files related to advertising. The second will be the classes of the license manager. In the third, we find the necessary data. And we enter it. Here it will be necessary to find and delete the key, and then the rest of the lines that check whether the working version is licensed. All this needs to be cleaned. Then in our Apk Manager we look for the place where it is indicated to place the bytecode. Now let's digress a bit and comment out the commands that could potentially cause problems. After that, we only need to compile the program.

Build application

reverse engineering android applications
The Apk Manager will help us with this. In the console window, which we did not close, select item No. 14. Further, a matter of technology. If the application is quite complex, then at startup it may partially or completely lose its performance. Do not worry, this means that we are only halfway and there is still where to go. We continue to reverse engineer Android applications. To say what needs to be done in a particular case, in general terms, alas, is impossible. Therefore, you have to look for the problem place yourself. So, if the application window is blocked by a pop-up window, then you need to view the code and delete that part of it that is responsible for this dialog. Jd-gui can help with this. As you can see, reverse engineering is not easy, and it requires a significant amount of knowledge. Even if everything started without problems, it will be necessary to test the application's performance. That is, reverse engineering is still time-consuming action. We continue to work until all problems are identified.

Security

But what if we need to protect Android applications from reverse engineering? In this case, there are two options: the use of special programs or the creation of a code construct that will interfere with the analysis of the written. The latter option is suitable exclusively for experienced professionals, so we will consider only the first method of protection. We use ProGuard as specialized software. This application is used to reduce, obfuscate, and optimize code. If the program is "run" through it, then we will get a file with the * .apk extension of a smaller size than it was. In this case, it will be much more difficult to disassemble. Moreover, the advantage of this program is that it was even introduced into the assembly system of Android applications with the r9 update. Therefore, any developer who has standard creation and development tools can use it.

Conclusion

protection of android applications from reverse engineering
This is not to say that reverse engineering can be thought of as uniformly bad or good. Of course, from the point of view of the developers who created the application, this is not a happy event at all. But on the other hand, in many cases, writing experienced files by experienced programmers can be less time consuming than using such tools. Although reverse engineering can do a good job for novice developers, if there is no idea how to implement something, even rough and not quite clear drafts can help achieve this goal.

Source: https://habr.com/ru/post/C5497/


All Articles