android中執行C可執行檔案時,出現/system/bin/sh: ./hello: No such file or directory 錯誤,
1. 問題:
msm8909w:/data # ./hello
/system/bin/sh: ./hello: No such file or directory
2. 解決方法 1:
使用靜態鏈接庫:在最后加上-static
arm-linux-gnueabihf-gcc hello.c -o hello -static
3. 解決方法 2:
將linux的C元件復制到android系統中的/lib目錄下,因為/lib里面有很多鏈接,所以不能直接復制檔案,要壓縮后再復制,再解壓,保證鏈接也一起被復制,
1). 在所用的arm-linux交叉編譯工具中找到ld-linux-armhf.so.3所在的/lib目錄
我目錄是:
home/ubuntu/Public/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/arm-linux-gnueabihf/libc/lib

2). 將其壓縮,試了壓縮成lib.tar,在安裝系統中解壓不了,用.tar.bz2格式可以解壓:
tar jcvf lib.tar.bz2 lib
3). 重新掛載檔案系統為可讀寫
mount -o rw,remount /
4).將lib.tar.bz2用android系統的根目錄
adb push lib.tar.bz2 /
5). 解壓
tar jxvf lib.tar.bz2

6). 查看鏈接是否有
ls -l

7). 一切準備好了,執行hello
msm8909w:/ # cd data
msm8909w:/data # ./hello
Hello World!
msm8909w:/data #
3. debug程序:
查看hello動態聯結器路徑:
輸入命令
msm8909w:/data # file hello
hello: ELF shared object, 32-bit LSB arm, dynamic (/lib/ld-linux-armhf.so.3), BuildID=e8f27306e68a08e256aaff15db40859d94b65e53, not stripped
android系統的動態聯結器與hello程式的動態聯結器的路徑不一樣(安卓和普通linux的根檔案目錄不一樣):
android系統的動態聯結器路徑:msm8909w:/system/lib
普通linux的動態聯結器路徑:/lib
參考:https://www.jianshu.com/p/ac9911eb7958?utm_campaign=maleskine&utm_content=note&utm_medium=seo_notes&utm_source=recommendation
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/243611.html
標籤:其他
下一篇:Objection動態分析App
