我想监控手机下/sdcard/1.txt是谁写入的,这个问题好像很难,实际上利用linux下的inotifywait这个命令就可以实现了

inotifywait -m /sdcard/1.txt -e access,modify,create,delete

 

/data/local/tmp/inotifywait -m /sdcard/1.txt -e access,modify,create,delete |
while read path event file
do
    pid=$(lsof -t $path/$file)
	if [ -n "$pid" ]; then         
        pname=$(ps -p $pid -o NAME)
        echo "path="$path$file , "event="$event , "pid="$pid "pname="$pname
    else
        echo "path="$path$file , "event="$event  
    fi 
done


 

arm64的inotifywait 这个去哪里搞?

GitHub - dstmath/inotifywait-for-Android

还有一种方法安装一个termux,然后pkg install inotify

然后把inotifywait拷贝出来即可,另外手机得要到root

05-15 05:37