Androguard Documentation:官方文档阅读笔记

打算快速阅读下官方文档,然后做一个笔记方便查阅,文章目录按照官方文档目录来的

DOCUMENTATION

Getting Started

使用 androguard axmlandroguard arsc解码分析AndroidManifest.xml或者resources.arsc。
创建call graphs可以使用androguard cg,control flow graphs使用androguard decompile
要分析apk文件和dex文件可以使用AnalyzeAPK(filename)AnalyzeDEX(filename)
a, d, dx = AnalyzeAPK("examples/android/abcore/app-prod-debug.apk")
The three objects you get are a an APK object, d an array of DalvikVMFormat object and dx an Analysis object.
在apk对象中,可以获取到apk的各种信息,包括包名、权限信息、AndroidManifest.xml或其它资源文件。
DalvikVMFormat corresponds to the DEX file found inside the APK file. You can get classes, methods or strings from the DEX file. But when using multi-DEX APK’s it might be a better idea to get those from another place. The Analysis object should be used instead, as it contains special classes, which link information about the classes.dex and can even handle many DEX files at once.

Getting Information about an APK

a.get_permissions()
#getting a list of all activites, which are defined in the AndroidManifest.xml
a.get_activities()
a.get_package()
a.get_app_name()
a.get_app_icon() # path of the icon
#Get the numeric version and the version string, and the minimal, maximal, target and effective SDK version
 a.get_androidversion_code()
a.get_androidversion_name()
a.get_min_sdk_version()
a.get_max_sdk_version()
 a.get_target_sdk_version()
 a.get_effective_target_sdk_version()

有关AndroidManifest.xml

 #you can even get the decoded XML for the AndroidManifest.xml
a.get_android_manifest_axml().get_xml()
#use the AndroidManifest.xml as an ElementTree object
a.get_android_manifest_xml()

Using the Analysis object
可根据特定api构建调用图
~androguard.core.analysis.analysis.Analysis对象中有all information about the classes, methods, fields and strings inside one or multiple DEX files,Additionally it enables you to get call graphs and crossreferences (XREFs) for each method, class, field and string. This means you can investigate the application for certain API calls or create graphs to see the dependencies of different classes.

dx.get_classes() #  get all classes from the Analysis

get_classes返回ClassAnalysis对象
其中被标记为 EXTERNAL的类并没有在dex文件中定义
A ClassAnalysis does not contain the actual code but the ClassDefItem can be loaded using the get_vm_class():
dx.get_classes()[2].get_vm_class()
If the class is EXTERNAL, a ExternalClass is returned instead.

XREFs(交叉引用)

可以理解为在一个类中调用了另一个类的方法或者对象。
XREFs are generated for four things: Classes、Methods、Fields、Strings
XREFs work in two directions: xref_from and xref_to. To means, that the current object is calling another object. From means, that the current object is called by another object.
使用其提供的测试apk进行测试:examples/android/TestsAndroguard/bin/TestActivity.apk

Get XREFs for method calls
In order to get the class, you can simply use classes or find_classes():
dx.classes['Ltests/androguard/TestActivity;']
This will return a ClassAnalysis object. Now you can iterate over all methods inside the class and query for the xrefs (the output is abbreviated):

for meth in dx.classes['Ltests/androguard/TestActivity;'].get_methods():
   print("inside method {}".format(meth.name))
   for _, call, _ in meth.get_xref_to():
   print(" calling -> {} -- {}".format(call.class_name, call.name))   

输出图
可以看到testCall方法调用了很多的其它方法
同样的思路也可以用在API类中,如:

for meth in dx.classes['Ljava/io/File;'].get_methods():
	print("usage of method {}".format(meth.name))
	for _, call, _ in meth.get_xref_from():
	print(" called by -> {} -- {}".format(call.class_name, call.name))

Get XREFs for Strings
查找哪些字符串在被不同地方引用
You can use either strings or find_strings() to get the proper object for the XREFs:
如: dx.strings['boom']

for _, meth in dx.strings['boom'].get_xref_from():
	print("Used in: {} -- {}".format(meth.class_name, meth.name))

Get XREFs for Fields
Fields are a little bit different and do not use xref_from and xref_to but xref_read() and xref_write()
可以使用find_methods() 查找fields
For example, you want to get the read’s and write’s to the field value inside tests.androguard. TestActivity:

for field in dx.find_fields(classname='Ltests/androguard/TestActivity;', fieldname='^value$'):
	print("Field: {}".format(field.name))
	for _, meth in field.get_xref_read():
	print(" read in {} -- {}".format(meth.class_name, meth.name))
	for _, meth in field.get_xref_write():
	print(" write in {} -- {}".format(meth.class_name, meth.name))

Basic Blocks

可以使用 decompile 来获取 Control Flow Graph (CFG)
androguard decompile -d output_folder -f jpg --limit "LTestDefaultPackage.*" examples/android/TestsAndroguard/bin/TestActivity.apk
之后生成的图片,每一个矩形都是一个DVMBasicBlock

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Godams

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值