简体   繁体   English

反编译APK,修改后重新编译

[英]Decompile an APK, modify it and then recompile it

I need to modify an existing APK, modify the sources and then recompile it.我需要修改现有的 APK,修改源代码,然后重新编译它。

  • I can decompile it using dex2jar or apktool, it's working great我可以使用 dex2jar 或 apktool 反编译它,效果很好
  • From the jar file I can obtain the java sources (using jd-gui)从 jar 文件我可以获得 java 源代码(使用 jd-gui)
  • Then I can modify the java files然后我可以修改java文件

But now I would like to know how to recompile the java files and put them back into a jar file!但是现在我想知道如何重新编译java文件并将它们放回jar文件中! (the jar part should be easy, the main problem seems to be how to recompile the java files for android) (jar部分应该很简单,主要问题似乎是如何重新编译android的java文件)

I know that an other solution is to use apktool and then modify the smali files, but it seems to be really complicated when we want to add a lot of code!我知道另一种解决方案是使用apktool,然后修改smali文件,但是当我们要添加很多代码时似乎真的很复杂!

My application is a basic a HelloWorld whitout obfuscation.我的应用程序是一个基本的 HelloWorld whitout 混淆。

Thanks to Chris Jester-Young I managed to make it work!感谢 Chris Jester-Young,我设法让它发挥作用!

I think the way I managed to do it will work only on really simple projects:我认为我设法做到的方式只适用于非常简单的项目:

  • With Dex2jar I obtained the Jar.使用 Dex2jar 我获得了 Jar。
  • With jd-gui I convert my Jar back to Java files.使用 jd-gui,我将 Jar 转换回 Java 文件。
  • With apktool i got the android manifest and the resources files.使用 apktool 我得到了 android 清单和资源文件。

  • In Eclipse I create a new project with the same settings as the old one (checking all the information in the manifest file)在 Eclipse 中,我创建了一个与旧项目具有相同设置的新项目(检查清单文件中的所有信息)

  • When the project is created I'm replacing all the resources and the manifest with the ones I obtained with apktool创建项目后,我将所有资源和清单替换为我通过 apktool 获得的资源和清单
  • I paste the java files I extracted from the Jar in the src folder (respecting the packages)我将从 Jar 中提取的 java 文件粘贴到 src 文件夹中(尊重包)
  • I modify those files with what I need我用我需要的东西修改这些文件
  • Everything is compiling!一切都在编译!

/!\\ be sure you removed the old apk from the device an error will be thrown stating that the apk signature is not the same as the old one! /!\\ 确保您从设备中删除了旧的 apk,将会抛出错误,指出 apk 签名与旧的签名不同!

I know this question is answered still, I would like to pass an information how to get source code from apk with out dexjar.我知道这个问题仍然有答案,我想传递一个信息,如何在没有 dexjar 的情况下从 apk 获取源代码。

There is an online decompiler for android apks一个适用于 android apks的在线反编译器

  1. Upload apk from local machine从本地机器上传apk
  2. Wait some moments稍等片刻
  3. Download source code in zip format下载 zip 格式的源代码

I don't know how reliable is this.我不知道这有多可靠。

@darkheir Answer is the manual way to do decompile apk. @darkheir答案是手动反编译 apk 的方法。 It helps us to understand different phases in Apk creation.它帮助我们了解 Apk 创建的不同阶段。

Once you have source code , follow the step mentioned in the accepted answer获得源代码后,请按照已接受的答案中提到的步骤进行操作

Report so many ads on this links Another online Apk De-compiler @Andrew Rukin : http://www.javadecompilers.com/apk在此链接上报告这么多广告另一个在线 Apk 反编译器@Andrew Rukinhttp : //www.javadecompilers.com/apk

Still worth.还是值得的。 Hats Off to creators.向创作者致敬。

The answers are already kind of outdated or not complete.答案已经过时或不完整。 This maybe works for non-protected apks (no Proguard), but nowadays nobody deploys an unprotected apk.这可能适用于不受保护的 apk(没有 Proguard),但现在没有人部署不受保护的 apk。 The way I was able to modify a (my) well-protected apk (Proguard, security check which checks for "hacking tools", security check, which checks if the app is repackaged with debug mode,...) is via apktool as already mentioned by other ones here.我能够修改(我的)受到良好保护的 apk 的方式(Proguard,检查“黑客工具”的安全检查,检查应用程序是否使用调试模式重新打包的安全检查,...)是通过 apktool 作为其他人已经在这里提到过。 But nobody explained, that you have to sign the app again.但是没有人解释说,您必须再次签署该应用程序。

apktool d app.apk
//generates a folder with smali bytecode files. 

//Do something with it.

apktool b [folder name] -o modified.apk
//generates the modified apk.

//and then
jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore ~/.android/debug.keystore modified.apk androiddebugkey
//signs the app the the debug key (the password is android)

//this apk can be installed on a device.

In my test, the original release apk had no logging.在我的测试中,原始版本的 apk 没有日志记录。 After I decompiled with apktool I exchanged a full byte code file without logging by a full byte code file with logging, re-compiled and signed it and I was able to install it on my device.在我用 apktool 反编译后,我交换了一个完整的字节码文件,而没有通过带有日志记录的完整字节码文件进行记录,重新编译并对其进行签名,然后我就可以将它安装在我的设备上。 Afterwards I was able to see the logs in Android Studio as I connected the app to it.之后,当我将应用程序连接到它时,我能够在 Android Studio 中看到日志。

In my opinion, decompiling with dex2jar and JD-GUI is only helpful to get a better understanding what the classes are doing, just for reading purposes.在我看来,使用dex2jarJD-GUI反编译只会有助于更好地理解类在做什么,仅用于阅读目的。 But since everything is proguarded, I'm not sure that you can ever re-compile this half-baked Java code to a working apk.但是由于一切都经过了保护,我不确定您是否可以将这个半生不熟的 Java 代码重新编译为可用的 apk。 If so, please let me know.如果是这样,请告诉我。 I think, the only way is to manipulate the byte code itself as mentioned in this example.我认为,唯一的方法是操作本示例中提到的字节码本身。

  1. First download the dex2jar tool from Following link http://code.google.com/p/dex2jar/downloads/list首先从以下链接下载 dex2jar 工具http://code.google.com/p/dex2jar/downloads/list

  2. Extract the file it create dex2jar folder解压它创建的文件dex2jar文件夹

  3. Now you pick your apk file and change its extension .apk to .zip after changing extension it seems to be zip file then extract this zip file you found classes.dex file现在您选择您的 apk 文件并将其扩展名 .apk 更改为 .zip 更改扩展名后它似乎是 zip 文件,然后解压缩您找到的这个 zip 文件classes.dex文件

  4. Now pick classes.dex file and put it into dex2jar folder现在选择 classes.dex 文件并将其放入dex2jar文件夹

  5. Now open cmd window and type the path of dex2jar folder现在打开cmd窗口并输入dex2jar文件夹的路径

  6. Now type the command dex2jar.bat classes.dex and press Enter现在输入命令dex2jar.bat classes.dex并按 Enter

  7. Now Open the dex2jar folder you found classes_dex2jar.jar file现在打开你找到classes_dex2jar.jar文件的dex2jar文件夹

  8. Next you download the java decompiler tool from the following link http://java.decompiler.free.fr/?q=jdgui接下来从以下链接下载java反编译工具http://java.decompiler.free.fr/?q=jdgui

  9. Last Step Open the file classes_dex2jar.jar in java decompiler tool now you can see apk code最后一步在java反编译工具中打开文件classes_dex2jar.jar ,现在可以看到apk代码了

I know this question has been answered and I am not trying to give better answer here.我知道这个问题已经得到回答,我不想在这里给出更好的答案。 I'll just share my experience in this topic.我只会分享我在这个主题上的经验。

Once I lost my code and I had the apk file only.一旦我丢失了我的代码并且我只有apk文件。 I decompiled it using the tool below and it made my day.我使用下面的工具对它进行了反编译,这让我很开心。

These tools MUST be used in such situation, otherwise, it is unethical and even sometimes it is illegal, (stealing somebody else's effort).这些工具必须在这种情况下使用,否则是不道德的,甚至有时是非法的(窃取别人的努力)。 So please use it wisely.所以请明智地使用它。

Those are my favorite tools for doing that:这些是我最喜欢的工具:

javadecompilers.com javadecompilers.com

and to get the apk from google play you can google it or check out those sites:要从 google play 获取 apk,您可以在 google 上搜索或查看这些网站:

On the date of posting this answer I tested all the links and it worked perfect for me.在发布此答案之日,我测试了所有链接,它对我来说非常有用。

NOTE: Apk Decompiling is not effective in case of proguarded code.注意: Apk 反编译在代码保护的情况下无效。 Because Proguard shrink and obfuscates the code and rename classes to nonsense names which make it fairly hard to understand the code.因为Proguard 会缩小和混淆代码并将类重命名为无意义的名称,这使得理解代码变得相当困难。

Bonus:奖金:

Basic tutorial of Using Proguard :使用 Proguard 的基本教程

dex2jar with jd-gui will give all the java source files but they are not exactly the same.带有jd-gui 的dex2jar将提供所有 java 源文件,但它们并不完全相同。 They are almost equivalent .class files (not 100%).它们几乎是等效的 .class 文件(不是 100%)。 So if you want to change the code for an apk file:因此,如果您想更改 apk 文件的代码:

  • decompile using apktool使用apktool反编译

  • apktool will generate smali(Assembly version of dex) file for every java file with same name. apktool将为每个同名的 java 文件生成 smali(dex 的汇编版本)文件。

  • smali is human understandable, make changes in the relevant file, recompile using same apktool ( apktool b Nw.apk <Folder Containing Modified Files> ) smali 是人类可以理解的,在相关文件中进行更改,使用相同的apktool重新编译( apktool b Nw.apk <Folder Containing Modified Files>

Use luckypatcher and remove your license verification than you do not have to sign apk. 使用luckypatcher并删除您的许可证验证,而不是您必须签署apk。 Use WINRAR to replace your modified source code without decompile apk. 使用WINRAR替换修改后的源代码而不反编译apk。

This is a way:这是一种方式:

  1. Using apktool to decode:使用apktool解码:

     $ apktool d -f {apkfile} -o {output folder}
  2. Next, using JADX (at github.com/skylot/jadx)接下来,使用 JADX(在 github.com/skylot/jadx)

     $ jadx -d {output folder} {apkfile}

2 tools extract and decompiler to same output folder. 2 个工具提取和反编译到同一个输出文件夹。

Easy way: Using Online APK Decompiler简单方法:使用在线 APK 反编译器

I know this question is answered still and I am not trying to be smart here.我知道这个问题仍然有答案,我不想在这里变得聪明。 I'll just want to share another method on this topic.我只想分享关于这个主题的另一种方法。

Download applications with apk grail使用apk grail下载应用程序

APK Grail providing the free zip file of the application. APK Grail 提供应用程序的免费 zip 文件。

One should change the file extension from .apk to .zip . 应该将文件扩展名从.apk更改为.zip Then extract the files, modify them and then compress them to .zip and remember to rename the extension back to .apk . 然后解压缩文件,修改它们,然后将它们压缩为.zip并记住将扩展名重命名为.apk

For doing this we don't even have to use any computer. 为此,我们甚至不必使用任何计算机。 I prefer ES file explorer, which can also help to view and edit the source code. 我更喜欢ES文件浏览器,它也可以帮助查看和编辑源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM