1. 提取zImage
1.1 下載rom,找到boot.img
1.2. 使用unpackbootimg或者其他工具解壓boot.img

1.3. out目錄下檔案如下:

1.4 binwalk boot.img-zImage -e提取被gzip壓縮的zImage

2. 32位rom獲取符號的核心地址



2.1 使用kallsymsprint可以獲取以上5個符號的地址

2.2 新增offset

2.3 使用kallsymsprint無法獲取到5個符號的地址

2.4 IDA載入32位的zImage

使用32位的IDA載入zImage時,Processer Type選擇ARM,勾選Manual load, 點選Ok

在ROM start address和Loading address填寫0xc0008000,這個是核心.text段的起始地址,通常都為0xc0008000,點選OK等待IDA載入完成。
如果你不確定是不是這個地址, 你可以使用如下命令直接從手機中獲取

往上檢視dmesg的輸出資訊可以找到

2.5 尋找 ptmx_fops 地址
在小米核心原始碼中搜尋,直接在github中搜尋的ptmx_fops

由上圖可以看到ptmx_fops僅在pty.c檔案中被引用了兩次,隨便選一處引用

再次搜尋tty_default_fops發現就只有一處呼叫該函式,那就用這個tty_default_fops函式去找到ptmx_fops吧

IDA跳轉到地址c03fb21c(按g,輸入地址,即可跳轉到指定地址),把c03fb21c重新命名為tty_default_fops(按n, 輸入名稱,即可修改別名)
IDA查詢tty_default_fops的引用(按x,可以找到所有引用該函式的地址),由於從原始碼知道只有一次引用該函式,就直接跳轉到應用tty_default_fops的地方


那麼就找到了ptmx_fops的地址為0xC12D5298
2.6 尋找 sidtab 地址
原始碼中搜尋sidtab,找到很多處引用,發現在services.c 中有個靜態的結構體變數,

進入services.c中,找引用sidtab的地方,找啊找啊找朋友~~~,找到一個好朋友
什麼是好朋友呢,就是引數越少的函式,引用越少的函式,這種函式方便分析,



sidtab的地址為0xC12BC530
2.7 尋找 policydb 地址





policydb地址0xC12BC420
2.8 尋找 selinux_enabled 地址




selinux_enabled地址0xC0F5332C
2.9 尋找 selinux_enforcing 地址





selinux_enforcing地址0xC12BA9D0
2.10 offset

2.11 演示結果

A.附錄:

B.參考連結

本文作者:Imyang(看雪ID)
原文連結:https://bbs.pediy.com/thread-246448.htm
轉載請註明:轉自看雪論壇
看雪推薦閱讀:
1、[原創]剖析2018騰訊遊戲安全競賽題目(上)-『CrackMe』-看雪安全論壇
2、[原創]GSLab2018-第一題標準版分析-『軟體逆向』-看雪安全論壇
3、[原創]網鼎杯第一場預選 babyheap
4、[原創]Android通用脫殼機FUPK3-『Android安全』-看雪安全論壇
5、[原創] 分析了個簡單的病毒, 熟悉一下16位彙編