Android系统探索

apk源码探索帮助手段

2018-06-08  本文已影响0人  Mwp的救赎

root模拟器

$ adb devices
List of devices attached
emulator-5554   device
$ adb root
adbd is already running as root
$ adb shell
generic_x86:/ # 

Device File Explorer

使用Device File Explorer查看系统文件:(可以使用Android Studio右上角搜索“Device File Explorer”)

使用systrace查看系统方法调用

官方文档:https://developer.android.com/studio/command-line/systrace

$ cd Library/Android/sdk/platform-tools/systrace/
$ python systrace.py -l
         gfx - Graphics
       input - Input
        view - View System
     webview - WebView
          wm - Window Manager
          am - Activity Manager
          sm - Sync Manager
       audio - Audio
       video - Video
      camera - Camera
         hal - Hardware Modules
         app - Application
         res - Resource Loading
      dalvik - Dalvik VM
          rs - RenderScript
      bionic - Bionic C Library
       power - Power Management
          pm - Package Manager
          ss - System Server
    database - Database
     network - Network
         adb - ADB
         pdx - PDX services
       sched - CPU Scheduling
         irq - IRQ Events
         i2c - I2C Events
        freq - CPU Frequency
        idle - CPU Idle
        disk - Disk I/O
        sync - Synchronization
       workq - Kernel Workqueues
  memreclaim - Kernel Memory Reclaim
  binder_driver - Binder Kernel driver
  binder_lock - Binder global lock trace
   pagecache - Page cache

执行下面的操作之后,紧接着执行adb install:

$ python systrace.py -t 5 pm
Starting tracing (5 seconds)
Tracing completed. Collecting output...
Outputting Systrace results...
Tracing complete, writing results

Wrote trace HTML file: file:///Users/mengweiping/Library/Android/sdk/platform-tools/systrace/trace.html
$ adb install /Volumes/TOSHIBA_EXT/Github/androidsky/ApkInstallDetail/app/release/app-release.apk 
Success

查看trace.html


QQ20180610-143711@2x.png

跟踪系统启动

方法同上,时间改为60,当模拟器刚出现开机界面即执行命令。可以看到系统启动过程中扫描文件夹操作:


scan_dirs.png

查看系统log

例如跟踪apk安装流程,执行adb install命令的同时,可以使用PackageManager过滤查看log:

06-10 14:38:20.781 1706-1742/system_process D/PackageManager: Ephemeral installer not found with new action; try old one
06-10 14:38:20.781 1706-1742/system_process D/PackageManager: Clear ephemeral installer activity
06-10 14:38:25.092 1706-1742/system_process I/PackageManager.DexOptimizer: Running dexopt (dexoptNeeded=1) on: /data/app/com.example.mwp.apkinstalldetail-F3r-1fYdjGaTIuwy2x5NLA==/base.apk pkg=com.example.mwp.apkinstalldetail isa=x86 dexoptFlags=boot_complete,public target-filter=quicken oatDir=/data/app/com.example.mwp.apkinstalldetail-F3r-1fYdjGaTIuwy2x5NLA==/oat sharedLibraries=PCL[]
06-10 14:38:25.559 1706-1742/system_process D/PackageManager: Ephemeral installer not found with new action; try old one
06-10 14:38:25.559 1706-1742/system_process D/PackageManager: Clear ephemeral installer activity

查看进程列表

$ adb shell ps

查看service列表

$ adb shell service list

dumpsys

https://developer.android.com/studio/command-line/dumpsys
例如 查看Activity

$ adb shell dumpsys activity
上一篇下一篇

猜你喜欢

热点阅读