[英]How can I count method calls inside APK? (using .smali format)
I am trying to develop a tool that basically analyses an Android app APK and counts the number of calls to a specific API method (eg, android.app.AlarmManager.set()
)我正在尝试开发一种工具,该工具基本上可以分析 Android 应用程序 APK 并计算对特定 API 方法(例如
android.app.AlarmManager.set()
)的调用次数
1. What approach do you recommend? 1. 你推荐什么方法?
So far I have used APKTool and now I have .smali
files.到目前为止,我已经使用了APKTool ,现在我有了
.smali
文件。 However, for the same java source, I can have multiple files:但是,对于同一个java源,我可以有多个文件:
ExportAsyncTask$1.smali
ExportAsyncTask$2.smali
ExportAsyncTask$3.smali
ExportAsyncTask$4.smali
2. What do these multiple files mean? 2. 这些多个文件是什么意思?
3. The resulting .smali
files also include external libraries that I would like to leave out the analysis. 3. 生成的
.smali
文件还包括我想忽略分析的外部库。 How can I do that?我怎样才能做到这一点?
1. What approach do you recommend? 1. 你推荐什么方法?
Yes, Apktool can be used for your task.是的,Apktool 可用于您的任务。 Each
java
class in the APK will be represented by a .smali
file in directories tree representing the packages. APK 中的每个
java
类都将由代表包的目录树中的.smali
文件表示。 Smali - is the Android Virtual Machine language. Smali - 是 Android 虚拟机语言。 The language is much simpler than Java and hence easier for analysis.
该语言比 Java 简单得多,因此更易于分析。 In your case you should search for
invoke
opcodes and Landroid/app/AlarmManager;->set
strings.在您的情况下,您应该搜索
invoke
操作码和Landroid/app/AlarmManager;->set
字符串。 If you are working in Linux, you can for example grep
and count them.如果您在 Linux 中工作,您可以例如
grep
并计算它们。 In Windows you have text editors like Notepad++ that allow text search in multiple files.在 Windows 中,您有像 Notepad++ 这样的文本编辑器,可以在多个文件中进行文本搜索。
2. What do these multiple files mean? 2. 这些多个文件是什么意思?
In Java there are internal classes and implicit internal classes.在 Java 中有内部类和隐式内部类。 The former will appear in
OutherClass$InnerClass.smali
and the later, having no name of its own, get numbers, like OuterClass$1.smali
.前者将出现在
OutherClass$InnerClass.smali
,而后者则没有自己的名字,获取数字,如OuterClass$1.smali
。 You sometimes even get more deep levels like a$b$c$1.smali
.您有时甚至会获得更深的级别,例如
a$b$c$1.smali
。
3. The resulting .smali files also include external libraries that I would like to leave out the analysis. 3. 生成的 .smali 文件还包括我想忽略分析的外部库。 How can I do that?
我怎样才能做到这一点?
You have no precise way to do that.你没有确切的方法来做到这一点。 But generally speaking, when you look at the packages/directory tree of many samples you usually grasp the pattern.
但一般来说,当您查看许多示例的包/目录树时,您通常会掌握模式。 Eg usually application code is in
com.*
package and android.*
, org.*
and uk.*
include libraries.例如,通常应用程序代码在
com.*
包中,而android.*
、 org.*
和uk.*
包含库。 After such inspection you simply exclude those directories from your search.经过这样的检查,您只需从搜索中排除这些目录。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.