Because its code is managed code placed on a Dalvik virtual machine, Android can easily decompile it into code that we can identify.
I've written an article that apk the Android package to the Smali file and then recompile the signature to implement the tamper-apk functionality.
Recently, there is a new way to implement the Classes.dex file directly from the Android APK package, decompile the DEX code to the Java. class binary code, and then decompile it from the. Class binary code to the Java source code presumably I don't have to say more.
First, the tools we need are Dex2jar and Jd-gui.
The first tool, Dex2jar, is used to translate the Classex.dex file, which is the Dex binary code, into Java. class binary code, then the Jd-gui is the standard. Class binary code and then decompile to Java source code.
First, extract the Classes.dex from the APK package.
Put it in the Dex2jar directory.
Then execute at the command line
Dex2jar.bat Classes.dex
When the execution succeeds, a Classes.dex.dex2jar.jar file is generated
This file is then opened with Jd-gui, as shown below
Almost like the source code of the program I wrote myself.
This decompile method is mainly used to study and research, and there are questions that can be discussed with my email.
I hope we do not use this method to engage in malicious activities, after all, others toil to write the program is not easy, with this method can be roughly learned to write the logic of other people's programs, architecture, hope for everyone to help.
The experience of Android reverse APK program
This article mainly introduces how to reverse an Android APK application, this article provides the method only for research study.
The tools you need to use in this article are
JDK this is used to build the Java Runtime Environment
Axmlprinter2.jar This is used in reverse. xml files
Baksmali.jar this for reverse Classex.dex file
Because the Android. apk file is actually a zip file that can be opened directly with WinRAR
As shown in the following illustration:
Opened with RAR we can see that the file is actually a ZIP package containing the Meta-inf folder, which is used to save the signature file to ensure the integrity of the package
Res folder is the APK to use the resource files, are preserved intact, we can directly extract, do the Chinese can read the string file directly and then modify
The Androidmanifest.xml file is a compiled configuration file that declares the Activity,service contained in the program and the capabilities of the program, that is, permissions. RESOURCES.ARSC is a compiled resource specification file, and the main concern is classes.dex. The Android program we write, all of the. java files in the source program, are eventually compiled into 1. Dex files, which are executed on the Dalvik virtual machine on the Android phone.
First, we introduce how to reverse an. xml file
Because the XML file in the APK package we open it directly with Notepad or some garbled
So we need to restore to be able to better see
We need to use the Axmlprinter2.jar tool here.
The specific is to open the command line we take Androidmanifest.xml as an example, enter the following command
Java-jar Axmlprinter2.jar androidmanifest.xml > AndroidManifest.txt
Interested can also be written as a. bat script for easy execution
We can look at the results of the execution.
Androidmanifest.xml files prior to execution
After execution, we can look at it again.
Copy Code code as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest
Xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:versioncode= "322"
Android:versionname= "ver 3.2.2"
Package= "Com.eoeandroid.wallpapers.christmas"
>
<application
Android:label= "@7f040000"
android:icon= "@7f020004"
>
<activity
Android:label= "@7f040001"
Android:name= ". Main "
>
<intent-filter
>
<action
Android:name= "Android.intent.action.MAIN"
>
</action>
<category
Android:name= "Android.intent.category.LAUNCHER"
>
</category>
</intent-filter>
</activity>
<service
Android:name= ". Service. Syncdeviceinfosservice "
>
</service>
<meta-data
Android:name= "Com.mobclix.APPLICATION_ID"
Android:value= "30C0E2BB-A878-43CB-830B-A39FCAE33B0C"
>
</meta-data>
</application>
<uses-sdk
Android:minsdkversion= "3"
>
</uses-sdk>
<uses-permission
Android:name= "Android.permission.INTERNET"
>
</uses-permission>
<uses-permission
Android:name= "Android.permission.SET_WALLPAPER"
>
</uses-permission>
<uses-permission
Android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"
>
</uses-permission>
<uses-permission
Android:name= "Android.permission.ACCESS_NETWORK_STATE"
>
</uses-permission>
<uses-permission
Android:name= "Android.permission.READ_PHONE_STATE"
>
</uses-permission>
<uses-permission
Android:name= "Android.permission.ACCESS_NETWORK_STATE"
>
</uses-permission>
</manifest>
Basically can restore the same as the source program
Here, I'm taking the EoE. A wallpaper program for example
Next, we must be more concerned about the classes.dex of the reverse
This is actually similar to the previous one.
Using the Baksmali.jar tool, a foreign study of Android is very deep in Daniel's
Executing code
Java-jar Baksmali.jar-o Classout/classes.dex
Speaking classes.dex can reverse into a folder
Here I can cut a picture for you to see
To open one of the files.
Do you think this code is very kind, from this code we can basically infer some of the source program structure flow from the reference, this article is only for research and learning, welcome to discuss the exchange with me