Android 从 APK 文件逆向工程到项目

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12732882/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 11:37:37  来源:igfitidea点击:

Reverse engineering from an APK file to a project

androidapkdecompiling

提问by Marko Cakic

I accidently erased my project from Eclipse, and all I have left is the APKfile which I transferred to my phone. Is there a way to reverse the process of exporting an application to the .apk file, so I can get my project back?

我不小心从Eclipse 中删除了我的项目,剩下的就是我传输到手机上的APK文件。有没有办法逆转将应用程序导出到 .apk 文件的过程,以便我可以恢复我的项目?

回答by rahul

There are two useful tools which will generate Java code (rough but good enough) from an unknown APK file.

有两个有用的工具可以从未知的 APK 文件生成 Java 代码(粗略但足够好)。

  1. Download dex2jar tool from dex2jar.
  2. Use the tool to convert the APK file to JAR:

    $ d2j-dex2jar.bat demo.apk
    dex2jar demo.apk -> ./demo-dex2jar.jar
    
  3. Once the JAR file is generated, use JD-GUIto open the JAR file. You will see the Java files.

  1. dex2jar下载 dex2jar 工具。
  2. 使用该工具将 APK 文件转换为JAR

    $ d2j-dex2jar.bat demo.apk
    dex2jar demo.apk -> ./demo-dex2jar.jar
    
  3. 生成 JAR 文件后,使用JD-GUI打开 JAR 文件。您将看到 Java 文件。

The output will be similar to:

输出将类似于:

JD GUI

京东图形界面

回答by Swapnil Sonar

First of all I recommend thisvideo may this is clears all yours doubts

首先我推荐this视频可能这会清除你所有的疑虑

If not please go through it

如果没有,请通过它

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

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

Step 1:

Step 1:

Make a new folder and put .apk file in it (which you want to decode). Now rename the extension of this .apkfile to .zip(eg.: rename from filename.apk to filename.zip) and save it.

创建一个新文件夹并将 .apk 文件放入其中(您要解码)。现在将此.apk文件的扩展名重命名为.zip(例如:从 filename.apk 重命名为 filename.zip)并保存它。

If problems in the converting into .zip please refers link

如果在转换为 .zip 时出现问题,请参考 link

After getting .zip now you get classes.dex files, etc. At this stage you are able to see drawable but not xml and java files, so continue. If you don't see the extensions go through check the configuration

获得 .zip 后,您将获得 classes.dex 文件等。在此阶段,您可以看到 drawable 但不能看到 xml 和 java 文件,所以继续。如果您没有看到扩展通过检查配置

Step 2:

Step 2:

Now extract this zip apk file in the same folder. Now download dex2jar from this link

现在将这个 zip apk 文件解压缩到同一文件夹中。现在从这里下载 dex2jarlink

and extract it to the same folder. Now open command prompt and change directory to that folder.

并将其解压缩到同一文件夹中。现在打开命令提示符并将目录更改为该文件夹。

Then write dex2jar classes.dexand press enter. Now you get classes.dex.dex2jarfile in the same folder.

然后写入dex2jar classes.dex并按回车键。现在您classes.dex.dex2jar在同一文件夹中获得文件。

Then download java decompiler

然后下载java反编译器

And now double click on jd-gui and click on open file. Then open classes.dex.dex2jarfile from that folder. Now you get class files and save all these class files (click on file then click "save all sources" in jd-gui) by src name. Extract that zip file (classes_dex2jar.src.zip)and you will get all java files of the application.

现在双击 jd-gui 并单击打开文件。然后classes.dex.dex2jar从该文件夹中打开文件。现在您获得类文件并按 src 名称保存所有这些类文件(单击文件,然后在 jd-gui 中单击“保存所有源”)。解压缩该 zip 文件(classes_dex2jar.src.zip),您将获得该应用程序的所有 java 文件。

At this stage you get java source but the xml files are still unreadable, so continue.

在这个阶段,你得到了 java 源代码,但 xml 文件仍然无法读取,所以继续。

Step 3:

Step 3:

Now open another new folder and put these files

现在打开另一个新文件夹并放置这些文件

  1. put .apk file which you want to decode

  2. download Apktool for windows v1.xAnd Apktool

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

  2. 下载 Apktool for windows v1.xAndApktool

install window using google and put in the same folder

使用谷歌安装窗口并放在同一个文件夹中

  1. download framework-res.apk file using google and put in the same folder (Not all apk file need framework-res.apk file)

  2. Open a command window

  3. Navigate to the root directory of APKtool and type the following command: apktool if framework-res.apk.

  1. 使用google下载framework-res.apk文件并放在同一个文件夹中(并非所有apk文件都需要framework-res.apk文件)

  2. 打开命令窗口

  3. 导航到 APKtool 的根目录并键入以下命令: apktool if framework-res.apk.

Above command should result in Framework installed ....

上面的命令应该导致Framework installed ....

  1. apktool d "appName".apk ("appName" denotes application which you want to decode) now you get a file folder in that folder and now you can easily read xml files also.
  1. apktool d "appName".apk(“appName”表示您要解码的应用程序)现在您在该文件夹中获得了一个文件夹,现在您也可以轻松读取 xml 文件。

Step 4:Finally we got the res/as well as java code of project which is our target at starting.

Step 4:最后我们得到了res/项目的以及java代码,这是我们开始的目标。

P.S.If you are not able to get res folder by above steps please do install new apktool

  • Is Java 1.7 installed? Install Apktool 2.x
  • Is Java 1.6 or higher installed? Install Apktool 1.x

P.S.如果您无法通过上述步骤获取 res 文件夹,请安装新的 apktool

  • 是否安装了 Java 1.7? 安装 Apktool 2.x
  • 是否安装了 Java 1.6 或更高版本? 安装 Apktool 1.x

Enjoy and happy coding

Enjoy and happy coding

回答by Ranjith Kumar

No software & No too much steps..

没有软件,没有太多的步骤..

Just upload your APK & get your all resources from this site..

只需上传您的 APK 并从该站点获取您的所有资源..

https://www.apkdecompilers.com/

https://www.apkdecompilers.com/

This website will decompile the code embedded in APK files and extract all the other assets in the file.

该网站将反编译嵌入在 APK 文件中的代码并提取文件中的所有其他资产。

note: I decompile my APK file & get code within one miniute from this website

注意:我反编译我的 APK 文件并在一分钟内从本网站获取代码

Update 1:

更新 1

I found another online decompiler site,

我找到了另一个在线反编译器站点,

http://www.javadecompilers.com/apk/- Not working continuously asking for popup blocking

http://www.javadecompilers.com/apk/- 不连续工作要求弹出窗口阻止

Update 2:

更新 2:

I found apk decompiler app in play store,

我在 Play 商店找到了 apk 反编译器应用程序,

https://play.google.com/store/apps/details?id=com.njlabs.showjava

https://play.google.com/store/apps/details?id=com.njlabs.showjava

We can decompile the apk files in our android phone. and also we can able to view the java & xml files in this application

我们可以在我们的android手机中反编译apk文件。并且我们还可以查看此应用程序中的 java 和 xml 文件

Update 3:

更新 3:

We can use another option Analyze APKfeature from Android studio 2.2 version

我们可以使用Android studio 2.2版本中的另一个选项Analyze APKfeature

Build -> Analyze APK -> Select your APK -> it give results

构建 -> 分析 APK -> 选择你的 APK -> 它给出结果

enter image description here

在此处输入图片说明

回答by Brijesh Masrani

There is a new way to do this.

有一种新方法可以做到这一点。

Android Studio 2.2 has APK Analyzer it will give lot of info about apk, checkout it here :- http://android-developers.blogspot.in/2016/05/android-studio-22-preview-new-ui.html

Android Studio 2.2 具有 APK 分析器,它将提供有关 APK 的大量信息,请在此处查看:- http://android-developers.blogspot.in/2016/05/android-studio-22-preview-new-ui.html

Ap

应用程序

回答by Chris Thompson

Not really. There are a number of dex disassembler/decompiler suites out there such as smali, or dex2jarthat will generate semi-humanreadable output (in the case of dex2jar, you can get java code through the use of something like JD-GUIbut the process is not perfect and it is very unlikely that you'll be able to 100% recreate your source code. However, it could potentially give you a place to start rebuilding your source tree.

并不真地。有许多 dex 反汇编器/反编译器套件,例如 smalidex2jar,它们将生成半人类可读的输出(在 dex2jar 的情况下,您可以通过使用诸如JD-GUI 之类的东西来获取 Java 代码,但过程是不完美,您不太可能 100% 重新创建源代码。但是,它可能为您提供一个开始重建源代码树的地方。

回答by Star

Yes, you can get your project back. Just rename the yourproject.apkfile to yourproject.zip, and you will get all the files inside that ZIP file. We are changing the file extension from .apk to .zip. From that ZIP file, extract the classes.dexfile and decompile it by following way.

是的,您可以恢复您的项目。只需将yourproject.apk文件重命名为yourproject.zip,您将获得该 ZIP 文件中的所有文件。我们正在将文件扩展名从 .apk 更改为 .zip。从该 ZIP 文件中,提取classes.dex文件并通过以下方式反编译。

First, you need a tool to extract all the (compiled) classes on the DEX to a JAR. There's one called dex2jar, which is made by a Chinese student.

首先,您需要一个工具将 DEX 上的所有(已编译)类提取到 JAR 中。有一个叫dex2jar 的,是一个中国学生做的。

Then, you can use JD-GUIto decompile the classes in the JAR to source code. The resulting source code should be quite readable, as dex2jar applies some optimizations.

然后,您可以使用JD-GUI将 JAR 中的类反编译为源代码。生成的源代码应该非常易读,因为 dex2jar 应用了一些优化。

回答by Stephane Piriou

For the Android platform, you can try ShowJava, available on the Play Store.

对于 Android 平台,您可以尝试Play 商店中提供的ShowJava

You can consult the generated code through the app interface and the generated java files and folders structure are stored in ShowJavafolder in /sdcard, alongside the resulting .jarfile from the conversion.

您可以通过应用程序界面查看生成的代码,生成的 java 文件和文件夹结构存储在ShowJava文件夹 in 中/sdcard,与.jar转换的结果文件一起存储。

The app is free with an ad banner at the bottom of the main view, but there is an in-app purchase option (3,99$) to remove it. In-app purchase does not add any functionality beside removing the ad banner.

该应用程序是免费的,主视图底部有一个广告横幅,但有一个应用程序内购买选项(3.99 美元)可以将其删除。除了移除广告横幅外,应用内购买不会添加任何功能。

Disclosure : I'm not the developer of the app neither I'm affiliated with him in any way.

披露:我不是该应用程序的开发者,也不与他有任何关联。

回答by Imran Qamer

In Android Studio 3.5, It's soo easy that you can just achieve it in a minute. following is a step wise process.

在 Android Studio 3.5 中,您可以在一分钟内实现它,这太容易了。以下是一个循序渐进的过程。

1:Open Android Studio, Press window button -> Type Android Studio -> click on icon to open android studio splash screen which will look like this.

1:打开Android Studio,按窗口按钮->输入Android Studio->点击图标打开android studio启动画面,如下所示。

enter image description here

在此处输入图片说明

2:Here you can see an option "Profile or debug APK"click on it and select your apk file and press ok.

2:在这里你可以看到一个选项“配置文件或调试APK”点击它并选择你的apk文件并按确定。

enter image description here

在此处输入图片说明

3:It will open all your manifest and java classes with in a minute depending upon size of apk.

3:它会在一分钟内打开您所有的清单和 java 类,具体取决于 apk 的大小。

enter image description here

在此处输入图片说明

That's it.

就是这样。

回答by Qing Xu

Try this tool: https://decompile.io, it runs on iPhone/iPad/Mac enter image description here

试试这个工具:https: //decompile.io,它在 iPhone/iPad/Mac 上运行 在此处输入图片说明

回答by Nick

If you are looking for a professional alternative, have a look at JEB Decompilerfrom PNF Software.

如果您正在寻找专业的替代方案,请查看PNF Software 的JEB Decompiler

There is a demo version that will let you decompile most code.

有一个演示版本可以让您反编译大多数代码。