有没有办法从 APK 文件中获取源代码? [英] Is there a way to get the source code from an APK file?

查看:286
本文介绍了有没有办法从 APK 文件中获取源代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我笔记本电脑的硬盘刚刚崩溃,我丢失了过去两个月一直在开发的应用程序的所有源代码.我所拥有的只是我发送给朋友时存储在我的电子邮件中的 APK 文件.

有没有办法从这个 APK 文件中提取我的源代码?

解决方案

简单方法:使用在线工具https://www.decompiler.com/,上传apk获取源码.


解码.apk文件的步骤,分步方法:

第 1 步:

  1. 创建一个新文件夹并复制您要解码的 .apk 文件.

  2. 现在将这个 .apk 文件的扩展名重命名为 .zip(例如,从 filename.apk 重命名为 filename.zip)并保存它.现在你可以访问 classes.dex 文件等.在这个阶段你可以看到 drawables 但不能看到 xml 和 java 文件,所以继续.

第 2 步:

  1. 现在将此 .zip 文件解压缩到同一文件夹(或新文件夹)中.

  2. 下载 dex2jar 并将其解压缩到同一文件夹(或新文件夹).

  3. 将 classes.dex 文件移动到 dex2jar 文件夹中.

  4. 现在打开命令提示符并将目录更改为该文件夹(或新文件夹).然后写d2j-dex2jar classes.dex(mac终端或ubuntu写./d2j-dex2jar.sh classes.dex)回车.您现在在同一文件夹中拥有 classes.dex.dex2jar 文件.

  5. 下载java反编译器,双击jd-gui,点击打开文件,打开该文件夹中的 classes.dex.dex2jar 文件:现在您获得了类文件.

  6. 按 src 名称保存所有这些类文件(在 jd-gui 中,单击 File -> Save All Sources).在此阶段,您获得了 java 源代码,但 .xml 文件仍然无法读取,因此请继续.

第 3 步:

现在打开另一个新文件夹

  1. 放入要解码的.apk文件

  2. 下载最新版本的apktool AND apktool 安装窗口(两者都可以从同一个链接下载)并将它们放在同一个文件夹中

  3. 打开命令窗口

  4. 现在运行像 apktool if framework-res.apk 这样的命令(如果你没有它 在此处获取) 和下一个

  5. apktool d myApp.apk(其中 myApp.apk 表示您要解码的文件名)

现在您在该文件夹中获得了一个文件夹,可以轻松读取 apk 的 xml 文件.

第 4 步:

这不是任何步骤,只需将两个文件夹(在本例中为两个新文件夹)的内容复制到一个文件夹中

并享受源代码...

The hard drive on my laptop just crashed and I lost all the source code for an app that I have been working on for the past two months. All I have is the APK file that is stored in my email from when I sent it to a friend.

Is there any way to extract my source code from this APK file?

解决方案

Simple way: use online tool https://www.decompiler.com/, upload apk and get source code.


Procedure for decoding .apk files, step-by-step method:

Step 1:

  1. Make a new folder and copy over the .apk file that you want to decode.

  2. Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.

Step 2:

  1. Now extract this .zip file in the same folder (or NEW FOLDER).

  2. Download dex2jar and extract it to the same folder (or NEW FOLDER).

  3. Move the classes.dex file into the dex2jar folder.

  4. Now open command prompt and change directory to that folder (or NEW FOLDER). Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex) and press enter. You now have the classes.dex.dex2jar file in the same folder.

  5. Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.

  6. Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.

Step 3:

Now open another new folder

  1. Put in the .apk file which you want to decode

  2. Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder

  3. Open a command window

  4. Now run command like apktool if framework-res.apk (if you don't have it get it here)and next

  5. apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)

now you get a file folder in that folder and can easily read the apk's xml files.

Step 4:

It's not any step, just copy contents of both folders(in this case, both new folders) to the single one

and enjoy the source code...

这篇关于有没有办法从 APK 文件中获取源代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆