Android系统编译之后的打包阶段,会将所有编译出来的有需要的执行文件,库文件以及各种配置文件等打包到各个镜像文件中。有时候我们需要看一下镜像文件中都打包了什么东西,那就可以通过一些方法将其挂载到一个目录,然后进行查看。
一、所用到的工具 1.1 simg2img 简述 :将sparse 格式的image文件转化为raw格式的image文件。 编译android源码默认会生成。
路径:out/host/linux-x86/bin/simg2img
如果没有请用如下的指令编出
source build/envsetup.sh lunch miodm_topaz_native-userdebug export OUT_DIR=out && nj simg2img
1.2 lpunpack **简述:**这个工具可以将system.img,product.img,vendor.img等文件从super.img解析出来。
路径:out/host/linux-x86/bin/lpunpack
如果没有请用如下的指令编出
source build/envsetup.sh lunch miodm_topaz_native-userdebug export OUT_DIR=out && nj lpunpack
1.3 unpack_bootimg **简述:**专门用于解析boot.img的工具。
路径:out/host/linux-x86/bin/unpack_bootimg system/core/mkbootimg/unpack_bootimg.py
如果没有请用如下的指令编出
source build/envsetup.sh lunch miodm_topaz_native-userdebug export OUT_DIR=out && nj unpack_bootimg
1.4 mkdtimg **简述:**将dtbo.img文件转化为dtb文件,一个dtbo.img会包含多个dtb文件; 编译android源码默认会生成。
路径:out/host/linux-x86/bin/mkdtimg
如果没有请用如下的指令编出
source build/envsetup.sh lunch miodm_topaz_native-userdebug export OUT_DIR=out && nj mkdtimg
1.5 dtc **简述:**将dtb文件转化为可阅读的dts文件; 编译android源码默认会生成。
路径:out/host/linux-x86/bin/dtc
二、解压缩各image文件 2.1 boot.img/recovery.img/vendor_boot.img 2.1.1 解压缩 指令如下:
boot.img
1 2 3 4 ../system/core/mkbootimg/unpack_bootimg.py --boot_img boot.img --out boot or ../out/host/linux-x86/bin/unpack_bootimg --boot_img boot.img --out boot
recovery.img
1 2 3 4 ../system/core/mkbootimg/unpack_bootimg.py --boot_img recovery.img --out recovery or ../out/host/linux-x86/bin/unpack_bootimg --boot_img recovery.img --out recovery
vendor_boot.img
1 2 3 4 ../system/core/mkbootimg/unpack_bootimg.py --boot_img vendor_boot.img --out vendor_boot or ../out/host/linux-x86/bin/unpack_bootimg --boot_img vendor_boot.img --out vendor_boot
2.2 dtbo.img
先从dtbo.img中解析出dtb文件
1 2 mkdir dtbo && ../out/host/linux-x86/bin/mkdtimg dump dtbo.img -b dtbo/dtb
将上一步的dtb文件转化为可以阅读的dts文件
1 2 3 4 5 ../out/host/linux-x86/bin/dtc dtbo/dtb.0 dtbo/0.dts # 批量解析 find ./dtbo -name 'dtb.*' | xargs -n1 sh -c '../out/host/linux-x86/bin/dtc $1 -o $1.dts'
也可以使用fdtdump
fdtdump -sd dtbo.img > dtbo.txt
2.3 dtb.img 1 2 ../out/host/linux-x86/bin/dtc dtb.img dtb/dtb.dts
也可以使用fdtdump
fdtdump -sd dtb.img > dtb.txt
将sparse格式的metadata.img转化为raw格式的metadata_raw.img
1 2 ../out/host/linux-x86/bin/simg2img metadata.img metadata_raw.img
将metadata_raw.img挂载到一个目录上,此时访问这个目录就可以访问镜像文件的内容了
1 2 3 4 5 6 #首先创建目录metadata,然后将metadata_raw.img挂载到此目录 mkdir metadata && sudo mount -o ro metadata_raw.img metadata #可以看到metadata目录已经有内容了 ~/android/imgs$ ls lost+found
2.5 super.img
sparse格式转化为raw格式
1 2 ../out/host/linux-x86/bin/simg2img super.img super_raw.img
使用lpunpack解析super_raw.img
1 2 3 4 5 mkdir super ../out/host/linux-x86/bin/lpunpack super_raw.img super ls super product_a.img product_b.img system_a.img system_b.img vendor_a.img vendor_b.img
挂载解析出来的镜像文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 #以system_a.img为例,其他同理 mkdir system_a sudo mount -o ro system_a.img system_a #查看system_a.img解析出来的文件 ll system_a 总用量 172 drwxr-xr-x. 22 root root 4096 1月 1 2009 ./ drwxrwxr-x 3 sun sun 4096 8月 26 13:49 ../ drwxr-xr-x. 2 root root 4096 1月 1 2009 acct/ drwxr-xr-x. 2 root root 4096 1月 1 2009 apex/ lrw-r--r--. 1 root root 11 1月 1 2009 bin -> /system/bin lrw-r--r--. 1 root root 50 1月 1 2009 bugreports -> /data/user_de/0/com.android.shell/files/bugreports lrw-r--r--. 1 root root 11 1月 1 2009 cache -> /data/cache lrw-r--r--. 1 root root 19 1月 1 2009 charger -> /system/bin/charger dr-xr-xr-x. 2 root root 4096 1月 1 2009 config/ lrw-r--r--. 1 root root 17 1月 1 2009 d -> /sys/kernel/debug/ drwxrwx--x. 2 sun sun 4096 1月 1 2009 data/ drwxr-xr-x. 2 root root 4096 1月 1 2009 debug_ramdisk/ lrw-------. 1 root root 23 1月 1 2009 default.prop -> system/etc/prop.default drwxr-xr-x. 2 root root 4096 1月 1 2009 dev/ lrw-r--r--. 1 root root 11 1月 1 2009 etc -> /system/etc lrwxr-x---. 1 root 2000 16 1月 1 2009 init -> /system/bin/init -rwxr-x---. 1 root 2000 2067 1月 1 2009 init.environ.rc* -rwxr-x---. 1 root 2000 34196 1月 1 2009 init.rc* -rwxr-x---. 1 root 2000 3343 1月 1 2009 init.recovery.qcom.rc* -rwxr-x---. 1 root 2000 7690 1月 1 2009 init.usb.configfs.rc* -rwxr-x---. 1 root 2000 5649 1月 1 2009 init.usb.rc* -rwxr-x---. 1 root 2000 611 1月 1 2009 init.zygote32.rc* -rwxr-x---. 1 root 2000 1029 1月 1 2009 init.zygote64_32.rc* drwx------. 2 root root 16384 1月 1 2009 lost+found/ drwxr-xr-x. 2 root root 4096 1月 1 2009 metadata/ drwxr-xr-x. 2 root sun 4096 1月 1 2009 mnt/ drwxr-xr-x. 2 root root 4096 1月 1 2009 odm/ drwxr-xr-x. 2 root root 4096 1月 1 2009 oem/ drwxr-xr-x. 2 root root 4096 1月 1 2009 postinstall/ drwxr-xr-x. 2 root root 4096 1月 1 2009 proc/ drwxr-xr-x. 2 root root 4096 1月 1 2009 product/ lrw-r--r--. 1 root root 24 1月 1 2009 product_services -> /system/product_services drwxr-xr-x. 3 root root 4096 1月 1 2009 res/ drwxr-x---. 2 root 2000 4096 1月 1 2009 sbin/ lrw-r--r--. 1 root root 21 1月 1 2009 sdcard -> /storage/self/primary drwxr-x--x. 2 root 1028 4096 1月 1 2009 storage/ drwxr-xr-x. 2 root root 4096 1月 1 2009 sys/ drwxr-xr-x. 14 root root 4096 1月 1 2009 system/ -rw-r--r--. 1 root root 2608 1月 1 2009 ueventd.rc drwxr-xr-x. 2 root 2000 4096 1月 1 2009 vendor
2.6 persist.img 这个镜像是linux ext4格式的,直接挂载即可
1 2 3 mkdir persist sudo mount -o ro persist.img persist