Android decompile APK to get code & resources

Introduction to this section

"Decompile Apk" looks like a very high-end look, but in fact it is not, it is to decompile our APK through some decompilation software, so as to obtain the source code, pictures, XML resources and other files of the program; I don't know Have you ever done this before, seeing someone else’s APP interface is very beautifully done, or you fancy someone else’s picture material, to be simple, we can download someone else’s APK, and then change the suffix name to xxx. zip, and then decompress: The author just uncompressed an APK:

We can open the res directory to get the picture material inside

However, with this method, only bitmap file resources such as .png or .jpg can be obtained. If it is an xml resource, we will find garbled characters when we open it. And if we want to see the Java code of the APK program, It also doesn't work, because they are all packed into the classes.dex file! But decompilation can solve your needs~ In addition, don’t use decompilation to do illegal things, such as repackaging other people’s APKs, using your own signature and then releasing them to the relevant market... In addition, we refer to other people’s codes , not a full copy! ! ! Remember! !

1. Three tools to prepare

  1. apktool: Get resource files, extract image files, layout files, and some XML resource files
  2. dex2jar: decompile APK into Java source code (convert classes.dex into jar file)
  3. jd-gui: View the converted jar file in 2, that is, view the Java file. For the convenience of readers, here are the three packaged together and put them in the cloud disk, and you can download them if you need them: three tools related to decompilation  . zip

2. Use apktool to decompile APK to obtain images and XML resources:

After decompressing the downloaded apktool, we can see the following files (ignoring the two csdn, one is the decompiled apk, and the other is the decompiled file):

 Next, double-click cmd.exe to come to the command line, type:  apktool.bat d csdn.apk  , and press Enter:

Then you can see the generated csdn folder, which contains the resources we want 

 Ok, the XML resource is here, right? The image material is also available!


3. Use dex2jar to convert classes.dex into a jar file:

Unzip the downloaded dex2jar folder, and copy the classes.dex in the decompressed apk to the directory where dex2jar.bat is located:

Open cmd and come to this directory: type: d2j-dex2jar.bat classes.dex

Then we can see that a jar package is generated:

 Ok, conversion complete!


4. Use jd-gui to view the Java code in the jar package:

Ok, open the jd-gui folder

After opening, open the converted jar package in our 3, we can see the code inside:

 The csdn client does not confuse the code...Maybe it is in the spirit of open source, let us learn the code! Generally speaking, the release of apk will be confused, and then some encryption will be performed, or a third-party encryption platform will be used, and the "love encryption" is used more often. If you are interested, you can also check the more detailed introduction on Baidu!

Guess you like

Origin blog.csdn.net/leyang0910/article/details/130893488