Java 在 res/layout 中提取 Android .apk 并读取 XML 文件的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3868768/
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-14 06:05:19  来源:igfitidea点击:

Extracting Android .apk and reading contents of XML file in res/layout

javaandroid

提问by nolan

I am trying to reverse engineer an existing android app and understand how a particular UI is constructed. I've found that I can rename the apk to zip and view some of the compiled source. The res/layout directory is populated with all the xml files that define the UI, but while they do have the xml extension, they are not in XML format. Is there anyway to convert these files back to text based markup?

我正在尝试对现有的 android 应用程序进行逆向工程,并了解特定 UI 的构建方式。我发现我可以将 apk 重命名为 zip 并查看一些已编译的源代码。res/layout 目录中填充了所有定义 UI 的 xml 文件,虽然它们有 xml 扩展名,但它们不是 XML 格式。有没有办法将这些文件转换回基于文本的标记?

采纳答案by pengwang

I think you can use android-apktool. The XML files look very well.

我认为你可以使用android-apktool。XML 文件看起来非常好。

回答by success_anil

First covert your .apkto .zip. Inside that you will get a compiled-bundled version of java class files called .dex. apply the below trick to convert that dex to class files

首先将您的.apk 转换.zip。在里面,您将获得一个名为.dex的 Java 类文件的编译捆绑版本。应用以下技巧将该 dex 转换为类文件

There's a way to do this. A slight atypical way is to download this opensource tool dextojarhttp://code.google.com/p/dex2jar/

有一种方法可以做到这一点。一个稍微不典型的方法是下载这个开源工具dextojarhttp://code.google.com/p/dex2jar/

This will convert your dex files to Jar file. Unjar these files to get java class files.

这会将您的 dex 文件转换为 Jar 文件。解压这些文件以获取 java 类文件。

Then reverse engineer the java class files to get the java code. Don't use it to break some commercial projects.

然后对java类文件进行逆向工程得到java代码。不要用它来破坏一些商业项目。

Thanks

谢谢

回答by xesam

if you just want to know the UI construction ,you can use Hierarchy Viewer

如果您只想了解 UI 构造,可以使用 Hierarchy Viewer

回答by Milad Faridnia

Create a new folder and put the .apk file which you want to decode into that.

创建一个新文件夹并将要解码的 .apk 文件放入其中。

Download the latest version of from here.

这里下载最新版本。

Open cmd then navigate to the root directory of APKtool and type the following command:

打开 cmd 然后导航到 APKtool 的根目录并键入以下命令:

apktool d myApp.apk 

(where myApp.apk is the filename that you want to decode)

(其中 myApp.apk 是您要解码的文件名)

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

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

Here is the linkfor more detail install instructions

这是更多详细安装说明的链接

回答by Fit Coder

For those Who are shortcut lovers: and using ubunto,

对于那些喜欢捷径的人:并使用 ubunto,

go to cmd : ctl+alt+t

转到 cmd :ctl+alt+t

type:

类型:

sudo apt install apktool

press enter then go to your apk(to decompile) folder. by using

按 Enter 然后转到您的 apk(反编译)文件夹。通过使用

cd ~/folder_name

then type:

然后输入:

apktool d yourAppName.apk

and boom , you are done.

和繁荣,你完成了。