Adb

Adb + strace + Monkeyアプリケーションランタイムのシステムコールを取得します(最終結果はtxtファイルに書き込まれます)



Adb Strace Monkey Get System Call Application Runtime



adb、strace、monkeyの紹介

adb (Android Debug Bridge)Android Debug Bridgeとして完全に知られている、コマンドラインツールです。これは、AndroidとPCをオープンにするためのブリッジとして機能します。 adbを使用すると、PC側でAndroidシステムを操作できます。
strace Linuxシステム用のデバッグ分析ツールです。 AndroidはLinuxカーネルに基づいているため、straceはAndroidシステムにも存在します。これは、アプリケーションの実行中にトリガーされるシステムコールを追跡するために使用できます。
モンキー これは、Androidシステム用のコマンドラインツールです。モンキーコマンドを使用して、アプリケーションで一連の任意の操作を実行することにより、アプリケーションのストレステストを行います。

straceの使用法は、ブログを参照できます。
Linuxstraceコマンド



adb + Monkeyの使用は、ブログを参照できます。
Adbコマンドの使用とmonkeyコマンドの使用

システムコールを取得する

思想

取得したいのは、アプリケーションが最初から実行するシステムコールのシーケンスであり、(1)アプリケーションを実行しないとプロセス番号を取得できません。同時に、(2)アプリケーションを実行してプロセスIDを取得した場合、アプリケーションを再度閉じるとプロセス番号が変わります。上記の2つの理由から、straceの親プロセスを決定します。



Androidシステムでは、ユーザーアプリケーションはzygoteによって生成され、その親プロセスはzygoteです。
画像
したがって、追跡する接合子プロセス番号を取得するだけです。 strace zygoteと同時に、monkeyコマンドを実行して指定されたアプリケーションを操作し、zygoteプロセスのシステムコールのシーケンスを取得し、指定されたアプリケーションのシステムコールのシーケンスをフィルタリングします。

プロセス全体

メインコマンドを書くと、コードは手放しません

1.接合子プロセス番号を取得します



public String getPid(String name)throws Exception{ / / Execute the adb shell ps command to get the current process information Process proc = Runtime.getRuntime().exec('adb shell ps') / / Enter in byte stream InputStream ins = proc.getInputStream() / / Convert to a character stream InputStreamReader insr = new InputStreamReader(ins) / / Use the character stream with caching function to facilitate row operations BufferedReader bufr = new BufferedReader(insr) String nextline = null String pid = null /*Read data by line, replace it with spaces, and then separate the string with spaces. Get its 7th string to determine if it is the process we need */ while((nextline=bufr.readLine())!=null){ String repnextline1 = nextline.replaceAll('\s+',' ') String[] substr = repnextline1.split(' ') if((substr.length > 8) && (substr[8].equals(name))) { pid = substr[1] break } } bufr.close() return pid }

2.アプリケーションをインストールします

Adb install apk where the path

3.接合子プロセスをトレースし、結果をAndroidシステムに出力します
このコマンドは、実行後にkill strace(ステップ5)で完了する必要があります。

Adb shell strace -o anfilepath (path in Android) -T -tt -e trace=all -f -p pid(zygote process)

4.monkeyコマンドを実行してアプリケーションを操作します。

Adb shell monkey --ignore-crashes --ignore-timeouts -p process name 500 (number of executions)

5.straceを終了します

手順1のコードからプロセス番号を取得します。

Adb shell kill strace process number

6.AndroidシステムからPCにファイルを抽出します

Adb pull filepath (PC side path) anfilepath (Android path)

7.Androidシステムでファイルを削除します

Adb shell rm anfilepath (path in Android)

8.アプリをアンインストールします

Adb uninstall apk package name (consistent with its process name)

最後に、システムコールからアプリケーションをフィルタリングするシステムコールの詳細は書き込まれません。
システムコールtxtのスクリーンショットは次のとおりです。
画像