[心得]2011/12 SA@Tainan 用Android學習系統程式

看板LinuxDev作者 (qqq)時間14年前 (2012/01/29 14:10), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/3 (看更多)
[補充jserv大大的feedback] 各位大大好: 這份是 【2011 十二月份 SA@Tainan 用 Android 學習系統程式 12/24 (六) 】 課程的心得。 感謝工作人員和講師的付出,整理一份當時抄的筆記,由於年代已久不可考,有些 其實已經忘記當初要記的重點。 這份筆記主要是補充投影片中的東西和自己有興趣的內容,建議搭配投影片和紫皮 書【程式設計師的自我修養:連結、載入、程式庫】。投影片可以到jserv 大大的 網站或是【酷!學園】討論區上面都有。 另外我想應該很多錯誤也請指正,謝謝! * Android IPC - Intent -> AIDL -> Binder - cat /sys/kernel/debug/binder 可以觀察相關資訊 - Parcel打包概念 - binder 是去shared memory 撈service - 所有service透過binder 相互聯繫 * Android debuggerd - Android 攔胡process segmentation fault signal,發生不正常錯誤時透過 socket 通知debuggerd - debuggerd在logcat中顯示的address是上次跑完的address - lr -> register for storing return address in ARM - 可以比照crash log和/proc/pid/maps - 參考: https://wiki.linaro.org/WorkingGroups/ToolChain/Outputs/LibunwindDebuggerd * Dynamic linker/program interpreter - 同一個 root file system 底下可有兩個以上的 ELF interpreter - Android下面不同的版本/system/bin/linker的address可能不同 + 安全性考量以及performance因素 - X86 + Entry: libc_start_main + library: libc + linker: ls-linux.so.2 (可以執行) - Android + Entry: __libc_init + library: bionic + linker: /system/bin/linker - 沒有正確處理 stack & calling convention,會發生 SegFault * bionic (Android的libc) - __init_libc有static和dynamic 兩種方式 - init process (pid 1 那個)用static,不可用malloc - 相關說明可以參考AOSP下面的文件(有點過期) - adbd 是static (?) - 看interpreter資訊 - objdump -s -j .interp filename * memory map of a process - cat /proc/pid/maps + 欄位說明: - address - perms + r = read + w = write + x = execute + s = shared + p = private (copy on write) - offset - dev - inode - pathname - 相同的path有兩個以上可能是text/data的差別 adb shell cat /proc/18696/maps (投影片剪貼) 00008000-00009000 r-xp 00000000 b3:02 8959 /data/local/hello 00009000-0000a000 rwxp 00001000 b3:02 8959 /data/local/hello b0001000-b0009000 r-xp 00001000 b3:01 128 /system/bin/linker b0009000-b000a000 rwxp 00009000 b3:01 128 /system/bin/linker b000a000-b0015000 rwxp 00000000 00:00 0 beb07000-beb28000 rw-p 00000000 00:00 0 [stack] ffff0000-ffff1000 r-xp 00000000 00:00 0 [vectors - heap是由address往後面增加 - stack是由address往前面增加 - 可以用來逆向以及trace程式 * ABI - readelf可以讀出來 $ readelf -h ../libs/armeabi/a ELF Header: Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 Class: ELF32 Data: 2's complement, little endian Version: 1 (current) OS/ABI: UNIX - System V ABI Version: 0 Type: EXEC (Executable file) Machine: ARM Version: 0x1 Entry point address: 0x8540 Start of program headers: 52 (bytes into file) Start of section headers: 7592 (bytes into file) Flags: 0x5000002, has entry point, Version5 EABI Size of this header: 52 (bytes) Size of program headers: 32 (bytes) Number of program headers: 7 Size of section headers: 40 (bytes) Number of section headers: 22 Section header string table index: 21 - eabi/oabi: e for embedded, o for old - 不同的ABI (包含ABI版本)對於data type的size定義有可能不同 + sizeof (char) - EABI: 1 - OABI: 4 + sizeof (struct empty_struct{};) - EABI: 1 - x86沒有ABI版本的問題 - Embedded的ABI不同的原因可能是 + 改板 + 商業考量,故意讓其他產品不能相容 + 效率 + ref: http://wiki.debian.org/ArmEabiPort - ARM EABI 基本上已大一統了 * Start a process - create a process - load executable file - setup runtime - page valid (?) * Before Hello World.. - UID/GID - Signal - load ld.so - mmap - random - load libstdc++.so - ... * Android GDB - adb forward tcp:port tcp:port - symbol 可能在 - ${PWD}/out/target/product/product_name/symbols/system/bin * LD debug - export LD_DEBUG=files - LD_DEBUG=help /lib/ld-2.13.so * Hear Say/忘記是記啥的 - BUILD_ID + Issue tracking - 忘記講的是ELF還是AOSP/Cyanogenmod - NDK的進版本和Android SDK進板有關聯 - mm -b => make clean; make - 有些elf執行檔沒有main的進入點 + pypy - 2010年開始ELF加入build ID - abort() - ptrace - addr2line -e [file] - Android重寫了libc/linker,size減少,代價就是功能也減少 - libunwind - ELF section的offset一般來說會和/proc/pid/maps會有點差別,主要是安全考量 - ANR + Android Not Responding + 執行很久的程式碼,建議放在 Service 中 - Android中把東西mix起來就叫flinger + Surface flinger + service flinger + ... -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 111.250.98.253

01/29 15:58, , 1F
推.... 雖然我跟android很不熟..Orz
01/29 15:58, 1F
※ 編輯: robinliao 來自: 111.250.98.253 (01/29 18:14)
文章代碼(AID): #1F9EBXs4 (LinuxDev)
討論串 (同標題文章)
文章代碼(AID): #1F9EBXs4 (LinuxDev)