简体   繁体   English

逆向工程安卓应用(附源码)

[英]Reverse Engineering Android Application (with source)

Looking at an existing Android app, I have the full source, I'm wondering how to determine which Adapter handles events from the UI for a particular screen in the running app.查看现有的 Android 应用程序,我有完整的源代码,我想知道如何确定哪个适配器处理来自正在运行的应用程序中特定屏幕的 UI 的事件。

There are a number of layout (XML) files, and a fistful (dramatically lower number) of Adapters.有许多布局 (XML) 文件和少量(数量明显减少)的适配器。 Guessing, grepping and setting debug points have not lead me to the Adapter in question thus far.到目前为止,猜测、grepping 和设置调试点还没有让我找到有问题的适配器。 (Frankly I'm unsure I can even find the correct layout file for the screen I'm trying to work on!) (坦率地说,我不确定我什至可以为我正在尝试处理的屏幕找到正确的布局文件!)

I'm very familiar with Web development and PHP and given an app, have a plethora of methods to find my way into the 'controller' code.我非常熟悉 Web 开发和 PHP,并且给定了一个应用程序,我有很多方法可以找到进入“控制器”代码的方法。 Also know Java fairly well, and have been making mods to the app so far, but stuck now... Can someone throw me pointers on reverse engineering an Android app?也相当了解 Java,并且到目前为止一直在为应用程序制作 mod,但现在卡住了......有人可以向我提出有关逆向工程 Android 应用程序的指针吗?

last time i did this was a year ago, when Android security sucked (and not a lot of proguard), so i used an eclipse decompiler and dex2jar.我上次这样做是在一年前,当时 Android 安全性很差(而且没有很多 proguard),所以我使用了 Eclipse 反编译器和 dex2jar。 Actually i'm surprised - how were you able to get the full code?实际上我很惊讶 - 你是如何获得完整代码的?

the benefit of using eclipse is that you can backtrace callers to function.使用 eclipse 的好处是您可以回溯调用者的功能。

the thing is - i don't think you're after the adapter.问题是 - 我不认为你在追求适配器。 if the screen is a list, you're actually after the ListView (which contains the adapter).如果屏幕是一个列表,那么您实际上是在ListView (其中包含适配器)之后。 maybe the adapter might even contain a reference to the listview itself.也许适配器甚至可能包含对列表视图本身的引用。 so, try to find the view and not the adapter所以,尝试找到视图而不是适配器

if it's a listView then, actually, look for something named "xxxx_row.xml" something with the word "row" in it, because that's the standard convention for listview views.如果它是一个listView,那么实际上,查找名为“xxxx_row.xml”的东西,其中包含“row”一词,因为这是listview 视图的标准约定。

This will work for most Android apps.这适用于大多数 Android 应用程序。

In general, each screen is built by an instance of the Activity class.一般来说,每个屏幕都是由 Activity 类的一个实例构建的。

  • Check AndroidManifest.xml in the root of the project.检查项目根目录中的 AndroidManifest.xml。 Look for an activity declaration which contains an intent filter like this:查找包含如下意图过滤器的活动声明:

     <intent-filter> <action android:name="android.intent.action.MAIN"/> <category android:name="android.intent.category.LAUNCHER"/> </intent-filter> </activity>

This is the "entry" point to the application, not strictly true but close enough for this task.这是应用程序的“入口”点,并非严格正确,但足够接近此任务。 In fact, Android creates an internal singleton instance of the Application class, which might be extended but usually not.事实上,Android 创建了一个 Application 类的内部单例实例,它可能会被扩展,但通常不会。 Grep for "extends Application" or " : Application" to know. Grep 用于“扩展应用程序”或“:应用程序”以了解。

  • Find the class file with the same name as the activity name, in this case SampleAppMainActivity.找到与活动名称同名的类文件,在本例中为SampleAppMainActivity.

  • Open this class file and find onCreate().打开这个类文件,找到onCreate()。 This is the first method that Android calls when the activity is instantiated.这是 Android 在实例化 Activity 时调用的第一个方法。

  • Find setContentView().找到 setContentView()。 It will reference a layout, to be found in res/layout or a subfolder therein, like this.它将引用一个布局,可以在 res/layout 或其中的子文件夹中找到,就像这样。 R.layout.sampleappmainlayout. R.layout.sampleappmainlayout。 The file itself will be XML.文件本身将是 XML。 This file defines the UI elements used in the activity screen (it might have includes to merge other layouts).该文件定义了活动屏幕中使用的 UI 元素(它可能包含合并其他布局)。

  • If there are multiple activities, then look for creation of instances of the Intent class in this activity, usually attached to button or menu click listeners.如果有多个活动,则在此活动中查找Intent类实例的创建,通常附加到按钮或菜单单击侦听器。

Recurse from step 2 :)从第 2 步递归:)

The other answers deal with the specifics of adapters.其他答案涉及适配器的细节。 Or perhaps not?或者也许不是? Android uses adapters to handle the retrieval of data and binding those data to UI elements. Android 使用适配器来处理数据的检索并将这些数据绑定到 UI 元素。 They do not "respond to UI events".它们不“响应 UI 事件”。 Are you perhaps asking about view controllers in the MVC model?您可能是在询问 MVC 模型中的视图控制器吗?

Good luck.祝你好运。

PS Whatever your client is paying you, it's not enough. PS 无论你的客户付给你什么钱,这还不够。 I can guess how you landed this gig but yeuch.我能猜到你是怎么得到这个演出的,但是你太棒了。 Just yeuch.只是你。

Instructions for OS Windows:操作系统 Windows 的说明:

  1. Dowload dex2jar-0.0.7.10-SNAPSHOT.zip (version can be different) and extract it ie to folder D:\\Decompile.下载 dex2jar-0.0.7.10-SNAPSHOT.zip (版本可以不同)并解压到文件夹 D:\\Decompile。
  2. Dowload Java Decompiler ie JD-GUI and extract to the same folder.下载Java DecompilerJD-GUI并解压到同一文件夹。
  3. Dowload apktool1.4.1.tar.bz2 and apktool-install-windows-r04-brut1.tar.bz2 and extract to the system folder ie C:\\Windows.下载apktool1.4.1.tar.bz2apktool-install-windows-r04-brut1.tar.bz2并解压到系统文件夹,即 C:\\Windows。
  4. For example our aplication is called Calculator.apk, move it to folder with Java Decompiler and dex2jar例如我们的应用程序叫做Calculator.apk,将它移动到Java Decompilerdex2jar文件夹中
  5. Open command line tool C:\\Windows\\System32\\cmd.exe打开命令行工具 C:\\Windows\\System32\\cmd.exe
  6. Change dirrectory into folder where dex2jar located, input command dex2jar Calculator.apk , if all successful in the same folder appears file Calculator.apk.dex2jar.jar将目录改成dex2jar所在的文件夹,输入命令dex2jar Calculator.apk ,如果在同一个文件夹中都成功了就会出现文件Calculator.apk.dex2jar.jar
  7. Open jd-gui and open file from previous step.打开jd-gui并打开上一步中的文件。
  8. Select File-Save All Sources and save file.选择File-Save All Sources并保存文件。
  9. Extract the resulting zip archive.提取生成的 zip 存档。
  10. Put the resulting folder to folder src (must be pre-created).将生成的文件夹放入文件夹 src (必须预先创建)。 (To get around this structure is D: \\ Decompile \\ Calculator \\ src \\ com \\ android). (绕过这个结构是D:\\Decompile\\Calculator\\src\\com\\android)。
  11. Again, at the command line enter the command apktool d Calculator.apk Calculator , where Calculator.apk-package name, Calculator-folder to decompile.再次,在命令行输入命令apktool d Calculator.apk Calculator ,其中 Calculator.apk-包名,Calculator-folder 进行反编译。
  12. If all is well, then in the folder will be the source in two formats (java and smali), resources and files AndroidManifest.xml, apktool.yml.如果一切顺利,那么文件夹中就会有两种格式的源码(java和smali),资源和文件AndroidManifest.xml、apktool.yml。

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

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