交叉引用
crossreferences (XREFs)
Androguard 的交叉引用包含了一下的四个东西:
- Classes
- Methods
- Fields
- Strings
XREFs 工作在两个方向: xref_from 和 xref_to . To 表示的是现在的这个对象正在调用其他的对象, from 意味这当前的对象正在被其他的对象调用。
举一个例子:
A 调用了B的对象,那么 A.xref_to 就包含了B
那么B被A调用了,那么B.xref_from 就包含了A
考虑如下的Java 源代码:
class Foobar {
public int afield = 23;
public void somemethod() {
String astring = "hello world";
}
}
class Barfoo {
public void othermethod() {
Foobar x = new Foobar();
x.somemethod();
System.out.println(x.afield);
}
}
这里有两个类,一个Foobar,一个Barfoo. Barfoo 这个列实例化了另一个类 FooBar 以及调用了这个类的方法和字段。
afield 在 Barfoo.othermethod的xref_to 中, 同样的也在Foobar 的xref_to 里。
针对Androguard 的3.4.0 版本来说
我们可以使用androguard analyze 来启动 ipython, 简单快速的分析我们的apk 文件。
$ androguard analyze examples/android/TestsAndroguard/bin/TestActivity.apk
Please be patient, this might take a while.
Found the provided file is of type 'APK'
[INFO ] androguard.analysis: End of creating cross references (XREF)
[INFO ] androguard.analysis: run time: 0min 00s
Added file to session: SHA256::3bb32dd50129690bce850124ea120aa334e708eaa7987cf2329fd1ea0467a0eb
Loaded APK file...
>>> a
<androguard.core.bytecodes.apk.APK object at 0x000000000581D710>
>>> d
[<androguard.core.bytecodes.dvm.DalvikVMFormat object at 0x000000000D847400>]
>>> dx
<analysis.Analysis VMs: 1, Classes: 495, Strings: 496>
不同的Androguard 版本的启用ipython 方式稍微有点不同
下面是androguard 3.1.1 的启动方式
$ androlyze.py
Androguard version 3.1.1 started
In [1]: a, d, dx = AnalyzeAPK("examples/android/abcore/app-prod-debug.apk")
# Depending on the size of the APK, this might take a while...
In [2]:
这里的三个对象分别表示了 一个APK的对象a, 一个DalvikVMFormat 的对象,dx 的一个Analysis 分析对象
我们使用 Analysis 的对象来做分析 ~androguard.core.analysis.analysis.Analysis
In [2]: dx.get_classes(